How cdaguerre/php-trello-api works
Main components
• API Layer: Represent the collection of classes encapsulating each Trello API endpoint (for Boards, Cards, Checklists, Members, etc.). These live in “lib/Trello/Api” (and similarly in "docs/Api" for documentation purposes) and implement the low-level API functions.
• HTTP Client Layer: Include the HTTP client abstraction (Guzzle is a dependency, and you see “lib/Trello/HttpClient” with its interface and listeners) which is responsible for making network requests and handling responses.
• Client: The central Client class (under “lib/Trello/Client.php”) is the entry point that ties the API, HTTP client, and authentication together.
• Manager/Model Layer: Represent the Manager class (in “lib/Trello/Manager.php”) and the Model layer (in “lib/Trello/Model”) that provides a higher-level and more object-oriented abstraction for Trello objects and operations.
• Event System: Illustrate the event classes (in “lib/Trello/Event”) and the Events class constants used to dispatch events coming from webhook handling. The integration with Symfony’s EventDispatcher should be highlighted.
• Service Layer: There's also a Service class (in “lib/Trello/Service.php”) that is used to listen to and handle webhook events.
• Exception Handling: Even though they’re not the focus of the control flow, include the exceptions (in “lib/Trello/Exception”) to emphasize error handling.
• External Dependencies: Show that the system relies on cURL (via PHP’s extension), Guzzle for HTTP transactions, and Symfony’s EventDispatcher for event management. Also note Composer for dependency management.
Relationships and interactions
• The “Client” is the central orchestrator that gets authenticated and then exposes the “api” function to return specific API objects.
• The API objects (for Board, Card, etc.) are responsible for mapping API endpoints to methods. They use the HTTP Client layer to perform requests.
• The Manager uses the Client to interact in a more domain-specific way. It encapsulates model objects (found in the Model directory) that represent Trello entities.
• The Service subscribes to webhook events and, using the event dispatching system (through Symfony’s component), distributes events to registered listeners.
Architectural Patterns & Principles
• Separation of Concerns: Different directories indicate a strict separation between the API (raw endpoint communications), the Model (object representations), and Event handling.
• Lazy Loading: Noted in the README, this principle ensures resource efficiency by loading API classes on demand.
• Client Abstraction & Fluent Interfaces: The chainable API provided by the Manager (as seen in the “Advanced usage”) allows fluent, domain-specific manipulations.
• Testing: A comprehensive testing suite is placed under the "test" directory, emphasizing unit testing across each module.
Specific components
• Client (lib/Trello/Client.php) as the core entry point.
• API Modules (e.g., lib/Trello/Api/Board.php, lib/Trello/Api/Card.php, etc.) connected to the Client.
• HTTP Client abstraction (lib/Trello/HttpClient/HttpClient.php) and its listeners.
• Manager (lib/Trello/Manager.php) and the Model classes (lib/Trello/Model/*).
• Events & Event Factory (lib/Trello/Event/* and lib/Trello/Events.php).
• Service layer handling webhooks (lib/Trello/Service.php) linking to EventDispatcher.
• External systems: Trello API, Guzzle library, PHP cURL.