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


PHP EventManager::addEventListener方法代码示例

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


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

示例1: enableEntity

 /**
  * Enable this listener for the given entity
  * This will apply the number generator when this entity will be flushed.
  *
  * @param SequenceSubjectInterface $subject
  */
 public function enableEntity(SequenceSubjectInterface $subject)
 {
     $this->entitiesEnabled[spl_object_hash($subject)] = $subject;
     if (!$this->listenerEnabled) {
         $this->eventManager->addEventListener(Events::preFlush, $this);
         $this->listenerEnabled = true;
     }
 }
开发者ID:vikey89,项目名称:Sylius,代码行数:14,代码来源:NumberListener.php

示例2: 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

示例3: getEntityManager

 public static function getEntityManager($smart = FALSE, $path_to_entity = null, $proxyPath = null, $proxyNamespace = null)
 {
     if (empty(self::$em)) {
         if ($path_to_entity === NULL) {
             //$path_to_entity = PATH_ROOT . '/' . Sokol::getApp()->name . '/Entity';
             $path_to_entity = PATH_ROOT . '/Entity';
         }
         $isDev = Sokol::getApp()->isDev;
         $connectionParams = Sokol::getConfig('db');
         //---Table Prefix---
         $tablePrefix = !empty($connectionParams['tablePrefix']) ? $connectionParams['tablePrefix'] : null;
         if ($tablePrefix) {
             $evm = new EventManager();
             $tablePrefix = new TablePrefix($tablePrefix);
             $evm->addEventListener(Events::loadClassMetadata, $tablePrefix);
         }
         //---/Table Prefix---
         if ($smart) {
             self::$em = self::getEmSmart($path_to_entity, $isDev, $connectionParams, $evm);
         } else {
             if ($proxyPath === NULL) {
                 $proxyPath = PATH_ROOT . '/' . Sokol::getApp()->name . '/Proxy';
             }
             if ($proxyNamespace === NULL) {
                 $proxyNamespace = Sokol::getApp()->getNamespace() . '\\Proxy';
             }
             self::$em = self::getEm($path_to_entity, $isDev, $connectionParams, $evm, $proxyPath, $proxyNamespace);
         }
         //подключаем тип данных "html"
         Type::addType('html', 'Sokol\\Doctrine\\Extension\\HtmlType');
         self::$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('db_html', 'html');
     }
     return self::$em;
 }
开发者ID:php-nik,项目名称:sokol,代码行数:34,代码来源:Doctrine.php

示例4: init

 /**
  * Executa as configurações iniciais e prepara o a entidade responsáveç
  * da biblioteca escolhida para ORM.
  */
 public function init()
 {
     $config = Config::getInstance();
     $paths = [SYS_ROOT . 'App' . DS . 'Models' . DS];
     $dev_mode = $config->get('database.debug');
     $conn_params = $this->loadConfiguration();
     $doctrine_config = Setup::createAnnotationMetadataConfiguration($paths, $dev_mode);
     if ($config->get('cache.cache')) {
         try {
             $cache = Cache::getInstance();
             if ($cache instanceof Cache) {
                 $doctrine_config->setResultCacheImpl($cache->getDriver());
             }
         } catch (\Exception $e) {
             $error = new Error();
             $error->log($e);
         }
     }
     $proxy_dir = SYS_ROOT . 'App' . DS . 'Models' . DS . 'Proxies';
     if (!is_dir($proxy_dir)) {
         if (mkdir($proxy_dir)) {
             $doctrine_config->setProxyDir($proxy_dir);
         }
     }
     $prefix = $config->get('database.connection.table_prefix');
     if ($prefix != '') {
         $evm = new EventManager();
         $table_prefix = new DoctrineTablePrefix($prefix);
         $evm->addEventListener(Events::loadClassMetadata, $table_prefix);
         $this->entityManager = EntityManager::create($conn_params, $doctrine_config, $evm);
     } else {
         $this->entityManager = EntityManager::create($conn_params, $doctrine_config);
     }
 }
开发者ID:anna-framework,项目名称:anna,代码行数:38,代码来源:DoctrineAdapter.php

示例5: __construct

 /**
  * @param array $database
  * @throws \Exception
  */
 public function __construct($database = [])
 {
     $this->db = $database;
     foreach ($this->db as $key => $db) {
         $this->allDb[$key] = function () use($db) {
             $db['dev'] = isset($db['dev']) && $db['dev'] ? true : false;
             if (isset($db['db_url'])) {
                 $dbParams = array('url' => $db['db_url']);
             } else {
                 if (!isset($db['driver']) || !isset($db['user']) || !isset($db['pass']) || !isset($db['host']) || !isset($db['db'])) {
                     throw new \Exception('Missing arguments for doctrine constructor');
                 }
                 $dbParams = array('driver' => $this->getDriver($db['driver']), 'user' => $db['user'], 'password' => $db['pass'], 'host' => $db['host'], 'dbname' => $db['db'], 'charset' => isset($db['charset']) ? $db['charset'] : 'utf8');
             }
             $evm = new EventManager();
             if (isset($db['prefix'])) {
                 $tablePrefix = new TablePrefix($db['prefix']);
                 $evm->addEventListener(Events::loadClassMetadata, $tablePrefix);
             }
             $config = Setup::createAnnotationMetadataConfiguration($db['path'], $db['dev']);
             if (!$db['dev']) {
                 $config->setQueryCacheImpl($db['cache']);
                 $config->setResultCacheImpl($db['cache']);
                 $config->setMetadataCacheImpl($db['cache']);
             }
             if (isset($db['functions']) && !empty($db['functions'])) {
                 $config->setCustomDatetimeFunctions($db['functions']['customDatetimeFunctions']);
                 $config->setCustomNumericFunctions($db['functions']['customNumericFunctions']);
                 $config->setCustomStringFunctions($db['functions']['customStringFunctions']);
             }
             return EntityManager::create($dbParams, $config, $evm);
         };
     }
 }
