当前位置: 首页>>代码示例>>PHP>>正文


PHP EventManager::addEventSubscriber方法代码示例

本文整理汇总了PHP中Doctrine\Common\EventManager::addEventSubscriber方法的典型用法代码示例。如果您正苦于以下问题:PHP EventManager::addEventSubscriber方法的具体用法?PHP EventManager::addEventSubscriber怎么用?PHP EventManager::addEventSubscriber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\EventManager的用法示例。


在下文中一共展示了EventManager::addEventSubscriber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: setUpEntityManager

 protected static function setUpEntityManager()
 {
     $config = new Configuration();
     $config->setSQLLogger(null);
     $config->setAutoGenerateProxyClasses(true);
     $config->setProxyDir(\sys_get_temp_dir());
     $config->setProxyNamespace('Proxies');
     $config->setMetadataDriverImpl(static::getMetadataDriverImpl());
     $config->setQueryCacheImpl(new ArrayCache());
     $config->setMetadataCacheImpl(new ArrayCache());
     $dbPath = __DIR__ . '/../db.sqlite';
     if (file_exists($dbPath)) {
         unlink($dbPath);
     }
     $connection = ['driver' => 'pdo_sqlite', 'path' => $dbPath];
     // Event listeners
     $interfaces = DoctrineBundleMapping::getDefaultImplementations();
     $evm = new EventManager();
     // Resolve entity target subscriber
     $rtel = new ResolveTargetEntityListener();
     foreach ($interfaces as $model => $implementation) {
         $rtel->addResolveTargetEntity($model, $implementation, []);
     }
     $evm->addEventSubscriber($rtel);
     // Load metadata subscriber
     $lm = new LoadMetadataSubscriber([], $interfaces);
     $evm->addEventSubscriber($lm);
     static::$em = EntityManager::create($connection, $config, $evm);
 }
开发者ID:ekyna,项目名称:commerce,代码行数:29,代码来源:OrmTestCase.php

示例2: setUp

 protected function setUp()
 {
     parent::setUp();
     $evm = new EventManager();
     $evm->addEventSubscriber(new SluggableListener());
     $evm->addEventSubscriber(new TreeListener());
     $this->getMockSqliteEntityManager($evm);
 }
开发者ID:7rin0,项目名称:SF3,代码行数:8,代码来源:TreeSlugHandlerUniqueTest.php

示例3: __construct

 public function __construct()
 {
     // load database configuration from CodeIgniter
     require APPPATH . 'config/database.php';
     //A Doctrine Autoloader is needed to load the models
     // first argument of classloader is namespace and second argument is path
     // setup models/entity namespace
     $entityLoader = new ClassLoader('models', APPPATH);
     $entityLoader->register();
     foreach (glob(APPPATH . 'modules/*', GLOB_ONLYDIR) as $m) {
         $module = str_replace(APPPATH . 'modules/', '', $m);
         $entityLoader = new ClassLoader($module, APPPATH . 'modules');
         $entityLoader->register();
     }
     //Register proxies namespace
     $proxyLoader = new ClassLoader('Proxies', APPPATH . 'Proxies');
     $proxyLoader->register();
     // Set up caches
     $config = new Configuration();
     $cache = new ArrayCache();
     $config->setMetadataCacheImpl($cache);
     $driverImpl = $config->newDefaultAnnotationDriver(array(APPPATH . 'models'));
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     // Set up entity
     $reader = new AnnotationReader($cache);
     $models = array(APPPATH . 'models');
     foreach (glob(APPPATH . 'modules/*/models', GLOB_ONLYDIR) as $m) {
         array_push($models, $m);
     }
     $driver = new AnnotationDriver($reader, $models);
     $config->setMetadataDriverImpl($driver);
     // Setup Gedmo
     $cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader($reader, $cache);
     // create a driver chain for metadata reading
     $driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain();
     // load superclass metadata mapping only, into driver chain
     // also registers Gedmo annotations.NOTE: you can personalize it
     Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);
     $event = new EventManager();
     $timestampableListener = new TimestampableListener();
     $timestampableListener->setAnnotationReader($cachedAnnotationReader);
     $event->addEventSubscriber($timestampableListener);
     $slugListener = new SluggableListener();
     $slugListener->setAnnotationReader($cachedAnnotationReader);
     $event->addEventSubscriber($slugListener);
     // Proxy configuration
     $config->setProxyDir(APPPATH . '/proxies');
     $config->setProxyNamespace('Proxies');
     // Set up logger
     // $logger = new EchoSQLLogger;
     // $config->setSQLLogger($logger);
     $config->setAutoGenerateProxyClasses(TRUE);
     // Database connection information
     $connectionOptions = array('driver' => 'pdo_mysql', 'user' => $db['default']['username'], 'password' => $db['default']['password'], 'host' => $db['default']['hostname'], 'dbname' => $db['default']['database']);
     // Create EntityManager
     $this->em = EntityManager::create($connectionOptions, $config, $event);
 }
