|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a Symfony 7.2 application that demonstrates integration with DotCMS using the DotCMS PHP SDK. It serves as a headless CMS frontend that dynamically renders pages, layouts, containers, and content from DotCMS. |
| 8 | + |
| 9 | +## Key Architecture Components |
| 10 | + |
| 11 | +### Core Integration Pattern |
| 12 | +- **Catch-all routing**: Single controller (`CatchAllController`) handles all page requests via a catch-all route |
| 13 | +- **Service layer**: `DotCMSService` wraps the DotCMS PHP SDK client for consistent API access |
| 14 | +- **Twig extensions**: `DotCMSExtension` provides template functions for rendering DotCMS content |
| 15 | +- **Exception mapping**: DotCMS SDK exceptions are mapped to appropriate Symfony HTTP exceptions |
| 16 | + |
| 17 | +### DotCMS Integration Flow |
| 18 | +1. Symfony router matches catch-all route to `CatchAllController::show()` |
| 19 | +2. Controller extracts path and optional query parameters (language_id, mode, personaId, publishDate) |
| 20 | +3. `DotCMSService` creates page request with parameters and fetches from DotCMS API |
| 21 | +4. Page data (layout, containers, contentlets) is passed to Twig templates |
| 22 | +5. Twig extension functions render content-type specific templates or fall back to SDK utilities |
| 23 | + |
| 24 | +### Template Architecture |
| 25 | +- `templates/page.html.twig`: Main page template that renders layout rows/columns |
| 26 | +- `templates/dotcms/container.twig`: Container template with contentlet rendering |
| 27 | +- `templates/dotcms/content-types/`: Content-type specific templates (banner.twig, product.twig, etc.) |
| 28 | +- `templates/dotcms/header.twig`: Navigation rendering using DotCMS navigation API |
| 29 | + |
| 30 | +## Development Commands |
| 31 | + |
| 32 | +### Start Development Server |
| 33 | +```bash |
| 34 | +symfony server:start |
| 35 | +``` |
| 36 | + |
| 37 | +### Testing |
| 38 | +```bash |
| 39 | +# Run all tests |
| 40 | +vendor/bin/phpunit |
| 41 | + |
| 42 | +# Or using Symfony's PHPUnit bridge |
| 43 | +php bin/phpunit |
| 44 | +``` |
| 45 | + |
| 46 | +### Dependency Management |
| 47 | +```bash |
| 48 | +# Install dependencies |
| 49 | +composer install |
| 50 | + |
| 51 | +# For local SDK development |
| 52 | +COMPOSER=composer.dev.json composer install |
| 53 | +``` |
| 54 | + |
| 55 | +### Cache and Assets |
| 56 | +```bash |
| 57 | +# Clear cache |
| 58 | +php bin/console cache:clear |
| 59 | + |
| 60 | +# Install assets |
| 61 | +php bin/console assets:install |
| 62 | + |
| 63 | +# Update importmap |
| 64 | +php bin/console importmap:install |
| 65 | +``` |
| 66 | + |
| 67 | +## Configuration |
| 68 | + |
| 69 | +### Environment Variables |
| 70 | +- `DOTCMS_HOST`: DotCMS instance URL (default: https://demo.dotcms.com) |
| 71 | +- `DOTCMS_API_KEY`: API key for DotCMS authentication |
| 72 | + |
| 73 | +### Service Configuration |
| 74 | +DotCMS client is configured in `config/services.yaml`: |
| 75 | +- `dotcms.client`: Main DotCMSClient service |
| 76 | +- `dotcms.config`: Configuration with host, API key, and client options |
| 77 | +- Client timeout: 30 seconds, SSL verification enabled |
| 78 | +- Debug logging enabled for development |
| 79 | + |
| 80 | +## Key Files and Their Purpose |
| 81 | + |
| 82 | +### Controllers |
| 83 | +- `src/Controller/CatchAllController.php`: Handles all page requests, fetches from DotCMS, maps exceptions |
| 84 | + |
| 85 | +### Services |
| 86 | +- `src/Service/DotCMSService.php`: Wraps DotCMS client, provides page and navigation methods with parameter support |
| 87 | + |
| 88 | +### Twig Extensions |
| 89 | +- `src/Twig/DotCMSExtension.php`: Template functions for content rendering, HTML attributes, grid classes |
| 90 | + |
| 91 | +### Templates |
| 92 | +- `templates/page.html.twig`: Main page template with layout rendering |
| 93 | +- `templates/dotcms/container.twig`: Container and contentlet rendering with DotCMS attributes |
| 94 | +- `templates/dotcms/content-types/`: Content-type specific templates |
| 95 | + |
| 96 | +## Working with Content Types |
| 97 | + |
| 98 | +To add support for new content types: |
| 99 | +1. Create template in `templates/dotcms/content-types/{content-type}.twig` |
| 100 | +2. Template receives `content` variable (Contentlet object) and `dotcms_host` variable |
| 101 | +3. The `generateHtmlBasedOnProperty` function automatically finds and renders the template |
| 102 | +4. Falls back to SDK's `simpleContentHtml` if no template exists |
| 103 | + |
| 104 | +## Error Handling |
| 105 | + |
| 106 | +The application maps DotCMS SDK exceptions to Symfony HTTP exceptions: |
| 107 | +- `HttpException` codes 400, 401, 404, 500, 503 map to corresponding Symfony exceptions |
| 108 | +- `ResponseException` maps to `ServiceUnavailableHttpException` |
| 109 | +- All unmapped exceptions default to `ServiceUnavailableHttpException` |
| 110 | + |
| 111 | +## Development Notes |
| 112 | + |
| 113 | +- Uses Symfony 7.2 with PHP 8.2+ requirement |
| 114 | +- Includes Doctrine ORM, Twig, Stimulus, and other standard Symfony components |
| 115 | +- PHPUnit configured for testing with Symfony bridge |
| 116 | +- Asset mapper handles frontend assets (CSS, JS) |
| 117 | +- Development uses local PHP SDK when `composer.dev.json` is specified |
0 commit comments