Statistics
107
2
3
22d
Badges
Tags
utils
Dependencies

Wavevision DI service annotation

Build Status Coverage Status PHPStan

Helper for registering Nette DI services via Doctrine Annotations, factory generator and inject generator.

Install

composer require --dev wavevision/di-service-annotation

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 add inject: on to generated service config (default true)
  • generateComponent: bool – will generate <className>Component trait, with factory and createComponent<ClassName> implemented
  • generateFactory: bool – will generate <ClassName>Factory interface with create function
  • generateInject: bool – will generate Inject<ClassName> trait with property $<className> and inject<ClassName> function implemented
  • params: string[] – list of DI parameters to be passed to service constructor
  • tags: string[] – list of tags to be used with the service in generated config

For configuration options see Configuration properties.

  • 2.0.0 Change annotation settings

    BC: inject renamed to enableInject to disambiguate inject and generateInject properly

  • 1.0.1 Update coding standard

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com