Skip to content

Commit

Permalink
Changed service to use array of Breadcrumbs. Removed Trail.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Hillerström committed Jun 28, 2012
1 parent b87d3d4 commit 3cf685d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 262 deletions.
22 changes: 4 additions & 18 deletions Model/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class Breadcrumb
/**
* @var string Label of the breadcrumb
*/
private $label;
public $label;

/**
* @var string Url of the breadcrumb
*/
private $url;
public $url;

/**
* @param string $label Label of the breadcrumb
Expand All @@ -32,23 +32,9 @@ public function __construct($label, $url = '')
$this->url = $url;
}

/**
* @return string Label of the breadcrumb
*/
public function getLabel() {
return $this->label;
}

/**
* @return string Url of the breadcrumb
*/
public function getUrl() {
return $this->url;
}

public function __toString()
{
$tpl = " Object\n(\n label => %s\n url => %s\n)";
return __CLASS__ . sprintf($tpl, $this->getLabel(), $this->getUrl());
$tpl = " Object(\n label => %s\n url => %s\n)";
return __CLASS__ . sprintf($tpl, $this->label, $this->url);
}
}
111 changes: 0 additions & 111 deletions Model/Trail.php

This file was deleted.

18 changes: 11 additions & 7 deletions Service/BreadcrumbsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use \Symfony\Component\Routing\Route;
use \Symfony\Component\Routing\RouteCollection;
use \Symfony\Component\Routing\RouterInterface;
use \Xi\Bundle\BreadcrumbsBundle\Model\Breadcrumb;

/**
* A service class to build breadcrumbs from Symfony routes.
Expand Down Expand Up @@ -48,25 +49,27 @@ public function setRouter(RouterInterface $router)
}

/**
* @param string $route
*
* @param string $name
* @return array
*/
public function getBreadcrumbs($name, array $params = array())
{
$route = $this->getRoute($name);
$parents = $this->getParents($name);
$breadcrumbs = array();

if ($route && $parents) {
foreach (
array_merge($parents, array($name)) as $n
array_merge($parents, array($name)) as $current
) {
$breadcrumbs[] = $this->getLabel($n, $params);
$breadcrumbs[$current] = new Breadcrumb(
$this->getLabel($current, $params),
$this->getUrl($current, $params)
);
}
return $breadcrumbs;
} else {
return array(); // fail quickly if not found
}

return $breadcrumbs;
}

/**
Expand Down Expand Up @@ -146,6 +149,7 @@ function ($tag) {

/**
* Returns only parameters applicable for the named route/label
*
* @param string name
* @return array
*/
Expand Down
4 changes: 2 additions & 2 deletions Tests/Model/BreadcrumbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function testConstructor()
public function testGetters()
{
$bc = new Breadcrumb('foo', '/bar');
$this->assertEquals('foo', $bc->getLabel());
$this->assertEquals('/bar', $bc->getUrl());
$this->assertEquals('foo', $bc->label);
$this->assertEquals('/bar', $bc->url);
}


Expand Down
110 changes: 0 additions & 110 deletions Tests/Model/TrailTest.php

This file was deleted.

Loading

0 comments on commit 3cf685d

Please sign in to comment.