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

Commit d6525e8

Browse files
committed
Merge pull request #596 from symfony-cmf/fixture_om_check
validate we have the right type of object manager in the fixtures
2 parents 9abb6be + aa4bdb5 commit d6525e8

File tree

8 files changed

+55
-0
lines changed

8 files changed

+55
-0
lines changed

book/routing.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ follows::
461461
*/
462462
public function load(ObjectManager $dm)
463463
{
464+
if (!$dm instanceof DocumentManager) {
465+
$class = get_class($dm);
466+
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
467+
}
468+
464469
$route = new Route();
465470
$route->setParentDocument($dm->find(null, '/cms/routes'));
466471
$route->setName('projects');

book/simplecms.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ To create a page, use the
6161
*/
6262
public function load(ObjectManager $dm)
6363
{
64+
if (!$dm instanceof DocumentManager) {
65+
$class = get_class($dm);
66+
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
67+
}
68+
6469
$parent = $dm->find(null, '/cms/simple');
6570
$page = new Page();
6671
$page->setTitle('About Symfony CMF');
@@ -111,6 +116,11 @@ structure, you would do::
111116
*/
112117
public function load(ObjectManager $dm)
113118
{
119+
if (!$dm instanceof DocumentManager) {
120+
$class = get_class($dm);
121+
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
122+
}
123+
114124
$root = $dm->find(null, '/cms/simple');
115125

116126
$about = new Page();

bundles/phpcr_odm/fixtures_initializers.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,11 @@ A simple example fixture class looks like this::
298298
{
299299
public function load(ObjectManager $manager)
300300
{
301+
if (!$manager instanceof DocumentManager) {
302+
$class = get_class($manager);
303+
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
304+
}
305+
301306
// ... create and persist your data here
302307
}
303308
}

bundles/seo/seo_aware.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ And after that, you can use the
156156
{
157157
public function load(ObjectManager $manager)
158158
{
159+
if (!$dm instanceof DocumentManager) {
160+
$class = get_class($dm);
161+
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
162+
}
163+
159164
$page = new Page();
160165
// ... set some page properties
161166

quick_tour/the_model.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ PHPCR. But first, you have to create a new Page document::
116116
// ...
117117
public function load(ObjectManager $documentManager)
118118
{
119+
if (!$documentManager instanceof DocumentManager) {
120+
$class = get_class($documentManager);
121+
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
122+
}
123+
119124
$page = new Page(); // create a new Page object (document)
120125
$page->setName('new_page'); // the name of the node
121126
$page->setLabel('Another new Page');
@@ -130,6 +135,11 @@ it as its parent::
130135
// ...
131136
public function load(ObjectManager $documentManager)
132137
{
138+
if (!$documentManager instanceof DocumentManager) {
139+
$class = get_class($documentManager);
140+
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
141+
}
142+
133143
// ...
134144

135145
// get root document (/cms/simple)
@@ -144,6 +154,11 @@ document using the Doctrine API::
144154
// ...
145155
public function load(ObjectManager $documentManager)
146156
{
157+
if (!$documentManager instanceof DocumentManager) {
158+
$class = get_class($documentManager);
159+
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
160+
}
161+
147162
// ...
148163
$documentManager->persist($page); // add the Page in the queue
149164
$documentManager->flush(); // add the Page to PHPCR

quick_tour/the_router.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ Now you can add a new ``Route`` to the tree using Doctrine::
158158
{
159159
public function load(ObjectManager $documentManager)
160160
{
161+
if (!$documentManager instanceof DocumentManager) {
162+
$class = get_class($documentManager);
163+
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
164+
}
165+
161166
$routesRoot = $documentManager->find(null, '/cms/routes');
162167

163168
$route = new Route();

tutorial/getting-started.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,11 @@ Create a page for your CMS::
372372
{
373373
public function load(ObjectManager $dm)
374374
{
375+
if (!$dm instanceof DocumentManager) {
376+
$class = get_class($dm);
377+
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
378+
}
379+
375380
$parent = $dm->find(null, '/cms/pages');
376381

377382
$page = new Page();

tutorial/the-frontend.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ to which you will add the existing ``Home`` page and an additional ``About`` pag
119119
{
120120
public function load(ObjectManager $dm)
121121
{
122+
if (!$dm instanceof DocumentManager) {
123+
$class = get_class($dm);
124+
throw new \RuntimeException("Fixture requires a PHPCR ODM DocumentManager instance, instance of '$class' given.");
125+
}
126+
122127
$parent = $dm->find(null, '/cms/pages');
123128

124129
$rootPage = new Page();

0 commit comments

Comments
 (0)