@@ -164,7 +164,6 @@ If you want control over the last modified timestamp, disable
164
164
of the PHPCR-ODM documentation.
165
165
166
166
.. versionadded :: 1.1
167
-
168
167
Since DoctrinePhpcrBundle 1.1, backend configuration flags are configured
169
168
in the ``parameters `` section. They are passed as-is to Jackalope. See the
170
169
``RepositoryFactory `` for some more documentation on the meaning of those
@@ -257,7 +256,7 @@ supported by Doctrine.
257
256
258
257
You can specify the connection name to use if you don't want to use the default
259
258
connection. The name must be one of the names of the dbal section in your
260
- Doctrine configuration, see ` the Symfony2 Doctrine documentation `_.
259
+ Doctrine configuration, see the ` Symfony2 Doctrine documentation `_.
261
260
262
261
You can tune the behaviour with the general Jackalope parameters listed above,
263
262
as well as enable transactions (Jackrabbit does not support transactions):
@@ -446,7 +445,7 @@ The session backend configuration looks as follows:
446
445
),
447
446
));
448
447
449
- For more information, please refer to ` the official Midgard PHPCR documentation `_.
448
+ For more information, please refer to the ` official Midgard PHPCR documentation `_.
450
449
451
450
Profiling and Performance of Jackalope
452
451
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1346,13 +1345,18 @@ Repository Initializers
1346
1345
1347
1346
The Initializer is the PHPCR equivalent of the ORM schema tools. It
1348
1347
is used to let bundles register PHPCR node types and to create required base
1349
- paths in the repository. Initializers have to implement
1350
- ``Doctrine\Bundle\PHPCRBundle\Initializer ``. If you don't need any special
1351
- logic, you can simply configure the ``GenericInitializer `` as service and don't
1352
- need to write any code. The generic initializer expects a name to identify
1353
- the initializer, an array of base paths it will create if they do not exist
1354
- and an optional string defining namespaces and primary / mixin node types in
1355
- the CND language.
1348
+ paths in the repository. Initializers have to implement the
1349
+ ``Doctrine\Bundle\PHPCRBundle\Initializer\InitializerInterface ``. If you don't
1350
+ need any special logic and want to create plain PHPCR nodes and not documents,
1351
+ you can simply define services with ``GenericInitializer ``. The generic
1352
+ initializer expects a name to identify the initializer, an array of repository
1353
+ paths it will create if they do not exist and an optional string defining
1354
+ namespaces and primary / mixin node types in the CND language.
1355
+
1356
+ .. versionadded :: 1.1
1357
+ Since version 1.1, the ``GenericInitializer `` expects a name parameter
1358
+ as first argument. With 1.0 there is no way to specify a custom name
1359
+ for the generic initializer.
1356
1360
1357
1361
A service to use the generic initializer looks like this:
1358
1362
@@ -1361,7 +1365,7 @@ A service to use the generic initializer looks like this:
1361
1365
.. code-block :: yaml
1362
1366
1363
1367
# src/Acme/ContentBundle/Resources/config/services.yml
1364
- acme .phpcr.initializer :
1368
+ acme_content .phpcr.initializer :
1365
1369
class : Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer
1366
1370
arguments :
1367
1371
- AcmeContentBundle Basepaths
@@ -1373,7 +1377,7 @@ A service to use the generic initializer looks like this:
1373
1377
.. code-block :: xml
1374
1378
1375
1379
<!-- src/Acme/ContentBundle/Resources/config/services.xml -->
1376
- <service id =" acme .phpcr.initializer" class =" Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer" >
1380
+ <service id =" acme_content .phpcr.initializer" class =" Doctrine\Bundle\PHPCRBundle\Initializer\GenericInitializer" >
1377
1381
<argument >AcmeContentBundle Basepaths</argument >
1378
1382
<argument type =" collection" >
1379
1383
<argument >%acme.content_basepath%</argument >
@@ -1398,7 +1402,7 @@ A service to use the generic initializer looks like this:
1398
1402
)
1399
1403
));
1400
1404
$definition->addTag('doctrine_phpcr.initializer');
1401
- $container->setDefinition('acme .phpcr.initializer', $definition);
1405
+ $container->setDefinition('acme_content .phpcr.initializer', $definition);
1402
1406
1403
1407
You can execute your initializers using the following command:
1404
1408
@@ -1407,9 +1411,110 @@ You can execute your initializers using the following command:
1407
1411
$ php app/console doctrine:phpcr:repository:init
1408
1412
1409
1413
.. versionadded :: 1.1
1414
+ Since DoctrinePHPCRBundle 1.1 the load data fixtures command will
1415
+ automatically execute the initializers after purging the database.
1416
+
1417
+ The generic initializer only creates PHPCR nodes. If you want to create
1418
+ specific documents, you need your own initializer. The interesting method
1419
+ to overwrite is the ``init `` method. It is passed the ``ManagerRegistry ``,
1420
+ from which you can retrieve the PHPCR session but also the document manager::
1421
+
1422
+ // src/Acme/BasicCmsBundle/Initializer/SiteInitializer.php
1423
+ namespace Acme\ContentBundle\Initializer;
1424
+
1425
+ use Doctrine\Bundle\PHPCRBundle\Initializer\InitializerInterface;
1426
+ use PHPCR\SessionInterface;
1427
+ use PHPCR\Util\NodeHelper;
1428
+
1429
+ class SiteInitializer implements InitializerInterface
1430
+ {
1431
+ private $basePath;
1432
+
1433
+ public function __construct($basePath = '/cms')
1434
+ {
1435
+ $this->basePath = $basePath;
1436
+ }
1437
+
1438
+ public function init(ManagerRegistry $registry)
1439
+ {
1440
+ $dm = $registry->getManagerForClass('Acme\BasicCmsBundle\Document\Site');
1441
+ if ($dm->find(null, $this->basePath)) {
1442
+ return;
1443
+ }
1444
+
1445
+ $site = new Acme\BasicCmsBundle\Document\Site();
1446
+ $site->setId($this->basePath);
1447
+ $dm->persist($site);
1448
+ $dm->flush();
1449
+
1450
+ $session = $registry->getConnection();
1451
+ // create the 'cms', 'pages', and 'posts' nodes
1452
+ NodeHelper::createPath($session, '/cms/pages');
1453
+ NodeHelper::createPath($session, '/cms/posts');
1454
+ NodeHelper::createPath($session, '/cms/routes');
1455
+
1456
+ $session->save();
1457
+ }
1458
+
1459
+ public function getName()
1460
+ {
1461
+ return 'Site Initializer';
1462
+ }
1463
+ }
1464
+
1465
+ .. versionadded :: 1.1
1466
+ Since version 1.1, the init method is passed the ``ManagerRegistry `` rather
1467
+ than the PHPCR ``SessionInterface `` to allow the creation of documents in
1468
+ initializers. With 1.0, you would need to manually set the ``phpcr:class ``
1469
+ property to the right value.
1470
+
1471
+ Define a service for your initializer as follows:
1410
1472
1411
- Since DoctrinePHPCRBundle 1.1 the load data fixtures command will automatically
1412
- execute the initializers after purging the database.
1473
+ .. configuration-block ::
1474
+
1475
+ .. code-block :: yaml
1476
+
1477
+ # src/Acme/BasicCmsBundle/Resources/config/config.yml
1478
+ services :
1479
+ # ...
1480
+ acme_content.phpcr.initializer.site :
1481
+ class : Acme\BasicCmsBundle\Initializer\SiteInitializer
1482
+ tags :
1483
+ - { name: doctrine_phpcr.initializer }
1484
+
1485
+ .. code-block :: xml
1486
+
1487
+ <!-- src/Acme/BasicCmsBUndle/Resources/config/config.php
1488
+ <?xml version="1.0" encoding="UTF-8" ?>
1489
+ <container xmlns="http://symfony.com/schema/dic/services"
1490
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1491
+ xmlns:acme_demo="http://www.example.com/symfony/schema/"
1492
+ xsi:schemaLocation="http://symfony.com/schema/dic/services
1493
+ http://symfony.com/schema/dic/services/services-1.0.xsd">
1494
+
1495
+ <!-- ... -->
1496
+ <services >
1497
+ <!-- ... -->
1498
+ <service id =" acme_content.phpcr.initializer.site"
1499
+ class =" Acme\BasicCmsBundle\Initializer\SiteInitializer" >
1500
+ <tag name =" doctrine_phpcr.initializer" />
1501
+ </service >
1502
+ </services >
1503
+
1504
+ </container >
1505
+
1506
+ .. code-block :: php
1507
+
1508
+ // src/Acme/BasicCmsBundle/Resources/config/config.php
1509
+
1510
+ // ...
1511
+ $container
1512
+ ->register(
1513
+ 'acme_content.phpcr.initializer.site',
1514
+ 'Acme\BasicCmsBundle\Initializer\SiteInitializer'
1515
+ )
1516
+ ->addTag('doctrine_phpcr.initializer', array('name' => 'doctrine_phpcr.initializer')
1517
+ ;
1413
1518
1414
1519
Fixture Loading
1415
1520
---------------
0 commit comments