Пример #1
0
    /**
     * @throws \RuntimeException
     *
     * @return MappingDriverChain
     */
    protected function getMetadataDriverImpl()
    {
        $rootDir = realpath(__DIR__.'/../../../..');
        if (false === $rootDir || false === is_file($rootDir.'/Payment.php')) {
            throw new \RuntimeException('Cannot guess Payum root dir.');
        }

        $driver = new MappingDriverChain();
        $xmlDriver = new XmlDriver(
            new SymfonyFileLocator(
                array($rootDir.'/Bridge/Doctrine/Resources/mapping' => 'Payum\Core\Model'),
                '.mongodb.xml'
            ),
            '.mongodb.xml'
        );
        $driver->addDriver($xmlDriver, 'Payum\Core\Model');

        AnnotationDriver::registerAnnotationClasses();

        $rc = new \ReflectionClass('Payum\Core\Tests\Mocks\Document\TestModel');
        $annotationDriver = new AnnotationDriver(new AnnotationReader(), array(
            dirname($rc->getFileName()),
        ));
        $driver->addDriver($annotationDriver, 'Payum\Core\Tests\Mocks\Document');

        return $driver;
    }
Пример #2
0
 /**
  * Creates the entity manager for the application.
  *
  * @param Configuration $config
  * @param string        $modelPath
  * @return AnnotationDriver
  */
 public function factory(Configuration $config, $modelPath)
 {
     $annotationDriver = new AnnotationDriver($config->getAnnotationsReader(), array($modelPath, $config->getAttributeDir()));
     // create a driver chain for metadata reading
     $driverChain = new MappingDriverChain();
     // register annotation driver for our application
     $driverChain->addDriver($annotationDriver, 'Shopware\\Models\\');
     $driverChain->addDriver($annotationDriver, 'Shopware\\CustomModels\\');
     $config->setMetadataDriverImpl($driverChain);
     return $annotationDriver;
 }
 public function testFromMetadataDriver()
 {
     $reader = new AnnotationReader();
     $locator = new SymfonyFileLocator(array(), '.yml');
     $omDriver = new MappingDriverChain();
     $omDriver->addDriver(new ORMAnnotationDriver($reader), 'Prezent\\Tests\\Fixture\\Foo');
     $omDriver->addDriver(new ORMYamlDriver($locator), 'Prezent\\Tests\\Fixture\\Bar');
     $expected = new DriverChain(array(new AnnotationDriver($reader), new YamlDriver($locator)));
     $driver = DoctrineAdapter::fromMetadataDriver($omDriver);
     $this->assertEquals($expected, $driver);
 }
 /**
  * {@inheritdoc}
  */
 public function register(Container $app)
 {
     //  @todo crear DoctrineOrmManagerRegistryProvider
     //  o poner en boot estos servicios
     $app->extend('form.extensions', function ($extensions, $app) {
         $extensions[] = new DoctrineOrmExtension($app['doctrine']);
         return $extensions;
     });
     $app['doctrine.orm.validator.unique_validator'] = function ($app) {
         return new UniqueEntityValidator($app['doctrine']);
     };
     if (!isset($app['validator.validator_service_ids'])) {
         $app['validator.validator_service_ids'] = [];
     }
     $app['validator.validator_service_ids'] = array_merge($app['validator.validator_service_ids'], ['doctrine.orm.validator.unique' => 'doctrine.orm.validator.unique_validator']);
     $app->extend('validator.object_initializers', function (array $objectInitializers, $app) {
         $objectInitializers[] = new DoctrineInitializer($app['doctrine']);
         return $objectInitializers;
     });
     $app['doctrine'] = function ($app) {
         return new ManagerRegistry($app);
     };
     $app['orm.em'] = function ($app) {
         $em = EntityManager::create($app['db'], $app['orm.config'], $app['db.event_manager']);
         return $em;
     };
     // Entity manager alias
     $app['em'] = function ($app) {
         return $app['orm.em'];
     };
     $app['orm.config'] = function ($app) {
         $config = new Configuration();
         // @todo path!
         $config->setProxyDir(sprintf('%s/../../../../../../var/cache/doctrine/proxies', __DIR__));
         $config->setProxyNamespace('DoctrineProxies');
         $config->setAutoGenerateProxyClasses($app['debug']);
         // The strongly recommended FALSE in production
         $chain = new MappingDriverChain();
         // Pulsar
         $path = realpath(sprintf('%s/../Entity', __DIR__));
         $driver = $config->newDefaultAnnotationDriver((array) $path, false);
         $chain->addDriver($driver, 'Pulsar\\Entity');
         // App
         $path = realpath(sprintf('%s/../../../../../../src/App', __DIR__));
         $driver = $config->newDefaultAnnotationDriver((array) $path, false);
         $chain->addDriver($driver, 'App\\Entity');
         $config->setMetadataCacheImpl($app['orm.cache']);
         $config->setMetadataDriverImpl($chain);
         return $config;
     };
     $app['orm.cache'] = function () {
         return new ArrayCache();
     };
 }
