Skip to content

Commit

Permalink
Merge pull request #219 from EmmanuelVella/child-interface
Browse files Browse the repository at this point in the history
Use child interface
  • Loading branch information
dbu committed Mar 25, 2014
2 parents cb9124e + 49636fe commit b6f9c17
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

* **2014-03-25**: setParent() and getParent() are now deprecated.
Use setParentDocument() and getParentDocument() instead.
Moreover, you should now enable the ChildExtension from the CoreBundle.

* **2014-03-23**: When using PHPCR-ODM, routes can now be generated with their
uuid as route name as well, in addition to the repository path.

Expand Down
25 changes: 22 additions & 3 deletions Doctrine/Phpcr/RedirectRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

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

use Symfony\Cmf\Bundle\CoreBundle\Model\ChildInterface;
use Symfony\Cmf\Bundle\RoutingBundle\Model\RedirectRoute as RedirectRouteModel;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;

Expand All @@ -21,7 +22,7 @@
* This extends the RedirectRoute Model. We need to re-implement everything
* that the PHPCR Route document adds.
*/
class RedirectRoute extends RedirectRouteModel implements PrefixInterface
class RedirectRoute extends RedirectRouteModel implements PrefixInterface, ChildInterface
{
/**
* parent document
Expand Down Expand Up @@ -75,21 +76,39 @@ public function __construct($addFormatPattern = false, $addTrailingSlash = false
$this->addTrailingSlash = $addTrailingSlash;
}

/**
* @deprecated Use setParentDocument instead.
*/
public function setParent($parent)
{
$this->parent = $parent;

return $this;
}

/**
* @deprecated Use getParentDocument instead.
*/
public function getParent()
{
return $this->parent;
}

/**
* Move the route by setting a parent.
*
* Note that this will change the URL this route matches.
*
* @param object $parent the new parent document
*/
public function setParent($parent)
public function setParentDocument($parent)
{
$this->parent = $parent;

return $this;
}

public function getParent()
public function getParentDocument()
{
return $this->parent;
}
Expand Down
25 changes: 22 additions & 3 deletions Doctrine/Phpcr/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\PHPCR\Document\Generic;
use Doctrine\ODM\PHPCR\Exception\InvalidArgumentException;
use Symfony\Cmf\Bundle\CoreBundle\Model\ChildInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Cmf\Bundle\RoutingBundle\Model\Route as RouteModel;

Expand All @@ -24,7 +25,7 @@
*
* @author [email protected]
*/
class Route extends RouteModel implements PrefixInterface
class Route extends RouteModel implements PrefixInterface, ChildInterface
{
/**
* parent document
Expand Down Expand Up @@ -88,14 +89,32 @@ public function setAddTrailingSlash($addTrailingSlash)
$this->addTrailingSlash = $addTrailingSlash;
}

/**
* @deprecated Use setParentDocument instead.
*/
public function setParent($parent)
{
$this->parent = $parent;

return $this;
}

/**
* @deprecated Use getParentDocument instead.
*/
public function getParent()
{
return $this->parent;
}

/**
* Move the route by setting a parent.
*
* Note that this will change the URL this route matches.
*
* @param object $parent the new parent document
*/
public function setParent($parent)
public function setParentDocument($parent)
{
if (!is_object($parent)) {
throw new InvalidArgumentException("Parent must be an object ".gettype ($parent)." given.");
Expand All @@ -112,7 +131,7 @@ public function setParent($parent)
*
* @return Generic object
*/
public function getParent()
public function getParentDocument()
{
return $this->parent;
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Resources/DataFixtures/Phpcr/LoadRouteData.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public function load(ObjectManager $manager)
$manager->persist($parent);

$route = new Route;
$route->setParent($parent);
$route->setParentDocument($parent);
$route->setName('route-1');
$manager->persist($route);

$redirectRoute = new RedirectRoute;
$redirectRoute->setParent($parent);
$redirectRoute->setParentDocument($parent);
$redirectRoute->setName('redirect-route-1');
$manager->persist($redirectRoute);

Expand Down

0 comments on commit b6f9c17

Please sign in to comment.