CakePHP中面向方面的编程
问题描述:
我是CakePHP的新手,我正在尝试使用Go! AOP在我的测试应用程序中。CakePHP中面向方面的编程
虽然我按照指南导入Go!通过将它添加到我的composer.json中,似乎找不到AspectKernel类。
<?php
// app/ApplicationAspectKernel.php
namespace Application;
use Go\Core\AspectKernel;
use Go\Core\AspectContainer;
/**
* Application Aspect Kernel
*/
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());
}
}
错误:类 '去\核心\ AspectKernel' 未找到
文件:/Applications/XAMPP/xamppfiles/htdocs/test/app/Application/ApplicationAspectKernel.php
如果有任何人谁之前解决了这个问题,我很想听听你的意见。
这里是我的composer.json“require”值。
"require": {
"php": ">=5.3.0",
"ext-mcrypt": "*",
"goaop/framework": "dev-master"
},
CakePHP的似乎是一个相当实用的框架一起工作,我希望我可以申请AOP那里不再需要手动将日志功能的开始和结束(测量的功能的性能)
答
它看起来像你把这个类放在/ Applications/XAMPP/xamppfiles/htdocs/test/app(第一行注释)中,并且正在调用命名空间Application,尝试使用App命名空间。
我走了!在我的应用程序工作。
在/webroot/index.php把这个使用下面的语句:
use App\ApplicationAspectKernel;
$aspect = ApplicationAspectKernel::getInstance();
$aspect->init(array(
'debug' => true, // use 'false' for production mode
'cacheDir' => dirname(__DIR__).'/tmp/aop',
'includePaths' => [
dirname(__DIR__) . '/src'
]
));
我已经忽略configureAop方法里面ApplicationAspectKernel @triggers注释:
protected function configureAop(AspectContainer $container) {
// use Doctrine\Common\Annotations\AnnotationReader;
AnnotationReader::addGlobalIgnoredName('triggers');
$container->registerAspect(new CacheAspect());
}
从你exlanation听起来如果你所做的只是将条目添加到你的'composer.json'文件中,而不是实际安装它。 – ndm
为什么你需要AOP来衡量函数调用的性能?只需使用Xdebug并分析您的应用程序?还有真正的性能问题,或者你是否尽早优化?早期优化是每个截止日期的敌人。 – burzum
@ndm:我已经运行了作曲家更新并确认goaop/framework位于Vendors文件夹中,所以我认为我可以安装。 – lynrd