protected function setUp() { parent::setUp(); $evm = new EventManager(); $evm->addEventSubscriber(new TimestampableListener()); $this->getMockDocumentManager($evm); }
public function setUp() { parent::setUp(); $evm = new EventManager(); $evm->addEventSubscriber(new TsVectorSubscriber()); // $this->getMock }
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(); }
/** * 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); } }
/** * 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; }
/** * {@inheritdoc} */ protected function createWithConfig(ContainerInterface $container, $configKey) { $config = $this->retrieveConfig($container, $configKey, 'event_manager'); $eventManager = new EventManager(); foreach ($config['subscribers'] as $subscriber) { if (is_object($subscriber)) { $subscriberName = get_class($subscriber); } elseif (!is_string($subscriber)) { $subscriberName = gettype($subscriber); } elseif ($container->has($subscriber)) { $subscriber = $container->get($subscriber); $subscriberName = $subscriber; } elseif (class_exists($subscriber)) { $subscriber = new $subscriber(); $subscriberName = get_class($subscriber); } else { $subscriberName = $subscriber; } if (!$subscriber instanceof EventSubscriber) { throw new DomainException(sprintf('Invalid event subscriber "%s" given, mut be a dependency name, class name or an instance' . ' implementing %s', $subscriberName, EventSubscriber::class)); } $eventManager->addEventSubscriber($subscriber); } return $eventManager; }
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); }
/** * @param $text * @return string */ public function run($text) { $args = new ContentEditorArgs(); $args->setValue($text); $this->eventManager->dispatchEvent(ContentEditorEvents::onContentEditorRender, $args); return $args->getValue(); }
/** * {@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()); }
protected function setUp() { parent::setUp(); $evm = new EventManager(); $evm->addEventSubscriber(new SluggableListener()); $this->getMockSqliteEntityManager($evm); }
public function setUp() { $evm = new EventManager(); $evm->addEventSubscriber(new DoctrineEncryptSubscriber(new \Doctrine\Common\Annotations\AnnotationReader(), new Rot13Encryptor())); $this->getMockSqliteEntityManager($evm); $this->populate(); }
protected function setUp() { parent::setUp(); $evm = new EventManager(); $this->listener = new UploadableListenerStub(); $this->listener->setMimeTypeGuesser(new MimeTypeGuesserStub('text/plain')); $evm->addEventSubscriber($this->listener); $config = $this->getMockAnnotatedConfig(); $this->em = $this->getMockSqliteEntityManager($evm, $config); $this->testFile = __DIR__ . '/../../data/test.txt'; $this->testFile2 = __DIR__ . '/../../data/test2.txt'; $this->testFile3 = __DIR__ . '/../../data/test_3.txt'; $this->testFileWithoutExt = __DIR__ . '/../../data/test4'; $this->testFileWithSpaces = __DIR__ . '/../../data/test with spaces.txt'; $this->destinationTestDir = __DIR__ . '/../../temp/uploadable'; $this->destinationTestFile = $this->destinationTestDir . '/test.txt'; $this->destinationTestFile2 = $this->destinationTestDir . '/test2.txt'; $this->destinationTestFile3 = $this->destinationTestDir . '/test_3.txt'; $this->destinationTestFileWithoutExt = $this->destinationTestDir . '/test4'; $this->destinationTestFileWithSpaces = $this->destinationTestDir . '/test with spaces'; $this->testFilename = substr($this->testFile, strrpos($this->testFile, '/') + 1); $this->testFilename2 = substr($this->testFile2, strrpos($this->testFile2, '/') + 1); $this->testFilename3 = substr($this->testFile3, strrpos($this->testFile3, '/') + 1); $this->testFilenameWithoutExt = substr($this->testFileWithoutExt, strrpos($this->testFileWithoutExt, '/') + 1); $this->testFilenameWithSpaces = substr($this->testFileWithSpaces, strrpos($this->testFileWithSpaces, '/') + 1); $this->testFileSize = 4; $this->testFileMimeType = 'text/plain'; $this->clearFilesAndDirectories(); if (!is_dir($this->destinationTestDir)) { mkdir($this->destinationTestDir); } }
public function setUp() { $this->evm = m::mock(EventManager::class); $this->evm->shouldReceive('addEventSubscriber')->once(); $this->em = m::mock(EntityManagerInterface::class); $this->reader = m::mock(Reader::class); }
/** * * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator * @return object */ public function createService(ServiceLocatorInterface $serviceLocator) { $manifest = $serviceLocator->get('manifest'); $config = new Configuration(); $config->setProxyDir(__DIR__ . '/../../../../Proxies'); $config->setProxyNamespace('Proxies'); $config->setHydratorDir(__DIR__ . '/../../../../Hydrators'); $config->setHydratorNamespace('Hydrators'); $config->setDefaultDB(self::DEFAULT_DB); $config->setMetadataCacheImpl(new ArrayCache()); //create driver chain $chain = new MappingDriverChain(); foreach ($manifest['documents'] as $namespace => $path) { $driver = new AnnotationDriver(new AnnotationReader(), $path); $chain->addDriver($driver, $namespace); } $config->setMetadataDriverImpl($chain); //register filters foreach ($manifest['filters'] as $name => $class) { $config->addFilter($name, $class); } //create event manager $eventManager = new EventManager(); foreach ($manifest['subscribers'] as $subscriber) { $eventManager->addEventSubscriber($serviceLocator->get($subscriber)); } //register annotations AnnotationRegistry::registerLoader(function ($className) { return class_exists($className); }); $conn = new Connection(null, array(), $config); return DocumentManager::create($conn, $config, $eventManager); }
/** * @param MappedEventSubscriber $subscriber * @param EventManager $manager * @param Reader|null $reader */ protected function addSubscriber(MappedEventSubscriber $subscriber, EventManager $manager, Reader $reader = null) { if ($reader) { $subscriber->setAnnotationReader($reader); } $manager->addEventSubscriber($subscriber); }
/** * @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; }
/** * @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); }; } }
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; }
protected function setUpEntityManager($transformer = null) { $evm = new EventManager(); $evm->addEventSubscriber($this->getSubscriber($transformer)); $configuration = Setup::createYAMLMetadataConfiguration([__DIR__ . '/Fixture']); $this->em = $this->getMockSqliteEntityManager($evm, $configuration); }
/** * @param EventManager $manager * @param EntityManagerInterface $em * @param Reader $reader */ public function addSubscribers(EventManager $manager, EntityManagerInterface $em, Reader $reader) { $subscriber = new IpTraceableListener(); $subscriber->setAnnotationReader($reader); $subscriber->setIpValue($this->request->getClientIp()); $manager->addEventSubscriber($subscriber); }
protected function getEventManager($user = null, $userCallback = null, $userEntity = null) { $em = new EventManager(); $this->subscriber = new \Knp\DoctrineBehaviors\ORM\Blameable\BlameableSubscriber(new ClassAnalyzer(), false, 'Knp\\DoctrineBehaviors\\Model\\Blameable\\Blameable', $userCallback, $userEntity); $this->subscriber->setUser($user); $em->addEventSubscriber($this->subscriber); return $em; }
protected function setUp() { parent::setUp(); $evm = new EventManager(); $evm->addEventSubscriber(new SluggableListener()); $this->getMockDocumentManager($evm); $this->populate(); }
protected function setUp() { parent::setUp(); $evm = new EventManager(); $this->encoderListener = new EncoderListener(); $evm->addEventSubscriber($this->encoderListener); $this->getMockDocumentManager($evm); }
public function testEventArgsNamespaceTest() { $listener = new ListenerStub(); $manager = new EventManager(); $manager->addEventListener(\Doctrine\MongoDB\Events::preConnect, $listener); $connection = new Connection(null, [], null, $manager); $connection->initialize(); }
public function getValue() { $args = new ContentEditorArgs(); $args->setValue(parent::getValue()); $this->eventManager->dispatchEvent(ContentEditorEvents::onContentEditorSave, $args); $value = $args->getValue(); return $value; }
protected function getEventManager($user = null, $userCallback = null, $userEntity = null) { $em = new EventManager(); $this->listener = new \Knp\DoctrineBehaviors\ORM\Blameable\BlameableListener($userCallback, $userEntity); $this->listener->setUser($user); $em->addEventSubscriber($this->listener); return $em; }
/** * @param EventManager $manager * @param EntityManagerInterface $em * @param Reader $reader */ public function addSubscribers(EventManager $manager, EntityManagerInterface $em, Reader $reader) { $subscriber = new TranslatableListener(); $subscriber->setTranslatableLocale($this->application->getLocale()); $subscriber->setDefaultLocale($this->repository->get('app.locale')); $subscriber->setAnnotationReader($reader); $manager->addEventSubscriber($subscriber); }
/** * 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; } }
public function setUp() { parent::setUp(); $this->timestampable = new TimestampableListener(); $evm = new EventManager(); $evm->addEventSubscriber($this->timestampable); $this->getMockSqliteEntityManager($evm); }
protected function getEventManager() { $em = new EventManager(); $em->addEventSubscriber(new \Knp\DoctrineBehaviors\ORM\Translatable\TranslatableListener(function () { return 'en'; })); return $em; }