Skip to content

Commit 3a8cebc

Browse files
committed
using interface for the id prefix listener
1 parent 5b613d7 commit 3a8cebc

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

Doctrine/Phpcr/IdPrefixListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 || $doc instanceof RedirectRoute)
51+
if (($doc instanceof PrefixInterface)
5252
&& ! strncmp($this->idPrefix, $doc->getId(), strlen($this->idPrefix))
5353
) {
5454
$doc->setPrefix($this->idPrefix);

Doctrine/Phpcr/PrefixInterface.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr;
4+
5+
/**
6+
* An interface for PHPCR route documents.
7+
*
8+
* We use the repository path as static part of the URL, but the documents
9+
* need to know what their base path is to remove that from the URL.
10+
*/
11+
interface PrefixInterface
12+
{
13+
/**
14+
* @return string the full path of this document in the repository.
15+
*/
16+
public function getId();
17+
18+
/**
19+
* @param string $prefix The path in the repository to the routing root
20+
* document.
21+
*/
22+
public function setPrefix($prefix);
23+
}

Doctrine/Phpcr/RedirectRoute.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* This extends the RedirectRoute Model. We need to re-implement everything
1111
* that the PHPCR Route document adds.
1212
*/
13-
class RedirectRoute extends RedirectRouteModel
13+
class RedirectRoute extends RedirectRouteModel implements PrefixInterface
1414
{
1515
/**
1616
* parent document
@@ -143,6 +143,9 @@ public function getPrefix()
143143
return $this->idPrefix;
144144
}
145145

146+
/**
147+
* {@inheritDoc}
148+
*/
146149
public function setPrefix($idPrefix)
147150
{
148151
$this->idPrefix = $idPrefix;

Doctrine/Phpcr/Route.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
1414
*/
15-
class Route extends RouteModel
15+
class Route extends RouteModel implements PrefixInterface
1616
{
1717
/**
1818
* parent document
@@ -145,6 +145,9 @@ public function getPrefix()
145145
return $this->idPrefix;
146146
}
147147

148+
/**
149+
* {@inheritDoc}
150+
*/
148151
public function setPrefix($idPrefix)
149152
{
150153
$this->idPrefix = $idPrefix;

0 commit comments

Comments
 (0)