Skip to content

[WIP] orm provider and content repository #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
{
protected function getCandidates($url)
{
$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())
{
}
}