-
-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Am running symfony 4.0.5, and trying to get go-aop working.
Although I see that my test aspect and advisor are loaded, tried several ways to fire up through @before, @around, the advise never fires up...
$ composer create-project symfony/skeleton:^4.0 sf4
$ cd sf4
$ composer require roave/security-advisories
$ composer require goaop/goaop-symfony-bundle
# moved GoAppBundle to the top in config/bundles.php
$ composer require logger
FILE CONTENTS src/Command/ShineCommand.php:
<?php
namespace App\Command;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class ShineCommand extends Command
{
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
parent::__construct(); // you *must* call the parent constructor
}
protected function configure()
{
$this->setName('app:shine');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->logger->info( $string = 'Waking up the sun' );
// ...
}
}
FILE CONTENTS Aspect/LoggingAspect.php:
<?php
namespace App\Aspect;
use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Before;
use Psr\Log\LoggerInterface;
/**
* Application logging aspect
*/
class LoggingAspect implements Aspect
{
/**
* @var LoggerInterface
*/
private $logger;
public function __construct(LoggerInterface $logger)
{
print "ASPECT INIT\n";
$this->logger = $logger;
}
/**
* Writes a log info before method execution
*
* @param MethodInvocation $invocation
* @Before("execution(public **->*(*))")
*/
public function beforeMethod(MethodInvocation $invocation)
{
print "ASPECT FIRED in ".get_class($this)."\n";
$this->logger->info($invocation, $invocation->getArguments());
}
}
FILE CONTENTS (Appended) config/services.yaml:
parameters:
container.dumper.inline_class_loader: false
services:
logging.aspect:
class: App\Aspect\LoggingAspect
public: true
arguments: ["@logger"]
tags:
- { name: goaop.aspect }
go_aop:
options:
debug: true
app_dir: "%kernel.root_dir%/../src"
cache_dir: "%kernel.cache_dir%/aspect"
features: # framework/src/Aop/Features.php
- INTERCEPT_FUNCTIONS
- INTERCEPT_INITIALIZATIONS
- INTERCEPT_INCLUDES
$ console debug:container goaop
Select one of the following services to display its information:
[0 ] goaop.aspect.kernel
[1 ] goaop.aspect.container
[2 ] goaop.cache.path.manager
[3 ] goaop.cache.warmer
[4 ] goaop.bridge.doctrine.metadata_load_interceptor
[5 ] goaop.command.warmup
[6 ] goaop.command.debug_advisor
[7 ] goaop.command.debug_aspect
[8 ] console.command.public_alias.goaop.command.warmup
[9 ] console.command.public_alias.goaop.command.debug_advisor
[10] console.command.public_alias.goaop.command.debug_aspect
$ bin/console debug:aspect
Aspect debug information
========================
Go\Symfony\GoAopBundle\Kernel\AspectSymfonyKernel has following enabled aspects:
App\Aspect\LoggingAspect
------------------------
Defined in: /home/holzmann/shared/pkg/sf4/src/Aspect/LoggingAspect.php
Application logging aspect
Pointcuts and advices
--------- ----------------------------------------
Type Identifier
--------- ----------------------------------------
Advisor App\Aspect\LoggingAspect->beforeMethod
--------- ----------------------------------------
$ bin/console debug:advisor
Advisor debug information
=========================
List of registered advisors in the container
---------------------------------------- ----------------------------
Id Expression
---------------------------------------- ----------------------------
App\Aspect\LoggingAspect->beforeMethod execution(public **->*(*))
---------------------------------------- ----------------------------
$ console debug:container goaop.aspect.container
Information for Service "goaop.aspect.container"
Option Value
Service ID goaop.aspect.container
Class Go\Core\GoAspectContainer
Tags -
Calls registerAspect, registerAspect
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired no
Autoconfigured no
Factory Service goaop.aspect.kernel
Factory Method getContainer
$ console debug:container goaop.aspect.kernel
Information for Service "goaop.aspect.kernel"
Option Value
Service ID goaop.aspect.kernel
Class Go\Symfony\GoAopBundle\Kernel\AspectSymfonyKernel
Tags -
Calls init
Public yes
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired no
Autoconfigured no
Factory Class Go\Symfony\GoAopBundle\Kernel\AspectSymfonyKernel
Factory Method getInstance
$ console app:shine -vv
[2018-02-16 14:19:48] app.INFO: Waking up the sun [] []