Skip to content

Commit 2a3dfd9

Browse files
committed
move document to model
1 parent a916a0d commit 2a3dfd9

37 files changed

+1213
-784
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
=========
33

4+
* **2013-06-15**: [Model] Separated database agnostic, doctrine generic and
5+
PHPCR-ODM specific code to prepare for Doctrine ORM support. Deprecated
6+
RoutingBundle\Document\Route and RedirectRoute in favor of
7+
RoutingBundle\Doctrine\Phpcr\Route resp. RedirectRoute and also moved the
8+
PHPCR-ODM specific listeners and repository implementations to Doctrine\Phpcr
9+
10+
1.1.0-beta1
11+
-----------
12+
413
* **2013-05-28**: [Bundle] Only include Doctrine PHPCR compiler pass if PHPCR-ODM is present
514
* **2013-05-25**: [Bundle] Drop symfony_ from symfony_cmf prefix
615
* **2013-05-24**: [Document] ContentRepository now requires ManagerRegistry in the constructor and provides `setManagerName()` in the same way as RouteProvider

CmfRoutingBundle.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ public function build(ContainerBuilder $container)
2727

2828
if (class_exists('Doctrine\Bundle\PHPCRBundle\DependencyInjection\Compiler\DoctrinePhpcrMappingsPass')) {
2929
$container->addCompilerPass($this->buildBasePhpcrCompilerPass());
30+
$container->addCompilerPass(
31+
DoctrinePhpcrMappingsPass::createXmlMappingDriver(
32+
array(
33+
realpath(__DIR__ . '/Resources/config/doctrine-model') => 'Symfony\Cmf\Bundle\RoutingBundle\Model',
34+
realpath(__DIR__ . '/Resources/config/doctrine-phpcr') => 'Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr',
35+
),
36+
array('cmf_routing.manager_name')
37+
)
38+
);
3039
}
3140
}
3241

Doctrine/DoctrineProvider.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine;
4+
5+
use Doctrine\Common\Persistence\ManagerRegistry;
6+
use Doctrine\Common\Persistence\ObjectManager;
7+
8+
/**
9+
* Abstract class for doctrine based content repository and route provider
10+
* implementations.
11+
*
12+
* @author Uwe Jäger
13+
* @author David Buchmann <[email protected]>
14+
*/
15+
abstract class DoctrineProvider
16+
{
17+
/**
18+
* If this is null, the manager registry will return the default manager.
19+
*
20+
* @var string|null Name of object manager to use
21+
*/
22+
protected $managerName;
23+
24+
/**
25+
* @var ManagerRegistry
26+
*/
27+
protected $managerRegistry;
28+
29+
/**
30+
* Class name of the object class to find, null for PHPCR-ODM as it can
31+
* determine the class on its own.
32+
*
33+
* @var string|null
34+
*/
35+
protected $className;
36+
37+
/**
38+
* @param ManagerRegistry $managerRegistry
39+
*/
40+
public function __construct(ManagerRegistry $managerRegistry, $className = null)
41+
{
42+
$this->managerRegistry = $managerRegistry;
43+
}
44+
45+
/**
46+
* Set the object manager name to use for this loader. If not set, the
47+
* default manager as decided by the manager registry will be used.
48+
*
49+
* @param string|null $managerName
50+
*/
51+
public function setManagerName($managerName)
52+
{
53+
$this->managerName = $managerName;
54+
}
55+
56+
/**
57+
* Get the object manager named $managerName from the registry.
58+
*
59+
* @return ObjectManager
60+
*/
61+
protected function getObjectManager()
62+
{
63+
return $this->managerRegistry->getManager($this->managerName);
64+
}
65+
}

Doctrine/Phpcr/ContentRepository.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr;
4+
5+
use Symfony\Cmf\Component\Routing\ContentRepositoryInterface;
6+
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\DoctrineProvider;
7+
8+
/**
9+
* Implement ContentRepositoryInterface for PHPCR-ODM
10+
*
11+
* This is <strong>NOT</strong> not a doctrine repository but just the content
12+
* provider for the NestedMatcher. (you could of course implement this
13+
* interface in a repository class, if you need that)
14+
*
15+
* @author Uwe Jäger
16+
*/
17+
class ContentRepository extends DoctrineProvider implements ContentRepositoryInterface
18+
{
19+
/**
20+
* {@inheritDoc}
21+
*/
22+
public function findById($id)
23+
{
24+
return $this->getObjectManager()->find(null, $id);
25+
}
26+
27+
/**
28+
* {@inheritDoc}
29+
*/
30+
public function getContentId($content)
31+
{
32+
if (! is_object($content)) {
33+
return null;
34+
}
35+
try {
36+
return $this->getObjectManager()->getUnitOfWork()->getDocumentId($content);
37+
} catch (\Exception $e) {
38+
return null;
39+
}
40+
}
41+
}

Listener/IdPrefix.php renamed to Doctrine/Phpcr/IdPrefixListener.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
22

3-
namespace Symfony\Cmf\Bundle\RoutingBundle\Listener;
3+
namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr;
44

5-
use Symfony\Cmf\Bundle\RoutingBundle\Document\Route;
5+
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
66
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
77

88
/**
9-
* Doctrine PHPCR-ODM listener to set the idPrefix on new routes
9+
* Doctrine PHPCR-ODM listener to set the idPrefix on routes
1010
*
11-
* @author david.buchmann@liip.ch
11+
* @author David Buchmann <mail@davidbu.ch>
1212
*/
13-
class IdPrefix
13+
class IdPrefixListener
1414
{
1515
/**
1616
* The prefix to add to the url to create the repository path
@@ -48,7 +48,7 @@ protected function updateId(LifecycleEventArgs $args)
4848

4949
// only update route objects and only if the prefix can match, to allow
5050
// for more than one listener and more than one route root
51-
if ($doc instanceof Route
51+
if (($doc instanceof Route || $doc instanceof RedirectRoute)
5252
&& ! strncmp($this->idPrefix, $doc->getId(), strlen($this->idPrefix))
5353
) {
5454
$doc->setPrefix($this->idPrefix);

Listener/LocaleUpdater.php renamed to Doctrine/Phpcr/LocaleListener.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<?php
22

3-
namespace Symfony\Cmf\Bundle\RoutingBundle\Listener;
3+
namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr;
44

5-
use Symfony\Cmf\Bundle\RoutingBundle\Document\Route;
65
use Doctrine\ODM\PHPCR\Event\MoveEventArgs;
76
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
87

8+
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route;
9+
910
/**
1011
* Doctrine PHPCR-ODM listener to update the locale on routes based on the URL.
1112
*
1213
* It uses the idPrefix and looks at the path segment right after the prefix to
1314
* determine if that segment matches one of the configured locales and if so
1415
* sets a requirement and default named _locale for that locale.
1516
*
16-
* @author David Buchmann <david@liip.ch>
17+
* @author David Buchmann <mail@davidbu.ch>
1718
*/
18-
class LocaleUpdater
19+
class LocaleListener
1920
{
2021
/**
2122
* The prefix to add to the url to create the repository path

0 commit comments

Comments
 (0)