|
| 1 | +.. include:: /include.rst.txt |
| 2 | + |
| 3 | +.. _extension_structure: |
| 4 | + |
| 5 | +================= |
| 6 | +General Structure |
| 7 | +================= |
| 8 | + |
| 9 | +You can extend the guides with your own Composer-based Symfony extension. |
| 10 | + |
| 11 | +.. _extension_composer: |
| 12 | + |
| 13 | +composer.json |
| 14 | +============= |
| 15 | + |
| 16 | +Each Composer package must have a file `composer.json`. See an example here: |
| 17 | + |
| 18 | +.. literalinclude:: _composer.json |
| 19 | + :language: json |
| 20 | + :caption: your-extension/composer.json |
| 21 | + :lineos: |
| 22 | + |
| 23 | +The PHP sources can be found in the directory `src` then as is stated in line 8 |
| 24 | +in the `composer.json`. |
| 25 | + |
| 26 | +.. _extension_symfony: |
| 27 | + |
| 28 | +Create an extension |
| 29 | +=================== |
| 30 | + |
| 31 | +For the PHP package to be an extension you need a class |
| 32 | +extending `\Symfony\Component\DependencyInjection\Extension\Extension` by |
| 33 | +implementing the interface |
| 34 | +`Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface` we |
| 35 | +can also add our ow configurations to our extension: |
| 36 | + |
| 37 | +.. literalinclude:: _YourExtension.php |
| 38 | + :language: php |
| 39 | + :caption: your-extension/DependencyInjection/YourExtension.php |
| 40 | + :lineos: |
| 41 | + |
| 42 | +Lines 24 to 28 load a :ref:`Dependency Injection configuration <extension_di_configuration>` |
| 43 | +file. Lines 29 to 36 configure the directory overriding the default templates. |
| 44 | +Read chapter :ref:`extending_templates` to learn more about this. |
| 45 | + |
| 46 | +.. note:: |
| 47 | + This is a Symfony extension, not a TYPO3 extension. See also the |
| 48 | + `Symfony documentation about Extensions <https://symfony.com/doc/current/bundles/extension.html>`__. |
| 49 | + |
| 50 | +.. _extension_di_configuration: |
| 51 | + |
| 52 | +Dependency Injection configuration |
| 53 | +=================================== |
| 54 | + |
| 55 | +.. literalinclude:: _your-extension.php |
| 56 | + :language: php |
| 57 | + :caption: your-extension/resources/config/your-extension.php |
| 58 | + :lineos: |
| 59 | + |
| 60 | +This is the place to register custom classes such as directives, text roles, |
| 61 | +custom compiler passes etc. You can also read about configuration files here: |
| 62 | +https://symfony.com/doc/current/bundles/configuration.html |
0 commit comments