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