Пример #5
0
 private function loadPhpcrOdm()
 {
     $this['psi_content_type.storage.doctrine.phpcr_odm.property_encoder'] = function ($container) {
         return new PropertyEncoder('psict', 'https://github.com/psiphp/content-type');
     };
     $this['psi_content_type.storage.doctrine.phpcr_odm.field_mapper'] = function ($container) {
         return new FieldMapper($container['psi_content_type.storage.doctrine.phpcr_odm.property_encoder'], $container['psi_content_type.field_loader']);
     };
     $this['psi_content_type.storage.doctrine.phpcr_odm.collection_updater'] = function ($container) {
         return new CollectionIdentifierUpdater($container['psi_content_type.metadata.factory'], $container['psi_content_type.storage.doctrine.phpcr_odm.property_encoder']);
     };
     $this['doctrine_phpcr.document_manager'] = function ($container) {
         $registerNodeTypes = false;
         // automatically setup the schema if the db doesn't exist yet.
         if (!file_exists($container['config']['db_path'])) {
             if (!file_exists($dir = dirname($container['config']['db_path']))) {
                 mkdir($dir);
             }
             $connection = $container['dbal.connection'];
             $schema = new RepositorySchema();
             foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) {
                 $connection->exec($sql);
             }
             $registerNodeTypes = true;
         }
         // register the phpcr session
         $factory = new RepositoryFactoryDoctrineDBAL();
         $repository = $factory->getRepository(['jackalope.doctrine_dbal_connection' => $container['dbal.connection']]);
         $session = $repository->login(new SimpleCredentials(null, null), 'default');
         if ($registerNodeTypes) {
             $typeRegistrator = new NodeTypeRegistrator();
             $typeRegistrator->registerNodeTypes($session);
             $ctTypeRegistrator = new CtNodeTypeRegistrator($container['psi_content_type.storage.doctrine.phpcr_odm.property_encoder']);
             $ctTypeRegistrator->registerNodeTypes($session);
         }
         // annotation driver
         $annotationDriver = new AnnotationDriver($container['annotation_reader'], [__DIR__ . '/../../vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Document', __DIR__ . '/Example']);
         $xmlDriver = new XmlDriver([__DIR__ . '/mappings']);
         $annotationDriver = new AnnotationDriver($container['annotation_reader'], [__DIR__ . '/../../vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Document', __DIR__ . '/Example']);
         $chain = new MappingDriverChain();
         $chain->addDriver($annotationDriver, 'Psi\\Bridge\\ContentType\\Doctrine\\PhpcrOdm\\Tests\\Functional\\Example');
         $chain->addDriver($xmlDriver, 'Psi\\Component\\ContentType\\Tests\\Functional\\Example\\Model');
         $chain->addDriver($annotationDriver, 'Doctrine');
         $config = new Configuration();
         $config->setMetadataDriverImpl($chain);
         $manager = DocumentManager::create($session, $config);
         $manager->getEventManager()->addEventSubscriber(new MetadataSubscriber($container['psi_content_type.metadata.factory'], $container['psi_content_type.field_loader'], $container['psi_content_type.storage.doctrine.phpcr_odm.field_mapper']));
         $manager->getEventManager()->addEventSubscriber(new CollectionSubscriber($container['psi_content_type.metadata.factory'], $container['psi_content_type.storage.doctrine.phpcr_odm.property_encoder']));
         return $manager;
     };
 }
