Guides

General Structure

You can extend the guides with your own Composer-based Symfony extension.

composer.json

Each Composer package must have a file composer.json . See an example here:

your-extension/composer.json
{
  "name": "t3docs/typo3-docs-theme",
  "description": "A theme for use in the phpdocumentor",
  "type": "library",
  "license": "MIT",
  "homepage": "https://docs.typo3.org",
  "autoload": {
    "psr-4": {
      "T3Docs\\Typo3DocsTheme\\": "src/"
    }
  },
  "require": {
    "phpdocumentor/guides-theme-bootstrap": "dev-main"
  }
}

The PHP sources can be found in the directory src then as is stated in line 8 in the composer.json .

Create an extension

For the PHP package to be an extension you need a class extending \Symfony\Component\DependencyInjection\Extension\Extension by implementing the interface Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface we can also add our own configurations to our extension:

your-extension/DependencyInjection/YourExtension.php
<?php

declare(strict_types=1);

namespace T3Docs\Typo3DocsTheme\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;

use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use function dirname;

class Typo3DocsThemeExtension extends Extension implements PrependExtensionInterface
{
    /** @param mixed[] $configs */
    public function load(array $configs, ContainerBuilder $container): void
    {
    }

    public function prepend(ContainerBuilder $container): void
    {
        $loader = new PhpFileLoader(
            $container,
            new FileLocator(dirname(__DIR__, 2) . '/resources/config'),
        );
        $loader->load('your-extension.php');
        $container->prependExtensionConfig('guides', [
            'themes' => [
                'typo3docs' => [
                    'extends' => 'bootstrap',
                    'templates' => [dirname(__DIR__, 2) . '/resources/template'],
                ],
            ],
        ]);
    }
}

Lines 24 to 28 load a Dependency Injection configuration file. Lines 29 to 36 configure the directory overriding the default templates. Read chapter Extending Templates to learn more about this.

Dependency Injection configuration

your-extension/resources/config/your-extension.php
<?php

declare(strict_types=1);

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use YourVendor\YourExtension\Directives\SomeDirective;

return static function (ContainerConfigurator $container): void {
    $container->services()
        ->defaults()
        ->autowire()
        ->autoconfigure()
        ->set(SomeDirective::class)
        ->tag('phpdoc.guides.directive');
};

This is the place to register custom classes such as directives, text roles, custom compiler passes etc. You can also read about configuration files here: https://symfony.com/doc/current/bundles/configuration.html

Search results