首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CakePHP中的面向方面编程

CakePHP中的面向方面编程
EN

Stack Overflow用户
提问于 2017-02-12 22:48:37
回答 1查看 281关注 0票数 1

我是CakePHP的新手,我正在尝试使用Go!测试应用程序中的AOP。

尽管我遵循了指南并导入了Go!通过将其添加到我的composer.json中,似乎找不到AspectKernel类。

代码语言:javascript
复制
<?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());
    }
}

错误:找不到'Go\Core\AspectKernel‘类

文件: /Applications/XAMPP/xamppfiles/htdocs/test/app/Application/ApplicationAspectKernel.php

如果有人以前解决过这个问题,我很想听听你的意见。

下面是我的composer.json "require“值。

代码语言:javascript
复制
"require": {
    "php": ">=5.3.0",
    "ext-mcrypt": "*",
    "goaop/framework": "dev-master"
},

CakePHP似乎是一个非常实用的框架,我希望我可以在那里应用面向方面编程,以消除手动为函数的开始和结束放置日志的需要(以测量函数的性能)。

EN

回答 1

Stack Overflow用户

发布于 2017-05-26 18:54:18

看起来你把这个类放在/Applications/XAMPP/xamppfiles/htdocs/test/app中(第一行注释)并且调用了一个命名空间应用程序,尝试使用应用程序命名空间。

我要走了!在开发我的应用程序。

在/webroot/index.php中,将以下内容放在use的语句下面:

代码语言:javascript
复制
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注释:

代码语言:javascript
复制
protected function configureAop(AspectContainer $container) {
    // use Doctrine\Common\Annotations\AnnotationReader;
    AnnotationReader::addGlobalIgnoredName('triggers');
    $container->registerAspect(new CacheAspect());
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42188995

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档