Пример #6
0
 /**
  * @throws \RuntimeException
  *
  * @return MappingDriverChain
  */
 protected function getMetadataDriverImpl()
 {
     $rootDir = realpath(__DIR__ . '/../../../../../../');
     if (false === $rootDir || false === is_dir($rootDir . '/src/Payum')) {
         throw new \RuntimeException('Cannot guess Payum root dir.');
     }
     $driver = new MappingDriverChain();
     $xmlDriver = new XmlDriver(new SymfonyFileLocator(array($rootDir . '/src/Payum/Bridge/Doctrine/Resources/mapping' => 'Payum\\Bridge\\Doctrine\\Document'), '.mongodb.xml'), '.mongodb.xml');
     $driver->addDriver($xmlDriver, 'Payum\\Bridge\\Doctrine\\Document');
     \Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver::registerAnnotationClasses();
     $annotationDriver = new AnnotationDriver(new AnnotationReader(), array($rootDir . '/examples/Payum/Examples/Document'));
     $driver->addDriver($annotationDriver, 'Payum\\Examples\\Document');
     return $driver;
 }
Пример #7
0
 /**
  * @return MappingDriver
  */
 protected function getMetadataDriverImpl(Configuration $config)
 {
     $rootDir = realpath(__DIR__ . '/../../../..');
     if (false === $rootDir || false === is_file($rootDir . '/Gateway.php')) {
         throw new \RuntimeException('Cannot guess Payum root dir.');
     }
     $driver = new MappingDriverChain();
     $xmlDriver = new SimplifiedXmlDriver(array($rootDir . '/Bridge/Doctrine/Resources/mapping' => 'Payum\\Core\\Model'));
     $driver->addDriver($xmlDriver, 'Payum\\Core\\Model');
     $rc = new \ReflectionClass('Payum\\Core\\Tests\\Mocks\\Entity\\TestModel');
     $annotationDriver = $config->newDefaultAnnotationDriver(array(dirname($rc->getFileName())), false);
     $driver->addDriver($annotationDriver, 'Payum\\Core\\Tests\\Mocks\\Entity');
     return $driver;
 }
