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.