Since: 1.0
Inheritance: extends Doctrine\Common\Persistence\Mapping\Driver\FileDriver
Beispiel #1
0
 public function testCreateXmlDriver()
 {
     $xmlDriver = new XmlDriver(__DIR__ . '/fixtures/xml');
     $classMetadata = new ClassMetadata('TestDocuments\\User');
     $xmlDriver->loadMetadataForClass('TestDocuments\\User', $classMetadata);
     $this->assertEquals(array('fieldName' => 'id', 'id' => true, 'name' => 'id', 'type' => 'string', 'isCascadeDetach' => false, 'isCascadeMerge' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeRemove' => false), $classMetadata->fieldMappings['id']);
     $this->assertEquals(array('fieldName' => 'username', 'name' => 'username', 'type' => 'string', 'isCascadeDetach' => false, 'isCascadeMerge' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeRemove' => false), $classMetadata->fieldMappings['username']);
     $this->assertEquals(array('fieldName' => 'createdAt', 'name' => 'createdAt', 'type' => 'date', 'isCascadeDetach' => false, 'isCascadeMerge' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeRemove' => false), $classMetadata->fieldMappings['createdAt']);
     $this->assertEquals(array('fieldName' => 'address', 'name' => 'address', 'type' => 'one', 'embedded' => true, 'targetDocument' => 'Documents\\Address', 'isCascadeDetach' => false, 'isCascadeMerge' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeRemove' => false), $classMetadata->fieldMappings['address']);
     $this->assertEquals(array('fieldName' => 'phonenumbers', 'name' => 'phonenumbers', 'type' => 'many', 'embedded' => true, 'targetDocument' => 'Documents\\Phonenumber', 'isCascadeDetach' => false, 'isCascadeMerge' => false, 'isCascadePersist' => false, 'isCascadeRefresh' => false, 'isCascadeRemove' => false), $classMetadata->fieldMappings['phonenumbers']);
     $this->assertEquals(array('cascade' => 'all', 'fieldName' => 'profile', 'name' => 'profile', 'type' => 'one', 'reference' => true, 'strategy' => 'set', 'targetDocument' => 'Documents\\Profile', 'isCascadeDetach' => true, 'isCascadeMerge' => true, 'isCascadePersist' => true, 'isCascadeRefresh' => true, 'isCascadeRemove' => true), $classMetadata->fieldMappings['profile']);
     $this->assertEquals(array('cascade' => 'all', 'fieldName' => 'account', 'name' => 'account', 'type' => 'one', 'reference' => true, 'strategy' => 'set', 'targetDocument' => 'Documents\\Account', 'isCascadeDetach' => true, 'isCascadeMerge' => true, 'isCascadePersist' => true, 'isCascadeRefresh' => true, 'isCascadeRemove' => true), $classMetadata->fieldMappings['account']);
     $this->assertEquals(array('cascade' => 'all', 'fieldName' => 'groups', 'name' => 'groups', 'type' => 'many', 'reference' => true, 'strategy' => 'set', 'targetDocument' => 'Documents\\Group', 'isCascadeDetach' => true, 'isCascadeMerge' => true, 'isCascadePersist' => true, 'isCascadeRefresh' => true, 'isCascadeRemove' => true), $classMetadata->fieldMappings['groups']);
 }
 public function getElement($className)
 {
     if (null === $this->classCache) {
         $this->initialize();
     }
     if (!isset($this->classCache[$className])) {
         $this->classCache[$className] = parent::getElement($className);
     }
     return $this->classCache[$className];
 }
Beispiel #3
0
 /**
  * {@inheritDoc}
  */
 public function __construct($prefixes, $fileExtension = self::DEFAULT_FILE_EXTENSION)
 {
     $locator = new SymfonyFileLocator((array) $prefixes, $fileExtension);
     parent::__construct($locator, $fileExtension);
 }
 public function loadDoctrineMongoDBConfiguration(Application $app)
 {
     $app['doctrine.odm.mongodb.configuration'] = $app->share(function () use($app) {
         $config = new Configuration();
         if ($app['doctrine.odm.mongodb.metadata_cache'] == 'apc') {
             $cache = new ApcCache();
         } else {
             $cache = new ArrayCache();
         }
         $config->setMetadataCacheImpl($cache);
         if (isset($app['doctrine.odm.mongodb.connection_options']['database'])) {
             $config->setDefaultDB($app['doctrine.odm.mongodb.connection_options']['database']);
         }
         $chain = new DriverChain();
         foreach ((array) $app['doctrine.odm.mongodb.documents'] as $document) {
             switch ($document['type']) {
                 case 'annotation':
                     $reader = new AnnotationReader();
                     $driver = new AnnotationDriver($reader, (array) $document['path']);
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 case 'yml':
                     $driver = new YamlDriver((array) $document['path']);
                     $driver->setFileExtension('.yml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 case 'xml':
                     $driver = new XmlDriver((array) $document['path'], $document['namespace']);
                     $driver->setFileExtension('.xml');
                     $chain->addDriver($driver, $document['namespace']);
                     break;
                 default:
                     throw new \InvalidArgumentException(sprintf('"%s" is not a recognized driver', $document['type']));
                     break;
             }
         }
         $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']);
         return $config;
     });
 }