Skip to content
57 changes: 57 additions & 0 deletions Doctrine/Orm/ContentRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm;

/**
* Abstract content repository for PHPCR-ODM
*
* @author teito
*/
class ContentRepository extends DoctrineProvider implements ContentRepositoryInterface
{
/**
* Determine target class and id for this content
*
* @param mixed $identifier as produced by getContentId
*
* @return array with model first element, id second
*/
protected function getModelAndId($identifier)
{
return explode(':', $identifier, 2);
}

/**
* {@inheritDoc}
*/
public function findById($id)
{
list($model, $modelId) = $this->getModelAndId($id);

return $this->getObjectManager()->getRepository($model)->find($modelId);
}

/**
* {@inheritDoc}
*/
public function getContentId($content)
{
if (! is_object($content)) {
return null;
}

try {
$meta = $this->getObjectManager()->getClassMetadata(get_class($content));
$ids = $meta->getIdentifierValues($content);
if (0 !== count($ids)) {
throw new \Exception('Multi identifier values not supported in ' . get_class($content));
}
return implode(':', array(
get_class($content),
reset($ids)
));
} catch (\Exception $e) {
return null;
}
}
}
55 changes: 55 additions & 0 deletions Doctrine/Orm/RouteProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm;

use Symfony\Component\Routing\Route as SymfonyRoute;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Exception\RouteNotFoundException;

use Symfony\Component\HttpFoundation\Request;

use Symfony\Cmf\Component\Routing\RouteProviderInterface;

/**
* Provider loading routes from Doctrine
*
* This is <strong>NOT</strong> not a doctrine repository but just the route
* provider for the NestedMatcher. (you could of course implement this
* interface in a repository class, if you need that)
*
* @author [email protected]
*/
class RouteProvider extends DoctrineProvider implements RouteProviderInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you forget a use statement for DoctrineProvider?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, there's some more missing which is going to be submitted in a pull request tonite, then code will be available for review

{
protected function getCandidates($url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this logic the same as with the ODM? Should we encapsulate it in a class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, the phpcr is using id prefix all over the place here

{
$candidates = array();
if ('/' !== $url) {
if (preg_match('/(.+)\.[a-z]+$/i', $url, $matches)) {
$candidates[] = $url;
$url = $matches[1];
}

$part = $url;
while (false !== ($pos = strrpos($part, '/'))) {
$candidates[] = $part;
$part = substr($url, 0, $pos);
}
}

$candidates[] = '/';

return $candidates;
}

/**
* {@inheritDoc}
*/
public function getRouteByName($name, $parameters = array())
{
}

public function getRoutesByNames($names, $parameters = array())
{
}
}