109 lines
1.9 KiB
PHP
109 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Klasa dodająca obsługę "okruszków chleba"
|
|
*
|
|
* @package stNavigationPlugin
|
|
*/
|
|
class stNavigationBreadcrumbs implements \Iterator, \Countable
|
|
{
|
|
/**
|
|
* Instancja kontekstu aplikacji
|
|
*
|
|
* @var sfContext
|
|
*/
|
|
protected $content;
|
|
|
|
/**
|
|
* "Okruszki chleba"
|
|
*
|
|
* @var stNavigationBreadcrumbItem[]
|
|
*/
|
|
protected $breadcrumbs = array();
|
|
|
|
/**
|
|
* Singleton
|
|
*
|
|
* @var static
|
|
*/
|
|
protected static $instance = null;
|
|
|
|
public function __construct(sfContext $context)
|
|
{
|
|
$this->context = $context;
|
|
}
|
|
|
|
/**
|
|
* Zwraca singleton
|
|
*
|
|
* @return static
|
|
*/
|
|
public static function getInstance()
|
|
{
|
|
if (null === self::$instance)
|
|
{
|
|
self::$instance = new static(sfContext::getInstance());
|
|
}
|
|
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Dodaje nowy "okruszek chleba"
|
|
*
|
|
* @param string $title Tytuł
|
|
* @param string $url Adres url
|
|
* @return $this
|
|
*/
|
|
public function add($title, $url = null)
|
|
{
|
|
if (null !== $url)
|
|
{
|
|
$url = $this->context->getController()->genUrl($url);
|
|
}
|
|
|
|
$this->breadcrumbs[] = new stNavigationBreadcrumbItem($title, $url);
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Zwraca "okruszki chleba"
|
|
*
|
|
* @return stNavigationBreadcrumbItem[]
|
|
*/
|
|
public function getBreadcrumbs()
|
|
{
|
|
return $this->breadcrumbs;
|
|
}
|
|
|
|
public function current()
|
|
{
|
|
return current($this->breadcrumbs);
|
|
}
|
|
|
|
public function next()
|
|
{
|
|
return next($this->breadcrumbs);
|
|
}
|
|
|
|
public function key()
|
|
{
|
|
return key($this->breadcrumbs);
|
|
}
|
|
|
|
public function valid()
|
|
{
|
|
return null !== $this->key();
|
|
}
|
|
|
|
public function rewind()
|
|
{
|
|
return reset($this->breadcrumbs);
|
|
}
|
|
|
|
public function count()
|
|
{
|
|
return count($this->breadcrumbs);
|
|
}
|
|
}
|