Пример #8
0
 /**
  * @return MappingDriver
  */
 protected function getMetadataDriverImpl()
 {
     $rootDir = realpath(__DIR__ . '/../../../../../../');
     if (false === $rootDir || false === is_dir($rootDir . '/src/Payum')) {
         throw new \RuntimeException('Cannot guess Payum root dir.');
     }
     $driver = new MappingDriverChain();
     $xmlDriver = new SimplifiedXmlDriver(array($rootDir . '/src/Payum/Bridge/Doctrine/Resources/mapping' => 'Payum\\Bridge\\Doctrine\\Entity'));
     $driver->addDriver($xmlDriver, 'Payum\\Bridge\\Doctrine\\Entity');
     $rc = new \ReflectionClass('\\Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver');
     AnnotationRegistry::registerFile(dirname($rc->getFileName()) . '/DoctrineAnnotations.php');
     $annotationDriver = new AnnotationDriver(new AnnotationReader(), array($rootDir . '/examples/Payum/Examples/Entity'));
     $driver->addDriver($annotationDriver, 'Payum\\Examples\\Entity');
     return $driver;
 }
 private function loadDoctrineMongoDBConfiguration(Application $app)
 {
     $app['doctrine.odm.mongodb.configuration'] = $app->share(function () use($app) {
         $config = new Configuration();
         $config->setMetadataCacheImpl($app['doctrine.odm.mongodb.metadata_cache']);
         if (isset($app['doctrine.odm.mongodb.connection_options']['database'])) {
             $config->setDefaultDB($app['doctrine.odm.mongodb.connection_options']['database']);
         }
         $chain = new MappingDriverChain();
         $usingAnnotations = false;
         foreach ((array) $app['doctrine.odm.mongodb.documents'] as $document) {
             switch ($document['type']) {
                 case 'annotation':
                     $driver = AnnotationDriver::create((array) $document['path']);
                     $chain->addDriver($driver, $document['namespace']);
                     $usingAnnotations = true;
                     break;
                 case 'yml':
                     $driver = new YamlDriver((array) $document['path'], '.yml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 case 'xml':
                     $driver = new XmlDriver((array) $document['path'], '.xml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 default:
                     throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $document['type']));
                     break;
             }
             // add namespace alias
             if (isset($document['alias'])) {
                 $config->addDocumentNamespace($document['alias'], $document['namespace']);
             }
         }
         if ($usingAnnotations) {
             AnnotationDriver::registerAnnotationClasses();
         }
         $config->setMetadataDriverImpl($chain);
         $config->setProxyDir($app['doctrine.odm.mongodb.proxies_dir']);
         $config->setProxyNamespace($app['doctrine.odm.mongodb.proxies_namespace']);
         $config->setAutoGenerateProxyClasses($app['doctrine.odm.mongodb.auto_generate_proxies']);
         $config->setHydratorDir($app['doctrine.odm.mongodb.hydrators_dir']);
         $config->setHydratorNamespace($app['doctrine.odm.mongodb.hydrators_namespace']);
         $config->setAutoGenerateHydratorClasses($app['doctrine.odm.mongodb.auto_generate_hydrators']);
         $config->setLoggerCallable($app['doctrine.odm.mongodb.logger_callable']);
         return $config;
     });
 }
 /**
  *
  * @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  \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return object
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $manifest = $serviceLocator->get('manifest');
     $extension = $serviceLocator->get('extension.odmcore');
     $config = new Configuration();
     $config->setProxyDir($extension->getProxyDir());
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir($extension->getHydratorDir());
     $config->setHydratorNamespace('Hydrators');
     $config->setDefaultDB($extension->getDefaultDb());
     $config->setClassMetadataFactoryName($extension->getClassMetadataFactory());
     $config->setMetadataCacheImpl(new ArrayCache());
     //create driver chain
     $chain = new MappingDriverChain();
     foreach ($manifest->getModels() as $namespace => $path) {
         $driver = new AnnotationDriver(new AnnotationReader(), $path);
         $chain->addDriver($driver, $namespace);
     }
     $config->setMetadataDriverImpl($chain);
     //register filters
     foreach ($extension->getFilters() as $name => $class) {
         $config->addFilter($name, $class);
     }
     //create event manager
     $eventManager = new EventManager();
     foreach ($manifest->getSubscribers() as $subscriber) {
         $eventManager->addEventSubscriber($serviceLocator->get($subscriber));
     }
     //register annotations
     AnnotationRegistry::registerLoader(function ($className) {
         return class_exists($className);
     });
     $conn = new Connection(null, array(), $config);
     return ModelManager::create($conn, $config, $eventManager);
 }
 /**
  * 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;
 }
 /**
  * @group DDC-706
  */
 public function testIsTransient()
 {
     $driver1 = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
     $chain = new MappingDriverChain();
     $chain->addDriver($driver1, 'Doctrine\\Tests\\Models\\CMS');
     $this->assertTrue($chain->isTransient('stdClass'), "stdClass isTransient");
 }
 /**
  * Register the application services.
  *
  * @return void
  */
 public function register()
 {
     $this->registerSession();
     $chain = new DriverChain();
     // Bind the annotation driver
     $chain->addDriver($this->getAnnotationDriver(), 'App');
     $this->addCommandsToArtisan();
     $this->addHelpersToArtisan();
 }
Пример #15
0
 /**
  * Create a \Doctrine\ORM\Configuration based on the config given.
  * If no config are given the method will try to get the config from the configuration file.
  *
  * @return \Doctrine\ORM\Configuration
  */
 public function configureDoctrine()
 {
     $configuredCache = $this->cache->configureCache();
     $configuredDriver = $this->mapping->configureDriver($configuredCache);
     foreach ($this->configuration->get('namespaces') as $namespace) {
         $this->driverChain->addDriver($configuredDriver->getMetadataDriverImpl(), $namespace);
     }
     $configuredDriver->setMetadataDriverImpl($this->driverChain);
     // Implement maximum caching
     $configuredDriver->setMetadataCacheImpl($configuredCache);
     $configuredDriver->setHydrationCacheImpl($configuredCache);
     $configuredDriver->setQueryCacheImpl($configuredCache);
     $configuredDriver->setResultCacheImpl($configuredCache);
     $proxyConfiguration = $this->configuration->get('proxy');
     // Set proxies and proxie-prefix
     $configuredDriver->setProxyNamespace($proxyConfiguration['namespace']);
     $configuredDriver->setAutoGenerateProxyClasses($proxyConfiguration['generate']);
     return $configuredDriver;
 }
 public function loadDoctrineConfiguration(Application $app)
 {
     $app['db.orm.config'] = $app->share(function () use($app) {
         $cache = $app['db.orm.cache'];
         $config = new ORMConfiguration();
         $config->setMetadataCacheImpl($cache);
         $config->setQueryCacheImpl($cache);
         $chain = new MappingDriverChain();
         foreach ((array) $app['db.orm.entities'] as $entity) {
             switch ($entity['type']) {
                 case 'default':
                 case 'annotation':
                     $driver = $config->newDefaultAnnotationDriver((array) $entity['path'], false);
                     $chain->addDriver($driver, $entity['namespace']);
                     break;
                 case 'yml':
                     $driver = new YamlDriver((array) $entity['path']);
                     $driver->setFileExtension('.yml');
                     $chain->addDriver($driver, $entity['namespace']);
                     break;
                 case 'xml':
                     $driver = new XmlDriver((array) $entity['path'], $entity['namespace']);
                     $driver->setFileExtension('.xml');
                     $chain->addDriver($driver, $entity['namespace']);
                     break;
                 default:
                     throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $entity['type']));
                     break;
             }
         }
         $config->setMetadataDriverImpl($chain);
         $config->setProxyDir($app['db.orm.proxies_dir']);
         $config->setProxyNamespace($app['db.orm.proxies_namespace']);
         $config->setAutoGenerateProxyClasses($app['db.orm.auto_generate_proxies']);
         $config->addCustomHydrationMode('SimpleArrayHydrator', 'App\\Provider\\SimpleArrayHydrator');
         // автолоад прокси
         $proxyDir = $app['db.orm.proxies_dir'];
         $proxyNamespace = $app['db.orm.proxies_namespace'];
         Autoloader::register($proxyDir, $proxyNamespace);
         return $config;
     });
 }
