Skip to content

Commit ea2c7bd

Browse files
committed
feat(docs): Update README for DotCMS Symfony integration example
Revise documentation to enhance clarity and detail: - Change project description to emphasize building a DotCMS webapp - Improve integration details for Symfony routing and error handling - Clarify configuration steps and service registration - Add sequence diagram for better understanding of request flow - Update prerequisites with links for Composer and Symfony CLI
1 parent 40b1ba0 commit ea2c7bd

1 file changed

Lines changed: 50 additions & 8 deletions

File tree

examples/dotcms-symfony/README.md

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# DotCMS Symfony Integration
22

3-
This project demonstrates how to integrate DotCMS with Symfony using the DotCMS PHP SDK. It provides a complete example of rendering DotCMS pages within a Symfony application, including layouts, containers, and content types.
3+
This project demonstrates how to build a DotCMS webapp with Symfony using the DotCMS PHP SDK. It provides a complete example of rendering DotCMS pages within a Symfony application, including layouts, containers, and content types.
44

55
## Overview
66

77
This integration allows you to:
88

99
- Fetch and render DotCMS pages in a Symfony application
10-
- Use Symfony's routing system to handle DotCMS URLs
11-
- Render DotCMS containers and contentlets using Twig templates
12-
- Handle DotCMS errors with Symfony's exception system
10+
- Integrate Symfony routing with DotCMS, enabeling content authors to create new pages without developer intervention.
11+
- Render DotCMS Pages using Twig templates, this includes layouts, containers and contentlets.
12+
- Integrating DotCMS SDK feedback into Symfony's exception framework for a smooth and reliable developer experience.
1313

1414
## Prerequisites
1515

1616
- PHP 8.1 or higher
17-
- Composer
18-
- Symfony CLI (optional, for local development)
19-
- DotCMS instance with API access
17+
- [Composer](https://getcomposer.org/doc/00-intro.md)
18+
- [Symfony CLI](https://symfony.com/download)
19+
- DotCMS instance with [API access](https://dev.dotcms.com/docs/rest-api-authentication)
2020

2121
## Project Structure
2222

@@ -70,8 +70,12 @@ DOTCMS_API_KEY=your-api-key-here
7070

7171
## Configuration
7272

73+
All the configuration described below is already implemented in this example project. The following sections explain the key components and how they work together to integrate DotCMS with Symfony.
74+
7375
### 1. Configure DotCMS Client
7476

77+
Symfony have [Service Container](https://symfony.com/doc/current/service_container.html) allows you to centralize useful objects waiting to be used within the app.
78+
7579
In `config/services.yaml`, add the DotCMS client configuration:
7680

7781
```yaml
@@ -104,9 +108,13 @@ services:
104108
tags: ['twig.extension']
105109
```
106110
111+
In this case we register two objects from the SDK the dotCMS `Config` and the `DotCMSClient`.
112+
113+
In Symfony's service container, we're initializing `DotCMSClient` by injecting a `Config` object as a dependency. The `Config` object itself is configured with environment variables and predefined options for the HTTP requests to the dotCMS APIs.
114+
107115
### 2. Create a DotCMS Service
108116

109-
Create a service to wrap the DotCMS client in `src/Service/DotCMSService.php`:
117+
Create a service to wrap the PHP `DotCMSClient` in `src/Service/DotCMSService.php`:
110118

111119
```php
112120
<?php
@@ -139,8 +147,16 @@ class DotCMSService
139147
}
140148
```
141149

150+
The `DotCMSService` class serves two important purposes:
151+
152+
1. **Dependency Injection**: Through Symfony's service container, the fully configured `DotCMSClient` is automatically injected into our service.
153+
154+
2. **Facade Pattern**: The service acts as a facade, exposing only specific DotCMS client methods needed by the application (like `getPage()`).
155+
142156
### 3. Configure Routes
143157

158+
DotCMS allows content authors to create pages without developer intervention. To support this, we use a catch-all route that handles all page requests through a single controller.
159+
144160
In `config/routes.yaml`, add a catch-all route to handle DotCMS pages:
145161

146162
```yaml
@@ -224,6 +240,10 @@ class CatchAllController extends AbstractController
224240
}
225241
```
226242

243+
This controller serves as the central entry point for all DotCMS page requests. It retrieves the current request path, fetches the corresponding page from DotCMS via the service, and renders it using the page template.
244+
245+
The controller also handles error cases by mapping DotCMS exceptions to appropriate Symfony HTTP exceptions, ensuring proper error responses.
246+
227247
### 5. Create Twig Extension
228248

229249
Create a Twig extension to help with rendering DotCMS content in `src/Twig/DotCMSExtension.php`:
@@ -328,6 +348,8 @@ class DotCMSExtension extends AbstractExtension
328348
}
329349
```
330350

351+
This Twig extension provides utility functions for rendering DotCMS content in templates - handling container data extraction, content-type HTML generation, and proper attribute formatting for DotCMS elements.
352+
331353
### 6. Create Templates
332354

333355
Create the necessary Twig templates to render DotCMS content:
@@ -438,6 +460,26 @@ symfony server:start
438460
4. The Twig extension provides helper functions for rendering DotCMS containers and content.
439461
5. Content-type specific templates render each content type appropriately.
440462

463+
```mermaid
464+
sequenceDiagram
465+
participant User
466+
participant Symfony as Symfony Router
467+
participant Controller as CatchAllController
468+
participant Service as DotCMSService
469+
participant DotCMS as DotCMS API
470+
participant Twig as Twig Templates
471+
472+
User->>Symfony: Request URL
473+
Symfony->>Controller: Route to show() method
474+
Controller->>Service: getPage(path)
475+
Service->>DotCMS: API Request
476+
DotCMS-->>Service: Return PageAsset
477+
Service-->>Controller: Return PageAsset
478+
Controller->>Twig: Render with page data
479+
Twig->>Twig: Process with Twig Extensions
480+
Twig-->>User: Return rendered HTML
481+
```
482+
441483
## Error Handling
442484

443485
The application includes comprehensive error handling:

0 commit comments

Comments
 (0)