本文整理汇总了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);
}
示例2: setUp
protected function setUp()
{
parent::setUp();
$evm = new EventManager();
$evm->addEventSubscriber(new SluggableListener());
$evm->addEventSubscriber(new TreeListener());
$this->getMockSqliteEntityManager($evm);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例11: setUp
public function setUp()
{
$evm = new EventManager();
$evm->addEventSubscriber(new DoctrineEncryptSubscriber(new \Doctrine\Common\Annotations\AnnotationReader(), new Rot13Encryptor()));
$this->getMockSqliteEntityManager($evm);
$this->populate();
}
示例12: setUp
public function setUp()
{
parent::setUp();
$evm = new EventManager();
$evm->addEventSubscriber(new TsVectorSubscriber());
// $this->getMock
}
示例13: setUp
protected function setUp()
{
parent::setUp();
$evm = new EventManager();
$evm->addEventSubscriber(new TimestampableListener());
$this->getMockDocumentManager($evm);
}
示例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();
}
示例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;
}