Пример #17
0
 public function testDefaultDriverGetAllClassNames()
 {
     $companyDriver = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
     $defaultDriver = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
     $chain = new MappingDriverChain();
     $companyDriver->expects($this->once())->method('getAllClassNames')->will($this->returnValue(array('Doctrine\\Tests\\Models\\Company\\Foo')));
     $defaultDriver->expects($this->once())->method('getAllClassNames')->will($this->returnValue(array('Other\\Class')));
     $chain->setDefaultDriver($defaultDriver);
     $chain->addDriver($companyDriver, 'Doctrine\\Tests\\Models\\Company');
     $classNames = $chain->getAllClassNames();
     $this->assertEquals(array('Doctrine\\Tests\\Models\\Company\\Foo', 'Other\\Class'), $classNames);
 }
 /**
  * Get mapping driver.
  *
  * @return MappingDriver
  */
 public function getMappingDriver()
 {
     if (null === $this->mappingDriver) {
         /** @var AnnotationReader $reader */
         $reader = new CachedReader(new AnnotationReader(), $this->cache);
         $annotationDriver = new AnnotationDriver($reader, [__DIR__ . '/../ORM']);
         $driverChain = new MappingDriverChain();
         $driverChain->addDriver($annotationDriver, Commander::ENTITY_NAMESPACE);
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $reader);
         $this->mappingDriver = $driverChain;
     }
     return $this->mappingDriver;
 }
Пример #19
0
 /**
  * Enable Gedmo Doctrine Extensions
  *
  * @param array $namespaces
  * @param bool  $all
  */
 public function bootGedmoExtensions($namespaces = ['App'], $all = true)
 {
     if ($all) {
         DoctrineExtensions::registerMappingIntoDriverChainORM($this->chain, $this->reader);
     } else {
         DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($this->chain, $this->reader);
     }
     $driver = $this->metadata->getMetadataDriverImpl();
     foreach ($namespaces as $namespace) {
         $this->chain->addDriver($driver, $namespace);
     }
     $this->metadata->setMetadataDriverImpl($this->chain);
     $this->dispatcher->fire('doctrine.driver-chain::booted', [$driver, $this->chain]);
 }
