Php Go AOP没有捕捉到我的方面
我正在尝试使用GoAOP来允许我将方面用于我正在进行的PHP项目。我使用composer安装goaop/framework。我已经为我的方面写了如下文件。我知道CalendarController在运行,因为在其中一个函数中,我可以看到一个回声。你知道为什么这样不行吗 index.phpPhp Go AOP没有捕捉到我的方面,php,windows,iis,aop,goaop,Php,Windows,Iis,Aop,Goaop,我正在尝试使用GoAOP来允许我将方面用于我正在进行的PHP项目。我使用composer安装goaop/framework。我已经为我的方面写了如下文件。我知道CalendarController在运行,因为在其中一个函数中,我可以看到一个回声。你知道为什么这样不行吗 index.php // Initialize an application aspect container $applicationAspectKernel = App\Http\applicationAspectKernel
// Initialize an application aspect container
$applicationAspectKernel = App\Http\applicationAspectKernel::getInstance();
$applicationAspectKernel->init(array(
'debug' => true, // use 'false' for production mode
// Cache directory
'cacheDir' => __DIR__ . '/path/to/cache/for/aop',
// Include paths restricts the directories where aspects should be applied, or empty for all source files
'includePaths' => array(
__DIR__ . '/../app'
)
));
MonitorAspect.php
namespace Aspects;
use Go\Aop\Aspect;
use Go\Aop\Intercept\FieldAccess;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\After;
use Go\Lang\Annotation\Before;
use Go\Lang\Annotation\Around;
use Go\Lang\Annotation\Pointcut;
use Psr\Log\LoggerInterface;
class MonitorAspect implements Aspect
{
/**
* Method that will be called before real method
*
* @param MethodInvocation $invocation Invocation
* @Before("execution(public App\Http\Controllers\CalendarController->*(*))")
*/
public function beforeMethodExecution(MethodInvocation $invocation)
{
\Monolog\Handler\error_log("Is this being called at all? Yes");
$obj = $invocation->getThis();
echo 'Calling Before Interceptor for method: ',
is_object($obj) ? get_class($obj) : $obj,
$invocation->getMethod()->isStatic() ? '::' : '->',
$invocation->getMethod()->getName(),
'()',
' with arguments: ',
json_encode($invocation->getArguments()),
"<br>\n";
}
}
Edit:修复了@Before语句。我已经尝试了两天,也遇到了问题:(.您解决了这个问题吗?您是否碰巧使用了windows操作系统。另外,请注意我刚才所做的编辑。我确实对其进行了某种程度的修复。出于某种原因,windows IIS不能与Aspect一起工作,不知道为什么。其他人声称他们可以与WAMP或MAMP一起工作(不确定是哪个),这对我不起作用,但一个朋友将我的代码移植到他的Mac电脑上,它与我发布的编辑一起工作(他做了最初的更正).所以我有点愤怒地退出windows,把整个东西放在ubuntu服务器虚拟机上。不确定这是否是最好的方法,但它起作用了。你能确认你的web服务器可以写入
cacheDir
路径吗?我的项目仍然不起作用,@wolfcall你能给我看看你的完整示例项目吗?
use Go\Core\AspectKernel;
use Go\Core\AspectContainer;
use Aspects\MonitorAspect;
/**
* Description of aspectKernel
*
*
*/
class applicationAspectKernel extends AspectKernel{
/**
* Configure an AspectContainer with advisors, aspects and pointcuts
*
* @param AspectContainer $container
*
* @return void
*/
protected function configureAop(AspectContainer $container)
{
$container->registerAspect(new MonitorAspect());
}
}