simplikocz / di-service-annotation
Register DI services using annotation for Nette Framework.
Package info
github.com/SimplikoCZ/wavevision-di-service-annotation
pkg:composer/simplikocz/di-service-annotation
5.3
2026-05-06 20:36 UTC
Requires
- php: ^8.4
- doctrine/annotations: ^2.0
- nette/finder: ^3.0
- wavevision/utils: ^3.0
Requires (Dev)
- mikey179/vfsstream: ^1.6.8
- php-coveralls/php-coveralls: ^2.7
- phpunit/phpunit: ^11.0
- wavevision/coding-standard: ^6.0
This package is auto-updated.
Last update: 2026-09-01 06:30:03 UTC
README
DIService Annotation
Helper for registering Nette DI services via Doctrine Annotations, factory generator and inject generator.
Install
composer require --dev wavevision/di-service-annotation
Note: Install phpstan-nette if you need support for strict return types.
Usage
Annotate your service
use Wavevision\DIServiceAnnotation\DIService; /** * @DIService(params={"%wwwDir%"}, generateInject=true, generateFactory=true) */ class ExampleService { }
Create runner script
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:
Annotation options
enableInject: bool– will addinject: onto generated service config (defaulttrue)generateComponent: bool– will generate<className>Componenttrait, with factory andcreateComponent<ClassName>implementedgenerateFactory: bool– will generate<ClassName>Factoryinterface withcreatefunctiongenerateInject: 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.
Configuration option
Required
sourceDirectory: string– location of servicesoutputFile: string– output file for registered services
Optional
setMask: string– mask for file locator - default*.phpsetFileMapping: 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 - defaultfalseenableFileValidation– check each file for fatal errors before reading annotation, skip file on errorautoloadFile: string– file for class autoloading, e.g.vendor/autoload.phptempDir: string– enable cache, directory for cache file, only changed files are validated