Пример #20
0
 /**
  * {@inheritDoc}
  */
 public function createStorage($modelClass, $idProperty, array $options)
 {
     if (false == Type::hasType('object')) {
         Type::addType('object', 'Payum\\Core\\Bridge\\Doctrine\\Types\\ObjectType');
     }
     $driver = new MappingDriverChain();
     // payum's basic models
     $coreRootDir = dirname((new \ReflectionClass(GatewayInterface::class))->getFileName());
     $driver->addDriver(new XmlDriver(new SymfonyFileLocator(array($coreRootDir . '/Bridge/Doctrine/Resources/mapping' => 'Payum\\Core\\Model'), '.mongodb.xml'), '.mongodb.xml'), 'Payum\\Core\\Model');
     // your models
     $sererRootDir = dirname((new \ReflectionClass(Application::class))->getFileName());
     AnnotationDriver::registerAnnotationClasses();
     $driver->addDriver(new AnnotationDriver(new AnnotationReader(), array($sererRootDir . '/Model')), 'Payum\\Server\\Model');
     $config = new Configuration();
     $config->setProxyDir(\sys_get_temp_dir() . '/PayumServer');
     $config->setProxyNamespace('Proxies');
     $config->setHydratorDir(\sys_get_temp_dir() . '/PayumServer');
     $config->setHydratorNamespace('Hydrators');
     $config->setMetadataDriverImpl($driver);
     $config->setMetadataCacheImpl(new ArrayCache());
     $config->setDefaultDB($options['databaseName']);
     $connection = new Connection($options['host'], array(), $config);
     return new DoctrineStorage(DocumentManager::create($connection, $config), $modelClass);
 }
 /**
  * @group DDC-1412
  */
 public function testDefaultDriver()
 {
     $companyDriver = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
     $dafaultDriver = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
     $entityClassName = 'Doctrine\\Tests\\ORM\\Mapping\\DriverChainEntity';
     $managerClassName = 'Doctrine\\Tests\\Models\\Company\\CompanyManager';
     $chain = new MappingDriverChain();
     $companyDriver->expects($this->never())->method('loadMetadataForClass');
     $companyDriver->expects($this->once())->method('isTransient')->with($this->equalTo($managerClassName))->will($this->returnValue(false));
     $dafaultDriver->expects($this->never())->method('loadMetadataForClass');
     $dafaultDriver->expects($this->once())->method('isTransient')->with($this->equalTo($entityClassName))->will($this->returnValue(true));
     $this->assertNull($chain->getDefaultDriver());
     $chain->setDefaultDriver($dafaultDriver);
     $chain->addDriver($companyDriver, 'Doctrine\\Tests\\Models\\Company');
     $this->assertSame($dafaultDriver, $chain->getDefaultDriver());
     $this->assertTrue($chain->isTransient($entityClassName));
     $this->assertFalse($chain->isTransient($managerClassName));
 }
 private function loadConfiguration(ContainerBuilder $container, $config)
 {
     $definition = new Definition('Doctrine\\ORM\\Configuration');
     $definition->addMethodCall('setProxyDir', array(sys_get_temp_dir()));
     $definition->addMethodCall('setProxyNamespace', array('Proxy'));
     $definition->addMethodCall('setAutoGenerateProxyClasses', array(true));
     $definition->addMethodCall('setClassMetadataFactoryName', array('Doctrine\\ORM\\Mapping\\ClassMetadataFactory'));
     $driver = new MappingDriverChain();
     $mappings = array();
     foreach ($config['mappings'] as $namespace => $classes) {
         $driver->addDriver(new AnnotationDriver(new AnnotationReader(), $mappings), $namespace);
         //            $driver->addDriver(new XmlDriver($mappings), $namespace);
         foreach ($classes as $class) {
             $mappings[] = realpath(sprintf("%s/../../../../../../../%s", __DIR__, $class));
         }
     }
     $definition->addMethodCall('setMetadataDriverImpl', array($driver));
     $definition->addMethodCall('newDefaultAnnotationDriver', array());
     $definition->addMethodCall('setDefaultRepositoryClassName', array('Doctrine\\ORM\\EntityRepository'));
     $definition->addMethodCall('setQuoteStrategy', array(new DefaultQuoteStrategy()));
     $definition->addMethodCall('setNamingStrategy', array(new DefaultNamingStrategy()));
     $definition->addMethodCall('setRepositoryFactory', array(new DefaultRepositoryFactory()));
     $container->setDefinition('doctrine.configuration', $definition);
 }
Пример #23
0
 /**
  * 
  * @param \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain $service
  * @param \DIP\FileManager\AddMaping $maping
  */
 public static function addDoctrineMaping(MappingDriverChain $service, Maping $maping, Cache $cache, CachedReader $reader)
 {
     $nestedDriver = new AnnotationDriver(array($maping->maping_doctrine['namespace'] => $maping->maping_doctrine['directory']), $reader, $cache);
     $service->addDriver($nestedDriver, $maping->maping_doctrine['namespace']);
 }
