Go\Core\GoAspectContainer::registerAspect PHP Méthode

registerAspect() public méthode

Register an aspect in the container
public registerAspect ( Go\Aop\Aspect $aspect )
$aspect Go\Aop\Aspect Instance of concrete aspect
    public function registerAspect(Aop\Aspect $aspect)
    {
        $refAspect = new ReflectionClass($aspect);
        $this->set("aspect.{$refAspect->name}", $aspect, array('aspect'));
        $this->addResource($refAspect->getFileName());
    }

Usage Example

 /**
  * Tests that aspect can be registered and accessed
  */
 public function testAspectCanBeRegisteredAndReceived()
 {
     $aspect = $this->getMock(Aspect::class);
     $aspectClass = get_class($aspect);
     $this->container->registerAspect($aspect);
     $this->assertSame($aspect, $this->container->getAspect($aspectClass));
     // Verify that tag is working
     $aspects = $this->container->getByTag('aspect');
     $this->assertSame(array("aspect.{$aspectClass}" => $aspect), $aspects);
 }