Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 4dc4570

Browse files
committed
Merge pull request #311 from symfony-cmf/getting_started_with_phpcr_odm
[WIP] Getting started with phpcr odm
2 parents 8dbc066 + 99b32ca commit 4dc4570

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
.. index::
2+
single: PHPCR-ODM, Creating a New Project
3+
4+
Create a New Project with PHPCR-ODM
5+
===================================
6+
7+
This article will show you how to create a new Symfony project from the
8+
`Symfony Standard Edition`_ using PHPCR-ODM instead of (or in addition to) the
9+
`Doctrine ORM`_.
10+
11+
For more information on the PHPCR-ODM see the
12+
:doc:`../book/database_layer` article.
13+
14+
General Instructions using Jackalope Doctrine DBAL
15+
--------------------------------------------------
16+
17+
The `Jackalope`_ Doctrine DBAL backend will use `Doctrine DBAL`_ to store the
18+
content repository.
19+
20+
**Step 1**: Create a new Symfony project with composer based on the standard edition:
21+
22+
.. code-block:: bash
23+
24+
$ php composer.phar create-project symfony/framework-standard-edition path/
25+
26+
**Step 2**: Add the required packages to ``composer.json``:
27+
28+
.. code-block:: javascript
29+
30+
{
31+
...
32+
"require": {
33+
...
34+
"doctrine/phpcr-bundle": "1.0.0",
35+
"doctrine/doctrine-bundle": "1.2.*",
36+
"doctrine/phpcr-odm": "1.0.*",
37+
"jackalope/jackalope-doctrine-dbal": "1.0.0"
38+
}
39+
}
40+
41+
**Step 3**: (*optional*) Remove the Doctrine ORM:
42+
43+
Remove the ``doctrine\orm`` package from ``composer.json``.
44+
45+
**Step 4**: Add the DoctrinePHPCRBundle to the AppKernel::
46+
47+
// app/AppKernel.php
48+
49+
// ...
50+
class AppKernel extends Kernel
51+
{
52+
public function registerBundles()
53+
{
54+
$bundles = array(
55+
// ...
56+
new Doctrine\Bundle\PHPCRBundle\DoctrinePHPCRBundle(),
57+
);
58+
59+
// ...
60+
}
61+
}
62+
63+
**Step 5**: (*optional*) Register the PHPCR-ODM annotations in ``app/autoload.php``::
64+
65+
// app/autoload.php
66+
67+
// ...
68+
AnnotationRegistry::registerFile(
69+
__DIR__.'/../vendor/doctrine/phpcr-odm/lib/Doctrine/ODM/PHPCR/Mapping/Annotations/DoctrineAnnotations.php'
70+
);
71+
72+
**Step 6**: Modify ``parameters.yml``, adding the required PHPCR-ODM settings:
73+
74+
.. code-block:: yaml
75+
76+
# app/config/parameters.yml.dist
77+
parameters:
78+
# ...
79+
phpcr_backend:
80+
type: doctrinedbal
81+
connection: default
82+
phpcr_workspace: default
83+
phpcr_user: admin
84+
phpcr_pass: admin
85+
86+
.. note::
87+
88+
The actual database backend (MySQL, sqlite3, Postgres etc) is handled by
89+
Doctrine DBAL.
90+
91+
**Step 7**: Add the Doctrine PHPCR configuration to the main application configuration:
92+
93+
.. configuration-block::
94+
95+
.. code-block:: yaml
96+
97+
# ...
98+
doctrine_phpcr:
99+
# configure the PHPCR session
100+
session:
101+
backend: %phpcr_backend%
102+
workspace: %phpcr_workspace%
103+
username: %phpcr_user%
104+
password: %phpcr_pass%
105+
# enable the ODM layer
106+
odm:
107+
auto_mapping: true
108+
auto_generate_proxy_classes: %kernel.debug%
109+
110+
.. code-block:: xml
111+
112+
<?xml version="1.0" encoding="UTF-8" ?>
113+
<container xmlns="http://symfony.com/schema/dic/services">
114+
<config xmlns="http://example.org/schema/dic/doctrine_phpcr">
115+
<session backend="%phpcr_backend%"
116+
workspace="%phpcr_workspace%"
117+
username="%phpcr_user%"
118+
password="%phpcr_pass%"
119+
/>
120+
121+
<odm auto-mapping="true"
122+
auto-generate-proxy-classes="%kernel.debug%"
123+
/>
124+
</config>
125+
</container>
126+
127+
.. code-block:: php
128+
129+
$container->loadFromExtension('doctrine_phpcr', array(
130+
'session' => array(
131+
'backend' => '%phpcr_backend%',
132+
'workspace' => '%phpcr_workspace%',
133+
'username' => '%phpcr_username%',
134+
'password' => '%phpcr_password%',
135+
),
136+
'odm' => array(
137+
'auto_mapping' => true,
138+
'auto_generate_proxy_classes' => '%kernel.debug%',
139+
),
140+
));
141+
142+
Alternative Backend: Apache Jackrabbit
143+
--------------------------------------
144+
145+
`Apache Jackrabbit`_ is a mature Java based content repository which can be used
146+
as an alternative to the Jackalope Doctrine DBAL backend.
147+
148+
The instructions are the same as for Doctrine DBAL with the following
149+
differences:
150+
151+
**Step 2**: Include ``jackalope/jackalope-jackrabbit`` instead of
152+
``jackalope/jackalope-doctrine-dbal``.
153+
154+
Install and Run the Jackrabbit Server
155+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
156+
157+
Download Jackrabbit in whatever way you prefer (for example using ``wget``):
158+
159+
.. code-block:: bash
160+
161+
$ wget http://www.apache.org/dyn/closer.cgi/jackrabbit/2.4.5/jackrabbit-standalone-2.4.5.jar
162+
163+
Start the Jackrabbit server:
164+
165+
.. code-block:: bash
166+
167+
$ java -jar jackrabbit
168+
169+
This will create a directory called ``jackrabbit`` in the current working
170+
directory which will contain the data of the content repository.
171+
172+
.. _`Symfony Standard Edition`: https://github.com/symfony/symfony-standard
173+
.. _`Doctrine ORM`: https://github.com/doctrine/doctrine2
174+
.. _`Apache Jackrabbit`: https://jackrabbit.apache.org
175+
.. _`Jackalope`: https://github.com/jackalope/jackalope
176+
.. _`Doctrine DBAL`: https://github.com/doctrine/dbal

cookbook/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The Cookbook
44
.. toctree::
55
:hidden:
66

7+
create_new_project_phpcr_odm
78
database/choosing_storage_layer
89
editions/cmf_sandbox
910
editions/cmf_core

cookbook/map.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
* :doc:`editions/cmf_sandbox`
88
* :doc:`editions/cmf_core`
9+
* :doc:`create_new_project_phpcr_odm`
910
* :doc:`installing_configuring_doctrine_phpcr_odm`
1011
* :doc:`creating_cms_using_cmf_and_sonata`
1112
* :doc:`using_blockbundle_and_contentbundle`

index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ Want to know more about the CMF and how each part can be configured? There's a t
134134
.. toctree::
135135
:maxdepth: 1
136136

137+
cookbook/create_new_project_phpcr_odm
137138
cookbook/database/choosing_storage_layer
138139
cookbook/editions/cmf_sandbox
139140
cookbook/editions/cmf_core

0 commit comments

Comments
 (0)