开发者ID:santhapa,项目名称:ci-mag-cms,代码行数:58,代码来源:Doctrine.php

示例4: setUp

 public function setUp()
 {
     $this->manager = $this->getContainer()->get('rc_servired.transaction.manager');
     $this->eventManager = $this->manager->getEntityManager()->getEventManager();
     $this->transaction = new Transaction(time());
     $this->subscriber = $this->getMockBuilder('RC\\ServiredBundle\\EventListener\\TransactionSubscriber')->setMethods(array())->setConstructorArgs(array($this->getContainer()->get('event_dispatcher')))->getMock();
     $this->subscriber->expects($this->once())->method('getSubscribedEvents')->will($this->returnValue(array('prePersist', 'postPersist')));
     $this->eventManager->addEventSubscriber($this->subscriber);
 }
开发者ID:krixer,项目名称:ServiredBundle,代码行数:9,代码来源:TransactionSubscriberTest.php

示例5: setUp

 protected function setUp()
 {
     parent::setUp();
     $evm = new EventManager();
     $translatableListener = new TranslatableListener();
     $translatableListener->setTranslatableLocale('en_US');
     $evm->addEventSubscriber($translatableListener);
     $evm->addEventSubscriber(new TimestampableListener());
     $this->getMockSqliteEntityManager($evm);
 }
开发者ID:esserj,项目名称:DoctrineExtensions,代码行数:10,代码来源:ProtectedPropertySupperclassTest.php

示例6: configureEventManager

 /**
  * @return DoctrineEventManager
  */
 public function configureEventManager()
 {
     $eventConfiguration = $this->configuration->get('events');
     foreach ($eventConfiguration['listeners'] as $listener => $events) {
         $this->eventManager->addEventListener((array) $events, new $listener());
     }
     foreach ($eventConfiguration['subscribers'] as $subscriber) {
         $this->eventManager->addEventSubscriber(new $subscriber());
     }
     return $this->eventManager;
 }
开发者ID:kohana,项目名称:doctrine,代码行数:14,代码来源:EventManager.php

示例7: setUp

 protected function setUp()
 {
     parent::setUp();
     $evm = new EventManager();
     $this->translationListener = new TranslationListener();
     $this->translationListener->setTranslatableLocale('en_us');
     $evm->addEventSubscriber(new SluggableListener());
     $evm->addEventSubscriber($this->translationListener);
     $this->getMockSqliteEntityManager($evm);
     $this->populate();
 }
开发者ID:rdohms,项目名称:DoctrineExtensions,代码行数:11,代码来源:TranslatableSlugTest.php

示例8: setUp

 protected function setUp()
 {
     parent::setUp();
     $evm = new EventManager();
     $translatableListener = new TranslatableListener();
     $translatableListener->setTranslatableLocale('en_US');
     $evm->addEventSubscriber($translatableListener);
     $blameableListener = new BlameableListener();
     $blameableListener->setUserValue('testuser');
     $evm->addEventSubscriber($blameableListener);
     $this->getMockSqliteEntityManager($evm);
 }
开发者ID:erichard,项目名称:DoctrineExtensions,代码行数:12,代码来源:ProtectedPropertySupperclassTest.php

示例9: setUp

 protected function setUp()
 {
     parent::setUp();
     $evm = new EventManager();
     $sluggableListener = new SluggableListener();
     $sluggableListener->addManagedFilter(self::SOFT_DELETEABLE_FILTER_NAME, true);
     $evm->addEventSubscriber($sluggableListener);
     $this->softDeleteableListener = new SoftDeleteableListener();
     $evm->addEventSubscriber($this->softDeleteableListener);
     $config = $this->getMockAnnotatedConfig();
     $config->addFilter(self::SOFT_DELETEABLE_FILTER_NAME, 'Gedmo\\SoftDeleteable\\Filter\\SoftDeleteableFilter');
     $this->em = $this->getMockSqliteEntityManager($evm, $config);
     $this->em->getFilters()->enable(self::SOFT_DELETEABLE_FILTER_NAME);
 }
开发者ID:erichard,项目名称:DoctrineExtensions,代码行数:14,代码来源:Issue449Test.php

示例10: createService

 public function createService(ServiceLocatorInterface $sl)
 {
     /** @var $options \DoctrineModule\Options\EventManager */
     $options = $this->getOptions($sl, 'eventmanager');
     $evm = new EventManager();
     foreach ($options->getSubscribers() as $subscriber) {
         if (is_subclass_of($subscriber, 'Doctrine\\Common\\EventSubscriber')) {
             $evm->addEventSubscriber(new $subscriber());
         } else {
             $evm->addEventSubscriber($sl->get($subscriber));
         }
     }
     return $evm;
 }
开发者ID:raykolbe,项目名称:DoctrineModule,代码行数:14,代码来源:EventManagerFactory.php

示例11: setUp

 public function setUp()
 {
     $evm = new EventManager();
     $evm->addEventSubscriber(new DoctrineEncryptSubscriber(new \Doctrine\Common\Annotations\AnnotationReader(), new Rot13Encryptor()));
     $this->getMockSqliteEntityManager($evm);
     $this->populate();
 }
