diff --git a/bundles/phpcr_odm/configuration.rst b/bundles/phpcr_odm/configuration.rst index 21fc19ce..8c6b32c8 100644 --- a/bundles/phpcr_odm/configuration.rst +++ b/bundles/phpcr_odm/configuration.rst @@ -63,25 +63,25 @@ Configuration .. code-block:: php // app/config/config.php - $container->loadFromExtension('doctrine_phpcr', array( - 'session' => array( - 'backend' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'session' => [ + 'backend' => [ 'type' => 'X', - 'parameters' => array( + 'parameters' => [ 'jackalope.factory' => 'Jackalope\Factory', 'jackalope.check_login_on_server' => false, 'jackalope.disable_stream_wrapper' => false, 'jackalope.auto_lastmodified' => true, - ), - ), + ], + ], 'workspace' => 'default', 'username' => 'admin', 'password' => 'admin', - 'options' => array( + 'options' => [ 'jackalope.fetch_depth' => 1, - ), - ), - )); + ], + ], + ]); ``workspace`` """"""""""""" @@ -233,18 +233,18 @@ PHPCR Session with Jackalope Jackrabbit .. code-block:: php // app/config/config.php - $container->loadFromExtension('doctrine_phpcr', array( - 'session' => array( - 'backend' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'session' => [ + 'backend' => [ 'type' => 'jackrabbit', 'url' => 'http://localhost:8080/server/', - 'parameters' => array( + 'parameters' => [ 'jackalope.default_header' => 'X-ID: %serverid%', 'jackalope.jackrabbit_expect' => true, - ), - ), - ), - )); + ], + ], + ], + ]); ``url`` """"""" @@ -327,24 +327,24 @@ supported by Doctrine. .. code-block:: php // app/config/config.php - $container->loadFromExtension('doctrine_phpcr', array( - 'session' => array( - 'backend' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'session' => [ + 'backend' => [ 'type' => 'doctrinedbal', 'connection' => 'default', - 'caches' => array( + 'caches' => [ 'meta' => 'doctrine_cache.providers.phpcr_meta' 'nodes' => 'doctrine_cache.providers.phpcr_nodes' - ), - 'parameters' => array( + ], + 'parameters' => [ // ... general parameters and options // optional parameters specific to Jackalope Doctrine Dbal 'jackalope.disable_transactions' => false, - ), - ), - ), - )); + ], + ], + ], + ]); ``connection`` """""""""""""" @@ -408,15 +408,15 @@ debug toolbar: .. code-block:: php // app/config/config.yml - $container->loadFromExtension('doctrine_phpcr', array( - 'session' => array( - 'backend' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'session' => [ + 'backend' => [ // ... 'logging' => true, 'profiling' => true, - ), - ), - )); + ], + ], + ]); Doctrine PHPCR-ODM Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -511,29 +511,29 @@ not configure anything here, the ODM services will not be loaded. .. code-block:: php // app/config/config.php - $container->loadFromExtension('doctrine_phpcr', array( - 'odm' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'odm' => [ 'configuration_id' => null, 'auto_mapping' => true, 'auto_generate_proxy_classes' => '%kernel.debug%', 'proxy-dir' => '%kernel.cache_dir%/doctrine/PHPCRProxies', 'proxy_namespace' => 'PHPCRProxies', - 'namespaces' => array( - 'translation' => array( + 'namespaces' => [ + 'translation' => [ 'alias' => 'phpcr_locale', - ), - ), - 'mappings' => array( - '' => array( + ], + ], + 'mappings' => [ + '' => [ 'mapping' => true, 'type' => null, 'dir' => null, 'alias' => null, 'prefix' => null, 'is-bundle' => null, - ), - ), - 'metadata_cache_driver' => array( + ], + ], + 'metadata_cache_driver' => [ 'type' => 'array', 'host' => null, 'port' => null, @@ -541,9 +541,9 @@ not configure anything here, the ODM services will not be loaded. 'class' => null, 'id' => null, 'namespace' => null, - ), - ), - )); + ], + ], + ]); ``configuration_id`` """""""""""""""""""" @@ -639,10 +639,10 @@ General Settings .. code-block:: php // app/config/config.php - $container->loadFromExtension('doctrine_phpcr', array( + $container->loadFromExtension('doctrine_phpcr', [ 'jackrabbit_jar' => '/path/to/jackrabbit.jar', 'dump_max_line_length' => 120, - )); + ]); ``jackrabbit_jar`` """""""""""""""""" diff --git a/bundles/phpcr_odm/events.rst b/bundles/phpcr_odm/events.rst index 22ad20e9..b56cd429 100644 --- a/bundles/phpcr_odm/events.rst +++ b/bundles/phpcr_odm/events.rst @@ -30,29 +30,30 @@ use this configuration: .. code-block:: yaml + # app/config/services.yml services: - acme_search.listener.search: - class: Acme\SearchBundle\EventListener\SearchIndexer + app.phpcr_search_indexer: + class: AppBundle\EventListener\SearchIndexer tags: - { name: doctrine_phpcr.event_listener, event: postPersist } - acme_search.subscriber.fancy: - class: Acme\SearchBundle\EventSubscriber\MySubscriber + app.phpcr_listener: + class: AppBundle\EventListener\MyListener tags: - { name: doctrine_phpcr.event_subscriber } .. code-block:: xml - + - + - + @@ -60,31 +61,33 @@ use this configuration: .. code-block:: php + // app/config/config.php + use AppBundle\EventListener\SearchIndexer; + use AppBundle\EventListener\MyListener; + $container ->register( - 'acme_search.listener.search', - 'Acme\SearchBundle\EventListener\SearchIndexer' + 'app.phpcr_search_indexer', + SearchIndexer::class ) - ->addTag('doctrine_phpcr.event_listener', array( + ->addTag('doctrine_phpcr.event_listener', [ 'event' => 'postPersist', - )) + ]) ; $container ->register( - 'acme_search.subscriber.fancy', - 'Acme\SearchBundle\EventSubscriber\FancySubscriber' + 'app.phpcr_listener', + MySubscriber::class ) - ->addTag('doctrine_phpcr.event_subscriber', array( - 'event' => 'postPersist', - )) + ->addTag('doctrine_phpcr.event_subscriber') ; .. tip:: - Doctrine event subscribers (both ORM and PHPCR-ODM) can not return a - flexible array of methods to call like the `Symfony event subscriber`_ can - do. Doctrine event subscribers must return a simple array of the event + Doctrine event subscribers (both ORM and PHPCR-ODM) can **not** return a + flexible array of methods to call like the `Symfony event subscriber`_. + Doctrine event subscribers must return a simple array of the event names they subscribe to. Doctrine will then expect methods on the subscriber with the names of the subscribed events, just as when using an event listener. diff --git a/bundles/phpcr_odm/fixtures_initializers.rst b/bundles/phpcr_odm/fixtures_initializers.rst index e3a23b61..91a4d8a3 100644 --- a/bundles/phpcr_odm/fixtures_initializers.rst +++ b/bundles/phpcr_odm/fixtures_initializers.rst @@ -46,46 +46,47 @@ A service to use the generic Initializer looks like this: .. code-block:: yaml - # src/Acme/ContentBundle/Resources/config/services.yml - acme_content.phpcr.initializer: + # app/config/services.yml + app.phpcr_initializer: class: Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer arguments: - - AcmeContentBundle Basepaths - - [ "/my/content", "/my/menu" ] - - "%acme.cnd%" + - App Basepaths + - ["/my/content", "/my/menu"] + - "%app.cnd%" tags: - { name: "doctrine_phpcr.initializer" } .. code-block:: xml - - + - AcmeContentBundle Basepaths + App Basepaths /my/content /my/menu - %acme.cnd% + %app.cnd% .. code-block:: php + // app/config/services.php + use Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer; use Symfony\Component\DependencyInjection\Definition // ... $definition = new Definition( - 'Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer', - array( - 'AcmeContentBundle Basepaths', - array('/my/content', '/my/menu'), - '%acme.cnd%', - ) - )); + GenericInitializer::class, [ + 'App Basepaths', + ['/my/content', '/my/menu'], + '%app.cnd%', + ] + ); $definition->addTag('doctrine_phpcr.initializer'); - $container->setDefinition('acme_content.phpcr.initializer', $definition); + $container->setDefinition('app.phpcr_initializer', $definition); You can execute your Initializers using the following command: @@ -103,9 +104,10 @@ specific documents, you need your own Initializer. The interesting method to overwrite is the ``init`` method. It is passed the ``ManagerRegistry``, from which you can retrieve the PHPCR session but also the document manager:: - // src/Acme/BasicCmsBundle/Initializer/SiteInitializer.php - namespace Acme\ContentBundle\Initializer; + // src/AppBundle/Initializer/SiteInitializer.php + namespace AppBundle\Initializer; + use AppBundle\Documents\Site; use Doctrine\Bundle\PHPCRBundle\Initializer\InitializerInterface; use Doctrine\Bundle\PHPCRBundle\ManagerRegistry; use PHPCR\SessionInterface; @@ -122,12 +124,12 @@ from which you can retrieve the PHPCR session but also the document manager:: public function init(ManagerRegistry $registry) { - $dm = $registry->getManagerForClass('Acme\BasicCmsBundle\Document\Site'); + $dm = $registry->getManagerForClass(Site::class); if ($dm->find(null, $this->basePath)) { return; } - $site = new Acme\BasicCmsBundle\Document\Site(); + $site = new Site(); $site->setId($this->basePath); $dm->persist($site); $dm->flush(); @@ -159,17 +161,17 @@ Define a service for your Initializer as follows: .. code-block:: yaml - # src/Acme/BasicCmsBundle/Resources/config/config.yml + # app/config/config.yml services: # ... - acme_content.phpcr.initializer.site: - class: Acme\BasicCmsBundle\Initializer\SiteInitializer + app.phpcr_initializer_site: + class: AppBundle\Initializer\SiteInitializer tags: - { name: doctrine_phpcr.initializer } .. code-block:: xml - - + @@ -190,15 +192,15 @@ Define a service for your Initializer as follows: .. code-block:: php - // src/Acme/BasicCmsBundle/Resources/config/config.php + // app/config/config.php // ... $container ->register( - 'acme_content.phpcr.initializer.site', - 'Acme\BasicCmsBundle\Initializer\SiteInitializer' + 'app.phpcr_initializer_site', + 'AppBundle\Initializer\SiteInitializer' ) - ->addTag('doctrine_phpcr.initializer', array('name' => 'doctrine_phpcr.initializer') + ->addTag('doctrine_phpcr.initializer', ['name' => 'doctrine_phpcr.initializer'] ; Migration Loading @@ -216,44 +218,45 @@ basis. .. code-block:: yaml - # src/Acme/ContentBundle/Resources/config/services.yml - acme.demo.migration.foo: - class: Acme\DemoBundle\Migration\Foo + # app/config/services.yml + app.migration: + class: AppBundle\Migration\Migration arguments: - - { "%acme.content_basepath%", "%acme.menu_basepath%" } + - { "%app.content_basepath%", "%app.menu_basepath%" } tags: - - { name: "doctrine_phpcr.migrator", alias: "acme.demo.migration.foo" } + - { name: "doctrine_phpcr.migrator", alias: "app.migration" } .. code-block:: xml - + - + - %acme.content_basepath% - %acme.menu_basepath% + %app.content_basepath% + %app.menu_basepath% - + .. code-block:: php - use Symfony\Component\DependencyInjection\Definition + use AppBundle\Migration\Migration; + use Symfony\Component\DependencyInjection\Definition; // ... - $definition = new Definition('Acme\DemoBundle\Migration\Foo', array( - array( - '%acme.content_basepath%', - '%acme.menu_basepath%', - ), - ))); - $definition->addTag('doctrine_phpcr.migrator', array('alias' => 'acme.demo.migration.foo')); + $definition = new Definition(Migration::class, [ + [ + '%app.content_basepath%', + '%app.menu_basepath%', + ], + ]); + $definition->addTag('doctrine_phpcr.migrator', ['alias' => 'app.migration']); - $container->setDefinition('acme.demo.migration.foo', $definition); + $container->setDefinition('app.migration', $definition); To find out available migrations run: @@ -289,8 +292,8 @@ don't specify a path in the command. A simple example fixture class looks like this:: - // src/Acme/MainBundle/DataFixtures/PHPCR/LoadPageData.php - namespace Acme\MainBundle\DataFixtures\PHPCR; + // src/AppBundle/DataFixtures/PHPCR/LoadPageData.php + namespace AppBundle\DataFixtures\PHPCR; use Doctrine\Common\Persistence\ObjectManager; use Doctrine\Common\DataFixtures\FixtureInterface; diff --git a/bundles/phpcr_odm/forms.rst b/bundles/phpcr_odm/forms.rst index 259d1f24..f9a73232 100644 --- a/bundles/phpcr_odm/forms.rst +++ b/bundles/phpcr_odm/forms.rst @@ -38,15 +38,17 @@ that the option for the document manager is called ``em``. A simple example of using the ``phpcr_document`` form type looks as follows:: + use AppBundle\Document\TargetClass; + $form ->add( 'speakers', 'phpcr_document', - array( + [ 'property' => 'title', - 'class' => 'AppBundle\Document\TargetClass', + 'class' => TargetClass::class, 'multiple' => true, - ) + ] ) ; @@ -80,17 +82,19 @@ targets as an array of PHPCR-ODM ids or PHPCR paths. The minimal code required to use this type looks as follows:: - $dataArr = array( + use AppBundle\Document\Article; + + $dataArr = [ '/some/phpcr/path/item_1' => 'first item', '/some/phpcr/path/item_2' => 'second item', - ); + ]; $formMapper ->with('form.group_general') - ->add('myCollection', 'phpcr_odm_reference_collection', array( + ->add('myCollection', 'phpcr_odm_reference_collection', [ 'choices' => $dataArr, - 'referenced_class' => 'Class\Of\My\Referenced\Documents', - )) + 'referenced_class' => Article::class, + ]) ->end(); .. tip:: diff --git a/bundles/phpcr_odm/introduction.rst b/bundles/phpcr_odm/introduction.rst index 33ba1cfd..80df996e 100644 --- a/bundles/phpcr_odm/introduction.rst +++ b/bundles/phpcr_odm/introduction.rst @@ -62,11 +62,11 @@ Besides the ``DoctrinePHPCRBundle`` you also need to instantiate the base { public function registerBundles() { - $bundles = array( + $bundles = [ // ... new Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), - ); + ]; // ... } @@ -139,15 +139,15 @@ with the DoctrineBundle. For detailed information, see the .. code-block:: php // app/config/config.php - $configuration->loadFromExtension('doctrine', array( - 'dbal' => array( + $configuration->loadFromExtension('doctrine', [ + 'dbal' => [ 'driver' => '%database_driver%', 'host' => '%database_host%', 'dbname' => '%database_name%', 'user' => '%database_user%', 'password' => '%database_password%', - ), - )); + ], + ]); Jackalope Doctrine DBAL provides a PHPCR implementation without any installation requirements beyond any of the RDBMS supported by Doctrine. @@ -210,23 +210,23 @@ Once you set up Doctrine DBAL, you can configure Jackalope: .. code-block:: php // app/config/config.php - $container->loadFromExtension('doctrine_phpcr', array( - 'session' => array( - 'backend' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'session' => [ + 'backend' => [ 'type' => 'doctrinedbal', //'connection': 'default', 'logging' => true, 'profiling' => true, - //'caches' => array( + //'caches' => [ // 'meta' => 'doctrine_cache.providers.phpcr_meta' // 'nodes' => 'doctrine_cache.providers.phpcr_nodes' - //), - ), + //], + ], 'workspace' => 'default', 'username' => 'admin', 'password' => 'admin', - ), - )); + ], + ]); Now make sure the database exists and initialize it: @@ -301,12 +301,12 @@ here, the ODM services will not be loaded. .. code-block:: php // app/config/config.php - $container->loadFromExtension('doctrine_phpcr', array( - 'odm' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'odm' => [ 'auto_mapping' => true, 'auto_generate_proxy_classes' => '%kernel.debug%', - ), - )); + ], + ]); Unless you disable ``auto_mapping``, you can place your documents in the ``Document`` folder inside your bundles and use annotations or name the @@ -373,15 +373,15 @@ debug toolbar: .. code-block:: php // app/config/config.yml - $container->loadFromExtension('doctrine_phpcr', array( - 'session' => array( - 'backend' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'session' => [ + 'backend' => [ // ... 'logging' => true, 'profiling' => true, - ), - ), - )); + ], + ], + ]); Now that you can see the effects of changes, you can try if adjusting the global fetch depth reduces the number and duration for queries. Set the option diff --git a/bundles/phpcr_odm/multilang.rst b/bundles/phpcr_odm/multilang.rst index ee92b5ef..2333ae15 100644 --- a/bundles/phpcr_odm/multilang.rst +++ b/bundles/phpcr_odm/multilang.rst @@ -60,18 +60,18 @@ To use translated documents, you need to configure the available languages: .. code-block:: php // app/config/config.php - $container->loadFromExtension('doctrine_phpcr', array( - 'odm' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'odm' => [ // ... - 'locales' => array( - 'en' => array('de', 'fr'), - 'de' => array('en', 'fr'), - 'fr' => array('en', 'de'), - ), + 'locales' => [ + 'en' => ['de', 'fr'], + 'de' => ['en', 'fr'], + 'fr' => ['en', 'de'], + ], 'locale_fallback' => 'hardcoded', 'default_locale' => 'fr', - ) - ); + ] + ]); The ``locales`` is a list of alternative locales to look up if a document is not translated to the requested locale. @@ -116,14 +116,15 @@ depending on the locale. .. code-block:: php - - @@ -164,18 +165,18 @@ depending on the locale. .. code-block:: yaml - MyPersistentClass: - translator: attribute - locale: locale - fields: - publishDate: - type: date - topic: - type: string - translated: true - image: - type: binary - translated: true + AppBundle\Documents\Article: + translator: attribute + locale: locale + fields: + publishDate: + type: date + topic: + type: string + translated: true + image: + type: binary + translated: true Unless you explicitly interact with the multi-language features of PHPCR-ODM, documents are loaded in the request locale and saved in the locale they where diff --git a/bundles/phpcr_odm/multiple_sessions.rst b/bundles/phpcr_odm/multiple_sessions.rst index 425f6997..abce07ed 100644 --- a/bundles/phpcr_odm/multiple_sessions.rst +++ b/bundles/phpcr_odm/multiple_sessions.rst @@ -59,24 +59,24 @@ Multiple PHPCR Sessions .. code-block:: php // app/config/config.php - $container->loadFromExtension('doctrine_phpcr', array( - 'session' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'session' => [ 'default_session' => null, - 'sessions' => array( - '' => array( + 'sessions' => [ + '' => [ 'workspace' => '...', // Required 'username' => null, 'password' => null, - 'backend' => array( + 'backend' => [ // ... - ), - 'options' => array( + ], + 'options' => [ // ... - ), - ), - ), - ), - )); + ], + ], + ], + ], + ]); Multiple Document Managers -------------------------- @@ -120,22 +120,25 @@ attribute. .. code-block:: php // app/config/config.php - $container->loadFromExtension('doctrine_phpcr', array( - 'odm' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'odm' => [ 'default_document_manager' => null, - 'document_managers' => array( - '' => array( + 'document_managers' => [ + '' => [ 'session' => '', // ... configuration as above - ), - ), - ), - )); + ], + ], + ], + ]); Bringing it all together ------------------------ -A full example looks as follows: +The following full example uses the default manager for ``AppBundle`` +and the documents provided by the CMF. Additionally, it has a website +and DMS manager that connects to the Jackrabbit of Magnolia CMS. That +manager looks for models in the MagnoliaBundle. .. configuration-block:: @@ -174,22 +177,22 @@ A full example looks as follows: default: session: default mappings: - SandboxMainBundle: ~ + AppBundle: ~ CmfContentBundle: ~ CmfMenuBundle: ~ CmfRoutingBundle: ~ website: session: website - configuration_id: sandbox_magnolia.odm_configuration + configuration_id: magnolia.odm_configuration mappings: - SandboxMagnoliaBundle: ~ + MagnoliaBundle: ~ dms: session: dms - configuration_id: sandbox_magnolia.odm_configuration + configuration_id: magnolia.odm_configuration mappings: - SandboxMagnoliaBundle: ~ + MagnoliaBundle: ~ .. code-block:: xml @@ -226,7 +229,7 @@ A full example looks as follows: name="default" session="default" > - + @@ -235,17 +238,17 @@ A full example looks as follows: - + - + @@ -255,66 +258,66 @@ A full example looks as follows: .. code-block:: php // app/config/config.php - $container->loadFromExtension('doctrine_phpcr', array( - 'session' => array( - 'sessions' => array( - 'default' => array( + $container->loadFromExtension('doctrine_phpcr', [ + 'session' => [ + 'sessions' => [ + 'default' => [ 'backend' => '%phpcr_backend%', 'workspace' => '%phpcr_workspace%', 'username' => '%phpcr_user%', 'password' => '%phpcr_pass%', - ), - 'website' => array( - 'backend' => array( + ], + 'website' => [ + 'backend' => [ 'type' => 'jackrabbit', 'url' => '%magnolia_url%', - ), + ], 'workspace' => 'website', 'username' => '%magnolia_user%', 'password' => '%magnolia_pass%', - ), - 'dms' => array( - 'backend' => array( + ], + 'dms' => [ + 'backend' => [ 'type' => 'jackrabbit', 'url' => '%magnolia_url%', - ), + ], 'workspace' => 'dms', 'username' => '%magnolia_user%', 'password' => '%magnolia_pass%', - ), - ), - ), + ], + ], + ], // enable the ODM layer - 'odm' => array( + 'odm' => [ 'auto_generate_proxy_classes' => '%kernel.debug%', - 'document_managers' => array( - 'default' => array( + 'document_managers' => [ + 'default' => [ 'session' => 'default', - 'mappings' => array( - 'SandboxMainBundle' => null, + 'mappings' => [ + 'AppBundle' => null, 'CmfContentBundle' => null, 'CmfMenuBundle' => null, 'CmfRoutingBundle' => null, - ), - ), - 'website' => array( + ], + ], + 'website' => [ 'session' => 'website', - 'configuration_id' => 'sandbox_magnolia.odm_configuration', - 'mappings' => array( - 'SandboxMagnoliaBundle' => null, - ), - ), - 'dms' => array( + 'configuration_id' => 'magnolia.odm_configuration', + 'mappings' => [ + 'MagnoliaBundle' => null, + ], + ], + 'dms' => [ 'session' => 'dms', - 'configuration_id' => 'sandbox_magnolia.odm_configuration', - 'mappings' => array( - 'SandboxMagnoliaBundle' => null, - ), - ), - ), - ), - )); + 'configuration_id' => 'magnolia.odm_configuration', + 'mappings' => [ + 'MagnoliaBundle' => null, + ], + ], + ], + ], + ]); You can access the managers through the manager registry available in