2017-02-12 120 views
1

我是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那裏不再需要手動將日誌功能的開始和結束(測量的功能的性能)

+0

從你exlanation聽起來如果你所做的只是將條目添加到你的'composer.json'文件中,而不是實際安裝它。 – ndm

+0

爲什麼你需要AOP來衡量函數調用的性能?只需使用Xdebug並分析您的應用程序?還有真正的性能問題,或者你是否儘早優化?早期優化是每個截止日期的敵人。 – burzum

+0

@ndm:我已經運行了作曲家更新並確認goaop/framework位於Vendors文件夾中,所以我認爲我可以安裝。 – lynrd

回答

0

它看起來像你把這個類放在/ 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()); 
}