|
11 | 11 |
|
12 | 12 | A Symfony bundle that implements the **Single Directory Component (SDC)** methodology for Symfony UX. It bridges the gap between **AssetMapper** and **Twig Components** by providing a fully automated, convention-over-configuration workflow. |
13 | 13 |
|
| 14 | +## Real-world Usage & Developer Experience |
| 15 | + |
| 16 | +This bundle is actively used in production. Here are some real-world examples: |
| 17 | +- [formalitka.mostka.sk](https://formalitka.mostka.sk/) |
| 18 | +- [mostka.sk](https://mostka.sk/) |
| 19 | +- [ycon.cc](https://ycon.cc) |
| 20 | + |
| 21 | +### Developer Evaluation |
| 22 | +Working with UX SDC provides an excellent developer experience. A recommended project structure organizes the code into distinct functional areas: |
| 23 | +- **UI**: Generic interface elements (e.g., `Button`, `Spinner`, `Tabs`). |
| 24 | +- **Layout**: Structural page elements (e.g., `TopBar`, `Footer`, `FlashMessage`). |
| 25 | +- **Component**: Reusable feature blocks. |
| 26 | +- **Page**: Complete page components (e.g., `Homepage`, `AboutUs`). |
| 27 | + |
| 28 | +A significant advantage of this architecture is the ability to place Symfony controllers directly within the page-level SDC component directory (e.g., `HomepageAction.php`). The controller merely handles routing and renders the base layout, while all business and presentation logic remains encapsulated in isolated SDC components. |
| 29 | + |
| 30 | +Because the code is highly granular and strictly structured, AI tools work exceptionally well within this architecture, easily generating robust and creative design implementations. |
| 31 | + |
14 | 32 | ## The Concept |
15 | 33 |
|
16 | 34 | This bundle is inspired by the architectural challenges discussed in **["A Better Architecture for Your Symfony UX Twig Components"](https://hugo.alliau.me/blog/posts/a-better-architecture-for-your-symfony-ux-twig-components)** by **Hugo Alliaume**. |
@@ -214,7 +232,54 @@ This will create: |
214 | 232 | - `src/Component/UI/Alert/Alert.php` (PHP logic) |
215 | 233 | - `src/Component/UI/Alert/Alert.html.twig` (Twig template) |
216 | 234 | - `src/Component/UI/Alert/Alert.css` (CSS styles) |
217 | | -- (Optional) `src/Component/Alert/Alert_controller.js` (Stimulus controller) |
| 235 | +- (Optional) `src/Component/UI/Alert/Alert_controller.js` (Stimulus controller) |
| 236 | + |
| 237 | +The maker supports options and interactive mode: |
| 238 | +- `--stimulus` to force generating a Stimulus controller (non-interactive mode will not create it unless explicitly set) |
| 239 | +- `--action` to generate a minimal controller action and a wrapper Twig template for the component |
| 240 | + |
| 241 | +Example with an action: |
| 242 | + |
| 243 | +```bash |
| 244 | +php bin/console make:sdc-component Page:Homepage --action |
| 245 | +``` |
| 246 | + |
| 247 | +This will additionally create: |
| 248 | +- `src/Component/Page/Homepage/HomepageAction.php` (Symfony controller) |
| 249 | +- `src/Component/Page/Homepage/HomepageAction.html.twig` (page template rendering the component) |
| 250 | + |
| 251 | +Generated files contents: |
| 252 | + |
| 253 | +```php |
| 254 | +// src/Component/Page/Homepage/HomepageAction.php |
| 255 | +namespace App\Component\Page\Homepage; |
| 256 | +
|
| 257 | +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 258 | +use Symfony\Component\Routing\Attribute\Route; |
| 259 | +
|
| 260 | +class HomepageAction extends AbstractController |
| 261 | +{ |
| 262 | + #[Route('/en', name: 'app.homepage')] |
| 263 | + public function index(): \Symfony\Component\HttpFoundation\Response |
| 264 | + { |
| 265 | + return $this->render('Page/Homepage/HomepageAction.html.twig'); |
| 266 | + } |
| 267 | +} |
| 268 | +``` |
| 269 | + |
| 270 | +```twig |
| 271 | +{# src/Component/Page/Homepage/HomepageAction.html.twig #} |
| 272 | +{% extends 'layout.html.twig' %} |
| 273 | +
|
| 274 | +{% block content %} |
| 275 | + <twig:Page:Homepage:Homepage /> |
| 276 | +{% endblock %} |
| 277 | +``` |
| 278 | + |
| 279 | +In interactive mode, you will be asked: |
| 280 | +- for the component name (supports `:` or `/` separators, e.g. `UI:Alert` or `UI/Alert`) |
| 281 | +- whether to generate a Stimulus controller |
| 282 | +- whether to generate an Action class and template |
218 | 283 |
|
219 | 284 | --- |
220 | 285 |
|
|
0 commit comments