2017 © Pedro Peláez
 

library add-call-to-remote-service-bundle

Symfony2 bundle that allows injecting method from one service declaration in DI to another

image

ojezu/add-call-to-remote-service-bundle

Symfony2 bundle that allows injecting method from one service declaration in DI to another

  • Wednesday, March 14, 2018
  • by ojezu
  • Repository
  • 1 Watchers
  • 2 Stars
  • 3,439 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 7 % Grown

The README.md

OJezu/AddCallToRemoteServiceBundle

This bundle allows adding calls in container to other services, as though they were declared there. Allows some decoupling - the hottest thing in OOP., (*1)

Symfony 3.4 and 4.0 Note

As of version 3.4 and 4.0 of Symfony, Dependency Injector is able to find all tagged services on its own:
http://symfony.com/doc/current/service_container/tags.html#reference-tagged-services, (*2)

This Bundle still works, and can be useful in some cases, e.g. when it's impossible to overwrite or modify declaration of the "parent" class., (*3)

Installation

composer require ojezu/add-call-to-remote-service-bundle

Usage

Register this bundle in app/appKernel.php:, (*4)

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new OJezu\ConfigurableDiscriminationBundle\AddCallToRemoteServiceBundle(),
            // app bundles
            new Acme\TestBundle\ParentBundle(),
            new Acme\TestBundle\ChildABundle(),
            new Acme\TestBundle\ChildBBundle(),
        );
        return $bundles;
    }
}

Now, instead of:, (*5)

services:
    acme.root_service:
        class: Acme\Services\RootService
        calls:
            - ['registerChildService', ['Foo', '@acme.children.foo']]
            - ['registerChildService', ['Bar', '@acme.children.bar', {'foo': 'bar'}]]

    acme.children.foo:
        class: Acme\Services\Children\FooService

    acme.children.bar:
        class: Acme\Services\Children\BarService

You can do this!, (*6)

services:
    acme.root_service:
        class: Acme\Services\RootService
services:
    acme.children.foo:
        class: Acme\Services\Children\FooService
        public: false
        tags:
          - name: 'ojezu.add_call_to_remote_service'
            remote_service: '@acme.root_service'
            method: 'registerChildService'
            argument.0: 'Foo'
            argument.1: '@'
            argument.2.foo: 'bar'
services:
    acme.children.bar:
        class: Acme\Services\Children\BarService
        public: false
        tags:
          - name: 'ojezu.add_call_to_remote_service'
            remote_service: '@acme.root_service'
            method: 'registerChildService'
            argument.0: 'Bar'
            argument.1: '@'

'@' will resolve to acme.children.foo and acme.children.bar respectively!, (*7)

Questions

Why argument.0, argument.1, argument.2.foo and not an array?

Symfony/DependencyInjector does not support that. All tag attributes must be scalars, because of XML format supported and used internally by DependencyInjector., (*8)

Will this load my services when they are unneeded?

No! This bundle modifies only definitions of services in container, it does not need to (and does not) load referenced services., (*9)

License

MIT, (*10)

The Versions

14/03 2018

dev-master

9999999-dev

Symfony2 bundle that allows injecting method from one service declaration in DI to another

  Sources   Download

MIT

The Requires

 

The Development Requires

by Krzysztof Chrapka

14/03 2018

v1.1.0

1.1.0.0

Symfony2 bundle that allows injecting method from one service declaration in DI to another

  Sources   Download

MIT

The Requires

 

The Development Requires

by Krzysztof Chrapka

16/03 2016

v0.0.1

0.0.1.0

Symfony2 bundle that allows configuring Doctrine discrimination maps in children bundles.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Krzysztof Chrapka

16/03 2016

v1.0.0

1.0.0.0

Symfony2 bundle that allows configuring Doctrine discrimination maps in children bundles.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Krzysztof Chrapka