2015-09-25 73 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; 
}