开发者ID:jetfirephp,项目名称:db,代码行数:38,代码来源:DoctrineConstructor.php

示例6: createEntityManager

 /**
  * @return \Doctrine\ORM\EntityManager
  */
 protected function createEntityManager()
 {
     // event manager used to create schema before tests
     $eventManager = new EventManager();
     $eventManager->addEventListener(array("preTestSetUp"), new SchemaSetupListener());
     // doctrine xml configs and namespaces
     $configPathList = array();
     if (is_dir(__DIR__ . '/../Resources/config/doctrine')) {
         $dir = __DIR__ . '/../Resources/config/doctrine';
         $configPathList[] = $dir;
         $prefixList[$dir] = 'Kitpages\\DataGridBundle\\Entities';
     }
     if (is_dir(__DIR__ . '/_doctrine/config')) {
         $dir = __DIR__ . '/_doctrine/config';
         $configPathList[] = $dir;
         $prefixList[$dir] = 'Kitpages\\DataGridBundle\\Tests\\TestEntities';
     }
     // create drivers (that reads xml configs)
     $driver = new \Symfony\Bridge\Doctrine\Mapping\Driver\XmlDriver($configPathList);
     $driver->setNamespacePrefixes($prefixList);
     // create config object
     $config = new Configuration();
     $config->setMetadataCacheImpl(new ArrayCache());
     $config->setMetadataDriverImpl($driver);
     $config->setProxyDir(__DIR__ . '/TestProxies');
     $config->setProxyNamespace('Kitpages\\DataGridBundle\\Tests\\TestProxies');
     $config->setAutoGenerateProxyClasses(true);
     //$config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger());
     // create entity manager
     $em = EntityManager::create(array('driver' => 'pdo_sqlite', 'path' => "/tmp/sqlite-test.db"), $config, $eventManager);
     return $em;
 }
开发者ID:radmar,项目名称:KitpagesDataGridBundle,代码行数:35,代码来源:BundleOrmTestCase.php

示例7: create

 /**
  * {@inheritdoc}
  */
 public static function create($conn, Configuration $config, EventManager $eventManager = null)
 {
     if (!$config->getMetadataDriverImpl()) {
         throw ORMException::missingMappingDriverImpl();
     }
     switch (true) {
         case is_array($conn):
             if (!$eventManager) {
                 $eventManager = new EventManager();
             }
             if (isset($conn['prefix']) && $conn['prefix']) {
                 $eventManager->addEventListener(Events::loadClassMetadata, new TablePrefix($conn['prefix']));
             }
             $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager);
             break;
         case $conn instanceof Connection:
             if ($eventManager !== null && $conn->getEventManager() !== $eventManager) {
                 throw ORMException::mismatchedEventManager();
             }
             break;
         default:
             throw new \InvalidArgumentException("Invalid argument: " . $conn);
     }
     return new self($conn, $config, $conn->getEventManager());
 }
开发者ID:minchal,项目名称:vero,代码行数:28,代码来源:EntityManager.php

示例8: testEventArgsNamespaceTest

 public function testEventArgsNamespaceTest()
 {
     $listener = new ListenerStub();
     $manager = new EventManager();
     $manager->addEventListener(\Doctrine\MongoDB\Events::preConnect, $listener);
     $connection = new Connection(null, [], null, $manager);
     $connection->initialize();
 }
开发者ID:alcaeus,项目名称:mongodb,代码行数:8,代码来源:EventTest.php

示例9: getEvent

 /**
  * 
  * @return \Doctrine\Common\EventManager
  */
 protected function getEvent()
 {
     $options = config('database')['connections']['mysql'];
     $evm = new EventManager();
     $tablePrefix = new \PanGuKTD\LaravelDoctrineORM\Listeners\TablePrefixListener($options['prefix']);
     $evm->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix);
     return $evm;
 }
开发者ID:panguktd,项目名称:laravel-doctrine-orm,代码行数:12,代码来源:DoctrineORMProvider.php

示例10: addLifecycleEventListener

 /**
  * Add doctrine event manager lifecycle listener
  * @param $events Array of Event constants to listen to
  * @param object $listener The listener object.
  * @throws \Exception
  * @return $this
  */
 public function addLifecycleEventListener($events = array(), $listener)
 {
     if (empty($this->entityManager)) {
         throw new \Exception('Please establish the entity manager connection using getEntityManager prior to adding event listeners');
     }
     $this->eventManager->addEventListener($events, $listener);
     return $this;
 }