Пример #24
0
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';
/** @var boolean $cli If the bootstrap (/web/index.php) sees this variable, don't 'run' the HTTP front-controller */
$cli = true;
require_once dirname(__DIR__) . '/web/index.php';
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain, Symfony\Component\Console\Application as CliApplication, Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper, Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper, Doctrine\Common\Annotations\AnnotationRegistry, Doctrine\ORM\Mapping\Driver\AnnotationDriver, Doctrine\Common\Annotations\AnnotationReader, Symfony\Component\Console\Helper\HelperSet, Doctrine\ORM\Mapping\Driver\DatabaseDriver, Doctrine\ORM\Tools\Console\Command, Doctrine\DBAL\Connection, Doctrine\DBAL\Version;
/** @var Connection $db The above bootstrap creates the app object for us */
$db = $app['db'];
/** @var Doctrine\ORM\EntityManager $em The entity manager */
$em = $app['orm.em'];
$driver = new DatabaseDriver($db->getSchemaManager());
$driver->setNamespace('App\\Entity\\');
$annotationsFile = dirname(__DIR__) . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';
AnnotationRegistry::registerFile($annotationsFile);
$driverChain = new MappingDriverChain();
$driverChain->addDriver(new AnnotationDriver(new AnnotationReader(), [dirname(__DIR__) . '/src/App/Model/Entity']), 'App\\Model\\Entity\\');
$em->getConfiguration()->setMetadataDriverImpl($driverChain);
/** @var Symfony\Component\Console\Application $cli */
$cli = new CliApplication('Doctrine Command Line Interface', Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet(new HelperSet(['db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em)]));
$cli->addCommands([new Command\GenerateRepositoriesCommand(), new Command\GenerateEntitiesCommand(), new Command\ConvertMappingCommand(), new Command\ValidateSchemaCommand(), new Command\SchemaTool\CreateCommand(), new Command\SchemaTool\UpdateCommand(), new Command\GenerateProxiesCommand()]);
$cli->run();
 protected function createEntityManager()
 {
     $driverChain = new MappingDriverChain();
     $config = Setup::createConfiguration($this->debugEnabled);
     $useSimpleAnnotationReader = false;
     foreach ($this->mappings as $key => $mapping) {
         $driver = null;
         if ($mapping['type'] == 'xml') {
             if (isset($mapping['extension'])) {
                 $driver = new XmlDriver(array($mapping['doctrine']), $mapping['extension']);
             } else {
                 $driver = new XmlDriver(array($mapping['doctrine']));
             }
         } else {
             if ($mapping['type'] == 'yaml') {
                 if (isset($mapping['extension'])) {
                     $driver = new YamlDriver(array($mapping['doctrine']), $mapping['extension']);
                 } else {
                     $driver = new YamlDriver(array($mapping['doctrine']));
                 }
             } else {
                 if ($mapping['type'] == 'annotation') {
                     $paths = array();
                     if (isset($mapping['doctrine'])) {
                         $paths[] = $mapping['doctrine'];
                     }
                     $driver = $config->newDefaultAnnotationDriver($paths, $useSimpleAnnotationReader);
                 }
             }
         }
         if ($driver) {
             $driverChain->addDriver($driver, $mapping['namespace']);
         }
     }
     // default to annotations
     if (empty($this->mappings)) {
         $driverChain = $config->newDefaultAnnotationDriver(array(), $useSimpleAnnotationReader);
     }
     $config->setMetadataDriverImpl($driverChain);
     $entityManager = EntityManager::create($this->connection, $config);
     return $entityManager;
 }
Пример #26
0
 /**
  * Setup the entity manager and annotation driver with the given additional namespace for entity classes, under the
  * specified alias.
  *
  * @param string $alias
  * @param string $namespace
  */
 public function registerEntityNamespace($alias, $namespace)
 {
     $this->getEngine()->doctrine()->getEntityManager()->getConfiguration()->addEntityNamespace($alias, $namespace);
     $this->driverChain->addDriver($this->annotationDriver, $namespace);
 }
 /**
  * Hooks only superclass metadata mapping drivers
  * into given $driverChain of drivers for ODM MongoDB
  *
  * @param MappingDriverChain $driverChain
  * @param Reader|null        $reader
  */
 public static function registerAbstractMappingIntoDriverChainMongodbODM(MappingDriverChain $driverChain, Reader $reader = null)
 {
     self::registerAnnotations();
     if (!$reader) {
         $reader = new CachedReader(new AnnotationReader(), new ArrayCache());
     }
     $annotationDriver = new DriverMongodbODM\AnnotationDriver($reader, array(__DIR__ . '/Translatable/Document/MappedSuperclass', __DIR__ . '/Loggable/Document/MappedSuperclass'));
     $driverChain->addDriver($annotationDriver, 'Gedmo');
 }
Пример #28
0
 /**
  * Create a entity manager used for the package installation,
  * update and unistall process.
  *
  * @return \Doctrine\ORM\EntityManager
  */
 public function getPackageEntityManager()
 {
     $providerFactory = new PackageProviderFactory($this->app, $this);
     $provider = $providerFactory->getEntityManagerProvider();
     $drivers = $provider->getDrivers();
     if (count($drivers)) {
         $config = Setup::createConfiguration(true, $this->app->make('config')->get('database.proxy_classes'));
         $driverImpl = new MappingDriverChain();
         $coreDriver = new CoreDriver($this->app);
         // Add the core driver to it so packages can extend the core and not break.
         $driverImpl->addDriver($coreDriver->getDriver(), $coreDriver->getNamespace());
         foreach ($drivers as $driver) {
             $driverImpl->addDriver($driver->getDriver(), $driver->getNamespace());
         }
         $config->setMetadataDriverImpl($driverImpl);
         $em = EntityManager::create(\Database::connection(), $config);
         return $em;
     }
 }
Пример #29
0
<?php

/** vendor/bin/doctrine looks for a config/cli-config.php file in the project - so that's why this is here **/
/** If the bootstrap (Aurex.php) sees this variable, don't 'run' the HTTP front-controller **/
$cli = true;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/web/index.php';
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain, Symfony\Component\Console\Application as CliApplication, Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper, Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper, UseAllFive\Command\LoadDataFixturesDoctrineCommand, Doctrine\Common\Annotations\AnnotationRegistry, Doctrine\ORM\Mapping\Driver\AnnotationDriver, Doctrine\Common\Annotations\AnnotationReader, Symfony\Component\Console\Helper\HelperSet, Doctrine\ORM\Mapping\Driver\DatabaseDriver, Doctrine\ORM\Tools\Console\Command, Doctrine\DBAL\Connection, Doctrine\DBAL\Version;
/** @var Connection $db The above bootstrap creates the app object for us */
$db = $aurex['db'];
/** @var Doctrine\ORM\EntityManager $em The entity manager */
$em = $aurex['orm.em'];
$driver = new DatabaseDriver($db->getSchemaManager());
$driver->setNamespace('Aurex\\Application\\Entity\\');
$annotationsFile = __DIR__ . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';
AnnotationRegistry::registerFile($annotationsFile);
$driverChain = new MappingDriverChain();
$driverChain->addDriver(new AnnotationDriver(new AnnotationReader(), [__DIR__ . '/lib/Application/Model/Entity']), 'Aurex\\Application\\Model\\Entity\\');
$em->getConfiguration()->setMetadataDriverImpl($driverChain);
/** @var Symfony\Component\Console\Application $cli */
$cli = new CliApplication('Doctrine Command Line Interface', Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet(new HelperSet(['db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em)]));
$cli->addCommands([new Command\GenerateRepositoriesCommand(), new Command\GenerateEntitiesCommand(), new Command\ConvertMappingCommand(), new Command\ValidateSchemaCommand(), new Command\SchemaTool\CreateCommand(), new Command\SchemaTool\UpdateCommand(), new Command\GenerateProxiesCommand(), new LoadDataFixturesDoctrineCommand()]);
$cli->run();
 /**
  * @return Configuration
  */
 protected function createConfiguration()
 {
     $configuration = new Configuration();
     $configuration->setMetadataFactory(new EntityMetadataFactory());
     $configuration->setRegistry($this->registry);
     $configuration->setTypeRegistry(new BaseTypeRegistry(new TypeRegistry()));
     $configuration->setProxyDir(CACHE_DIR . '/doctrine/proxy/');
     $configuration->setProxyNamespace('Bankiru\\Api\\Test\\Proxy');
     $driver = new MappingDriverChain();
     $driver->addDriver(new YmlMetadataDriver(new SymfonyFileLocator([__DIR__ . '/../Test/Resources/config/api/' => 'Bankiru\\Api\\Test\\Entity'], '.api.yml', DIRECTORY_SEPARATOR)), 'Bankiru\\Api\\Test\\Entity');
     $configuration->setDriver($driver);
     return $configuration;
 }