-
Notifications
You must be signed in to change notification settings - Fork 76
[WIP] ORM based dynamic routing #122
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
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
65af83e
WIP orm provider and content repository
dbu 3e4ac26
Added orm entity and implemented provider matching; added orm configu…
matteocaberlotto 2a2b2da
added namespace to orm manager name parameter
matteocaberlotto 74cd6f3
RouteProvider::getRouteByName() returns a collection
matteocaberlotto 6a34a0f
fix: orm mapping configuration options
matteocaberlotto f361535
fix: added orm mapping for Symfony\Component\Routing\Route
matteocaberlotto f5dfd9f
Merge pull request #133 from raindropdevs/orm
dbu efb7f45
Merge remote-tracking branch 'origin/master' into orm
dbu 48194cb
making configuration consistent
dbu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
| { | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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