2015-09-25 68 views
0

我正在嘗試實現緩存到symfony應用程序。 我使用FOSHttpCacheBundle,它工作得很好,我沒有問題。 但是,當我在做我的測試我有一個頁面上此錯誤:如何才能找到「無法重新聲明類」錯誤

Compile Error: Cannot redeclare class Symfony\Component\EventDispatcher\Event

問題是我不知道我怎麼能找到的bug ...... 我只有在這個頁面得到它。 我唯一知道的是可以通過註釋行

$kernel = new AppCache($kernel); 

從而導致

require_once __DIR__.'/AppKernel.php'; 

use FOS\HttpCache\SymfonyCache\UserContextSubscriber; 
use FOS\HttpCache\SymfonyCache\PurgeSubscriber; 
use FOS\HttpCacheBundle\SymfonyCache\EventDispatchingHttpCache; 

class AppCache extends EventDispatchingHttpCache 
{ 
    public function getDefaultSubscribers() 
    { 
     $subscribers[] = new PurgeSubscriber(array('purge_client_ips' => 'localhost')); 

     return $subscribers; 
    } 
} 

所以有一個想法,我需要做什麼檢查修復這個bug?

回答

0

這是一個很難說「爲什麼」,無需調試,但你可以嘗試檢查,如果類已經註冊

if(!class_exists('Symfony\Component\EventDispatcher\Event'){ 
      use FOS\HttpCacheBundle\SymfonyCache\EventDispatchingHttpCache; 
}