wavevision / di-service-annotation
Register DI services using annotation for Nette Framework.
Installs: 10 856
Dependents: 6
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 2
Open Issues: 5
Requires
- php: >=7.4
- doctrine/annotations: ^1.8
- nette/finder: ^2.5
- wavevision/utils: ^2.13
Requires (Dev)
- mikey179/vfsstream: ^1.6
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^9.4
- wavevision/coding-standard: ^5.2
This package is auto-updated.
Last update: 2024-08-19 23:43:07 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: 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.
Configuration option
Required
sourceDirectory: string
– location of servicesoutputFile: string
– output file for registered services
Optional
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