2017 © Pedro PelĂĄez
 

library nucleus-bundle

Reusable library

image

mpoiriert/nucleus-bundle

Reusable library

  • Wednesday, March 26, 2014
  • by mpoiriert
  • Repository
  • 1 Watchers
  • 0 Stars
  • 773 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Nucleus-Bundle

Build Status, (*1)

This is a base bundle that is use by other bundle Nucleus bundle., (*2)

By itself it have a generic compiler pass to help modifying the container for annotation., (*3)

Also it does implement the Nucleus\Invoker\IInvoker as a service., (*4)

It also redefined the event_dispatcher service for the class Nucleus\Bundle\CoreBundle\EventDispatcher\InvokerEventDispatcher., (*5)

NucleusCompilerPass

If you need to do something base on annotation you can use the NucleusCompilerPass to simplify your life., (*6)

You must define a annotation like documented in the doctrine annotation project., (*7)

Once this is done you must create a class that will implements Nucleus\Bundle\CoreBundle\DependencyInjection\IAnnotationContainerGenerator that will receive a Nucleus\Bundle\CoreBundle\GenerationContext, (*8)

Than you need to add a mapping between your annotation and the generator in the nucleus_core configuration., (*9)

nucleus_core:
    annotation_container_generators:
        test_annotation:
            annotationClass: Nucleus\Bundle\CoreBundle\Tests\DependencyInjection\Annotation
            generatorClass: Nucleus\Bundle\CoreBundle\Tests\DependencyInjection\AnnotationTagGenerator

From there you can do what ever you want like you were in a compiler pass., (*10)

You also have some static method in Nucleus\Bundle\CoreBundle\DependencyInjection\Definition that could help you., (*11)

If you want a example you can check the test class Nucleus\Bundle\CoreBundle\Tests\DependencyInjection\AnnotationTagGenerator and also the mpoiriert/binder-bundle, (*12)

Nucleus\Bundle\CoreBundle\EventDispatcher\InvokerEventDispatcher

The way you must should use the new event dispatcher is by using the InvokerEventDispatcher::notify() method who does receive a $subject, $eventName and $parameters as parameter. The Invoker will map the parameters to the "listeners" of the event. The created "Event" object is the return value. You should not create typed Event by this means since the service should not manipulate the event by itself (unless you want to stop the propagation). It does work like the Request and a controller but with event., (*13)

You must also think about the way you will do unit test, no more Event faking just plane call. Also you could reuse a method of a service to be call directly without having to redefine another method or a mediator for the event itself., (*14)

<?php

 $eventDispatcher = $client->getContainer()->get('event_dispatcher');

 /* @var $eventDispatcher \Nucleus\Bundle\CoreBundle\EventDispatcher\InvokerEventDispatcher */
 $eventDispatcher->addListenerService('WebTestCase.test',array('test_listener_service','listen'));

 $user = new User();

 $event = $eventDispatcher->notify($user,'User.test',array('param1'=>1));

 class ListenerService
 {
     public function listen(User $user,IEvent $event, $eventName, $param1)
     {
         //...
     }
 }

The Invoker is in charge of mapping the $subject, $event, $eventName and any parameters pass to the event., (*15)

You can still create typed event but you will need to use the original EventDispatcherInterface::dispatch() method. Be sure to extends from the Nucleus\Bundle\CoreBundle\EventDispatcher if you want to use the mapping functionality of parameters. You could override the Event::getParameters() method an return processed parameter from the event., (*16)

The Versions

26/03 2014

dev-master

9999999-dev

Reusable library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Martin Poirier ThĂ©orĂȘt

library bundle symfony nucleus