开发者ID:51systems,项目名称:doctrine-encrypt,代码行数:7,代码来源:DoctrineEncryptSubscriberTest.php

示例12: setUp

 public function setUp()
 {
     parent::setUp();
     $evm = new EventManager();
     $evm->addEventSubscriber(new TsVectorSubscriber());
     //		$this->getMock
 }
开发者ID:jbinfo,项目名称:DoctrineFullTextPostrgres,代码行数:7,代码来源:TsVectorTest.php

示例13: setUp

 protected function setUp()
 {
     parent::setUp();
     $evm = new EventManager();
     $evm->addEventSubscriber(new TimestampableListener());
     $this->getMockDocumentManager($evm);
 }
开发者ID:esserj,项目名称:DoctrineExtensions,代码行数:7,代码来源:TimestampableEmbeddedDocumentTest.php

示例14: setUp

 protected function setUp()
 {
     $config = new Configuration();
     //$config->setHydratorDir(sys_get_temp_dir());
     //$config->setHydratorNamespace('Hydrators');
     $config->setProxyDir(sys_get_temp_dir());
     $config->setProxyNamespace('Proxies');
     $locatorXml = new SymfonyFileLocator(array(__DIR__ . '/../../../../../lib/Vespolina/Product/Mapping' => 'Vespolina\\Entity\\Product', __DIR__ . '/../../../../../vendor/vespolina/pricing/lib/Vespolina/Pricing/Mapping' => 'Vespolina\\Entity\\Pricing', __DIR__ . '/../../../../../vendor/vespolina/taxonomy/lib/Vespolina/Taxonomy/Mapping' => 'Vespolina\\Entity\\Taxonomy'), '.orm.xml');
     $drivers = new MappingDriverChain();
     $xmlDriver = new XmlDriver($locatorXml);
     $config->setMetadataDriverImpl($xmlDriver);
     $config->setMetadataCacheImpl(new ArrayCache());
     $config->setAutoGenerateProxyClasses(true);
     $eventManager = new EventManager();
     $treeListener = new TreeListener();
     $eventManager->addEventSubscriber($treeListener);
     $em = EntityManager::create(array('driver' => 'pdo_sqlite', 'path' => 'database.sqlite'), $config, $eventManager);
     $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
     $classes = array($em->getClassMetadata('Vespolina\\Entity\\Product\\Product'), $em->getClassMetadata('Vespolina\\Entity\\Taxonomy\\TaxonomyNode'));
     try {
         $schemaTool->dropSchema(array());
         $schemaTool->createSchema($classes);
     } catch (\Exception $e) {
     }
     $this->productGateway = new ProductDoctrineORMGateway($em, 'Vespolina\\Entity\\Product\\Product');
     $this->taxonomyGateway = new TaxonomyDoctrineORMGateway($em, 'Vespolina\\Entity\\Taxonomy\\TaxonomyNode');
     parent::setUp();
 }
开发者ID:vespolina,项目名称:commerce,代码行数:28,代码来源:ProductDoctrineORMGatewayTest.php

示例15: getEntityManager

 /**
  * Get entity manager.
  *
  * @return EntityManagerInterface
  */
 protected function getEntityManager()
 {
     if (null === $this->entityManager) {
         $params = ['driver' => 'pdo_sqlite', 'memory' => true];
         $cache = new ArrayCache();
         /** @var AnnotationReader $reader */
         $reader = new CachedReader(new AnnotationReader(), $cache);
         $annotationDriver = new AnnotationDriver($reader, [__DIR__ . '/../../../src/ORM']);
         $driverChain = new MappingDriverChain();
         $driverChain->addDriver($annotationDriver, Commander::ENTITY_NAMESPACE);
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $reader);
         $config = new Configuration();
         $config->setAutoGenerateProxyClasses(true);
         $config->setProxyDir(sys_get_temp_dir());
         $config->setProxyNamespace(Commander::ENTITY_NAMESPACE);
         $config->setMetadataDriverImpl($driverChain);
         $config->setMetadataCacheImpl($cache);
         $config->setQueryCacheImpl($cache);
         $config->setResultCacheImpl($cache);
         $config->setHydrationCacheImpl($cache);
         $timestampableListener = new TimestampableListener();
         $timestampableListener->setAnnotationReader($annotationDriver->getReader());
         $eventManager = new EventManager();
         $eventManager->addEventSubscriber($timestampableListener);
         $entityManager = EntityManager::create($params, $config, $eventManager);
         $schemaTool = new SchemaTool($entityManager);
         $schemaTool->createSchema($entityManager->getMetadataFactory()->getAllMetadata());
         $this->entityManager = $entityManager;
     }
     return $this->entityManager;
 }
开发者ID:gravitymedia,项目名称:commander,代码行数:36,代码来源:TaskEntityRepositoryTest.php


注:本文中的Doctrine\Common\EventManager::addEventSubscriber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。