Helper for registering Nette DI services via Doctrine Annotations, factory generator and inject generator.
composer require --dev wavevision/di-service-annotation
Note: Install phpstan-nette if you need support for strict return types.
use Wavevision\DIServiceAnnotation\DIService;
/**
* @DIService(params={"%wwwDir%"}, generateInject=true, generateFactory=true)
*/
class ExampleService
{
}
For example bin/extract-services.php
use Wavevision\DIServiceAnnotation\Configuration;
use Wavevision\DIServiceAnnotation\Runner;
Runner::run(new Configuration('sourceDirectory', 'services.neon'));
Running this script with php bin/extract-services.php
will generate from class following:
enableInject: bool
โ will addinject: on
to generated service config (defaulttrue
)generateComponent: bool
โ will generate<className>Component
trait, with factory andcreateComponent<ClassName>
implementedgenerateFactory: bool
โ will generate<ClassName>Factory
interface withcreate
functiongenerateInject: bool
โ will generateInject<ClassName>
trait with property$<className>
andinject<ClassName>
function implementedparams: string[]
โ list of DI parameters to be passed to service constructortags: string[]
โ list of tags to be used with the service in generated config
For configuration options see Configuration properties.
sourceDirectory: string
โ location of servicesoutputFile: string
โ output file for registered services
setMask: string
โ mask for file locator - default*.php
setFileMapping: array
โ map for splitting configs by namespace
$configuration->setFileMapping([
'RootNamespace\Namespace1' => 'config1.neon',
'RootNamespace\Namespace2' => 'config2.neon',
]);
setInjectGenerator: Inject
โ set custom generator for injectssetFactoryGenerator: Factory
โ set custom generator for factoriessetComponentFactory: Component
โ set custom generator for componentssetRegenerate: bool
โ regenerate all generated code each run - defaultfalse
enableFileValidation
โ check each file for fatal errors before reading annotation, skip file on errorautoloadFile: string
โ file for class autoloading, e.g.vendor/autoload.php
tempDir: string
โ enable cache, directory for cache file, only changed files are validated