-
Notifications
You must be signed in to change notification settings - Fork 76
move document to model #112
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
Changes from 3 commits
2a3dfd9
12f5436
7896ad8
5b613d7
3a8cebc
11152d3
f576865
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,29 +58,31 @@ public function getConfigTreeBuilder() | |
->useAttributeAsKey('alias') | ||
->prototype('scalar')->end() | ||
->end() | ||
->scalarNode('manager_registry')->defaultValue('doctrine_phpcr')->end() | ||
->scalarNode('manager_name')->defaultValue('default')->end() | ||
->arrayNode('phpcr_provider') | ||
->children() | ||
->scalarNode('manager_registry')->defaultValue('doctrine_phpcr')->end() | ||
->scalarNode('manager_name')->defaultValue('default')->end() | ||
->scalarNode('route_basepath')->defaultValue('/cms/routes')->end() | ||
->scalarNode('content_basepath')->defaultValue('/cms/content')->end() | ||
->enumNode('use_sonata_admin') | ||
->values(array(true, false, 'auto')) | ||
->defaultValue('auto') | ||
->end() | ||
->end() | ||
->end() | ||
->scalarNode('uri_filter_regexp')->defaultValue('')->end() | ||
->scalarNode('route_provider_service_id')->defaultValue('cmf_routing.default_route_provider')->end() | ||
->scalarNode('route_provider_service_id')->end() | ||
->arrayNode('route_filters_by_id') | ||
->canBeUnset() | ||
->useAttributeAsKey('id') | ||
->prototype('scalar')->end() | ||
->end() | ||
->scalarNode('content_repository_service_id')->defaultValue('cmf_routing.default_content_repository')->end() | ||
->scalarNode('routing_repositoryroot')->defaultValue('/cms/routes')->end() | ||
->scalarNode('content_repository_service_id')->end() | ||
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. Why remove the defaults for 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. because if you enable phpcr, the DI extension will set those alias to the phpcr route provider + content repository now. these options are to override the automatic alias that happens because of your choice of backend. |
||
->arrayNode('locales') | ||
->prototype('scalar')->end() | ||
->end() | ||
->end() | ||
->end() | ||
->enumNode('use_sonata_admin') | ||
->values(array(true, false, 'auto')) | ||
->defaultValue('auto') | ||
->end() | ||
->scalarNode('content_basepath')->defaultValue('/cms/content')->end() | ||
// TODO: fix widget to show root node when root is selectable, then use routing_repositoryroot for both | ||
->scalarNode('route_basepath')->defaultValue('/cms')->end() | ||
->end() | ||
; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine; | ||
|
||
use Doctrine\Common\Persistence\ManagerRegistry; | ||
use Doctrine\Common\Persistence\ObjectManager; | ||
|
||
/** | ||
* Abstract class for doctrine based content repository and route provider | ||
* implementations. | ||
* | ||
* @author Uwe Jäger | ||
* @author David Buchmann <[email protected]> | ||
*/ | ||
abstract class DoctrineProvider | ||
{ | ||
/** | ||
* If this is null, the manager registry will return the default manager. | ||
* | ||
* @var string|null Name of object manager to use | ||
*/ | ||
protected $managerName; | ||
|
||
/** | ||
* @var ManagerRegistry | ||
*/ | ||
protected $managerRegistry; | ||
|
||
/** | ||
* Class name of the object class to find, null for PHPCR-ODM as it can | ||
* determine the class on its own. | ||
* | ||
* @var string|null | ||
*/ | ||
protected $className; | ||
|
||
/** | ||
* @param ManagerRegistry $managerRegistry | ||
*/ | ||
public function __construct(ManagerRegistry $managerRegistry, $className = null) | ||
{ | ||
$this->managerRegistry = $managerRegistry; | ||
} | ||
|
||
/** | ||
* Set the object manager name to use for this loader. If not set, the | ||
* default manager as decided by the manager registry will be used. | ||
* | ||
* @param string|null $managerName | ||
*/ | ||
public function setManagerName($managerName) | ||
{ | ||
$this->managerName = $managerName; | ||
} | ||
|
||
/** | ||
* Get the object manager named $managerName from the registry. | ||
* | ||
* @return ObjectManager | ||
*/ | ||
protected function getObjectManager() | ||
{ | ||
return $this->managerRegistry->getManager($this->managerName); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr; | ||
|
||
use Symfony\Cmf\Component\Routing\ContentRepositoryInterface; | ||
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\DoctrineProvider; | ||
|
||
/** | ||
* Implement ContentRepositoryInterface for PHPCR-ODM | ||
* | ||
* This is <strong>NOT</strong> not a doctrine repository but just the content | ||
* provider for the NestedMatcher. (you could of course implement this | ||
* interface in a repository class, if you need that) | ||
* | ||
* @author Uwe Jäger | ||
*/ | ||
class ContentRepository extends DoctrineProvider implements ContentRepositoryInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function findById($id) | ||
{ | ||
return $this->getObjectManager()->find(null, $id); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getContentId($content) | ||
{ | ||
if (! is_object($content)) { | ||
return null; | ||
} | ||
try { | ||
return $this->getObjectManager()->getUnitOfWork()->getDocumentId($content); | ||
} catch (\Exception $e) { | ||
return null; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\RoutingBundle\Listener; | ||
namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr; | ||
|
||
use Symfony\Cmf\Bundle\RoutingBundle\Document\Route; | ||
use Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route; | ||
use Doctrine\Common\Persistence\Event\LifecycleEventArgs; | ||
|
||
/** | ||
* Doctrine PHPCR-ODM listener to set the idPrefix on new routes | ||
* Doctrine PHPCR-ODM listener to set the idPrefix on routes | ||
* | ||
* @author david.buchmann@liip.ch | ||
* @author David Buchmann <mail@davidbu.ch> | ||
*/ | ||
class IdPrefix | ||
class IdPrefixListener | ||
{ | ||
/** | ||
* The prefix to add to the url to create the repository path | ||
|
@@ -48,7 +48,7 @@ protected function updateId(LifecycleEventArgs $args) | |
|
||
// only update route objects and only if the prefix can match, to allow | ||
// for more than one listener and more than one route root | ||
if ($doc instanceof Route | ||
if (($doc instanceof Route || $doc instanceof RedirectRoute) | ||
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. this is one of the drawbacks of not having multiple inheritance/traits to build the document classes... 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. Not sure I understand, why can't they at least implement an interface? 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. well then we would define a PhpcrPathPrefixInterface or something, just sounds weird as its just an implementation detail. if this was a Trait, we could check the class for having the trait. (but until php 5.3 can be dropped, i guess we are at least in Symfony3...) 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. Hmm. Why would such an interface be a bad idea? Although, the only problem I can see here is if/when the user wants another type of Routing object à la "RedirectRoute". They would have to override this class - creating a little interface in the Doctrine/PHPCR namespace seems like a painless solution? If we were to implement the interface I guess we would also have to determine the ID from either the DM or the metadata also. 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. ok, convinced. i added the interface |
||
&& ! strncmp($this->idPrefix, $doc->getId(), strlen($this->idPrefix)) | ||
) { | ||
$doc->setPrefix($this->idPrefix); | ||
|
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.
Should this rather default to NULL? Otherwise the default manager as defined by
phpcr_odm
is worthless?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.
ups, very true. fixed.