Exemplo n.º 1
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;
     };
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var $session \PHPCR\SessionInterface */
     $session = $this->getHelper('phpcr')->getSession();
     $registrator = new NodeTypeRegistrator();
     try {
         $registrator->registerNodeTypes($session);
     } catch (\Exception $e) {
         $output->writeln('<error>' . $e->getMessage() . '</error>');
         return 1;
     }
     $output->write(PHP_EOL . sprintf('Successfully registered system node types.') . PHP_EOL);
     return 0;
 }