开发者ID:51systems,项目名称:doctrine-test,代码行数:15,代码来源:EntityTestCase.php

示例11: setUp

 protected function setUp()
 {
     $ev = new EventManager();
     $ev->addEventListener(Events::prePersist, new \stdClass());
     $lr = new ListenerResolver();
     $this->md = new ClassMetadata('Test');
     $this->md->documentListeners[Events::prePersist] = [];
     $this->md->lifecycleCallbacks[Events::prePersist] = [];
     $this->li = new ListenersInvoker($ev, $lr);
 }
开发者ID:Edencia,项目名称:orientdb-php-odm,代码行数:10,代码来源:ListenersInvokerEvent.php

示例12: createEntityManager

 /**
  * @return EntityManager
  */
 private static function createEntityManager()
 {
     $config = \Doctrine\ORM\Tools\Setup::createConfiguration(true);
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver([__DIR__ . '/../../../../src/Driver/Doctrine/ORM/Entity', __DIR__ . '/Entity'], false));
     $rtel = new ResolveTargetEntityListener();
     $rtel->addResolveTargetEntity('FOS\\Message\\Model\\PersonInterface', 'FOS\\Message\\Tests\\Driver\\Doctrine\\ORM\\Entity\\TestPerson', []);
     $evm = new EventManager();
     $evm->addEventListener(Events::loadClassMetadata, $rtel);
     $dbParams = ['driver' => 'pdo_sqlite', 'path' => self::$dbFile];
     return \Doctrine\ORM\EntityManager::create($dbParams, $config, $evm);
 }
开发者ID:jbinfo,项目名称:FOSMessage,代码行数:14,代码来源:DoctrineORMDriverTest.php

示例13: createEntityManager

 /**
  * Create an entity manager
  *
  * @param array $params Parameters
  * @return object Entity manager
  * @filter
  */
 protected function createEntityManager()
 {
     $configuration = Setup::createAnnotationMetadataConfiguration([$this->_config['models']], Environment::is('development'), $this->_config['proxies'], isset($this->_config['cache']) ? call_user_func($this->_config['cache']) : null);
     $configuration->setProxyNamespace($this->_config['proxyNamespace']);
     $eventManager = new EventManager();
     $eventManager->addEventListener([Events::postLoad, Events::prePersist, Events::preUpdate], $this);
     $connection = $this->connectionSettings;
     $params = compact('connection', 'configuration', 'eventManager');
     return $this->_filter(__METHOD__, $params, function ($self, $params) {
         return EntityManager::create($params['connection'], $params['configuration'], $params['eventManager']);
     });
 }
开发者ID:mariano,项目名称:li3_doctrine2,代码行数:19,代码来源:Doctrine.php

示例14: setUpBeforeClass

 public static function setUpBeforeClass()
 {
     self::$connection = new MysqlPersistentConnection();
     $params = self::$connection->getConnectionParams();
     $configuration = Setup::createConfiguration(true);
     $event_manager = new EventManager();
     $annotation_reader = new AnnotationReader();
     $configuration->setMetadataDriverImpl(new AnnotationDriver($annotation_reader, [__DIR__ . '/Entity']));
     $annotation_metadata_provider = new EntityAnnotationMetadataProvider($annotation_reader);
     $mutation_metadata_provider = new EntityMutationMetadataProvider($annotation_reader);
     $entity_changed_listener = new EntityChangedListener($annotation_metadata_provider, $mutation_metadata_provider);
     $mutation_resolver = new MutationResolver($annotation_metadata_provider);
     $mutation_listener = new MutationListener($mutation_resolver);
     $event_manager->addEventListener('prePersist', $entity_changed_listener);
     $event_manager->addEventListener('preFlush', $entity_changed_listener);
     $event_manager->addEventListener('entityChanged', $mutation_listener);
     self::$entity_manager = EntityManager::create($params, $configuration, $event_manager);
     $metadata = self::$entity_manager->getMetadataFactory()->getAllMetadata();
     $schema_tool = new SchemaTool(self::$entity_manager);
     $schema_tool->createSchema($metadata);
 }
开发者ID:hostnet,项目名称:entity-mutation-component,代码行数:21,代码来源:DiscriminatorMapTest.php

示例15: testConnectDispatchEvent

 public function testConnectDispatchEvent()
 {
     $listenerMock = $this->getMock('ConnectDispatchEventListener', array('postConnect'));
     $listenerMock->expects($this->once())->method('postConnect');
     $eventManager = new EventManager();
     $eventManager->addEventListener(array(Events::postConnect), $listenerMock);
     $driverMock = $this->getMock('Doctrine\\DBAL\\Driver');
     $driverMock->expects($this->at(0))->method('connect');
     $platform = new Mocks\MockPlatform();
     $conn = new Connection(array('platform' => $platform), $driverMock, new Configuration(), $eventManager);
     $conn->connect();
 }
开发者ID:llinder,项目名称:FrameworkBenchmarks,代码行数:12,代码来源:ConnectionTest.php


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