Extension
Extensions are a way to extend the package with your own generators and tokenizers. This is useful if you want to generate something that is not supported by the package out of the box.
Configuration
In order to use extensions, you need to register them in the config/arch.php
file. The extensions
key is an array of fully qualified class names that implements the BaseCodeOy\Arch\Extension\ExtensionInterface
interface. You can review the contents of the config/arch.php
file here.
Interface
php
<?php
declare(strict_types=1);
namespace BaseCodeOy\Arch\Contract;
interface ExtensionInterface
{
public function register(array $configuration): void;
}
Example
php
<?php
declare(strict_types=1);
namespace BaseCodeOy\Arch\Extension;
use BaseCodeOy\Arch\Contract\ExtensionInterface;
use BaseCodeOy\Arch\Facade\Environment;
final readonly class LaravelExtension implements ExtensionInterface
{
public function register(array $configuration): void
{
foreach ($configuration['generators'] as $generator) {
Environment::generators()->add($generator);
}
foreach ($configuration['statements'] as $statement) {
Environment::statements()->add($statement);
}
foreach ($configuration['tokenizers'] as $tokenizerClassName => $tokenizerConfiguration) {
if (\is_string($tokenizerClassName)) {
Environment::tokenizers()->add($tokenizerClassName, $tokenizerConfiguration);
} else {
Environment::tokenizers()->add($tokenizerConfiguration);
}
}
}
}