Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://git.zendframework.com/zf into mikaelkael
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkael committed Jun 21, 2010
2 parents b306c72 + a22d6e2 commit d18a7ab
Show file tree
Hide file tree
Showing 16 changed files with 635 additions and 420 deletions.
78 changes: 42 additions & 36 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
* @version $Id$
*/

/**
* @namespace
*/
namespace Zend\Navigation;
use Zend\Config;

/**
* Zend_Navigation_Container
*
Expand All @@ -27,14 +33,14 @@
* @uses Countable
* @uses RecursiveIterator
* @uses RecursiveIteratorIterator
* @uses Zend_Navigation_Exception
* @uses Zend_Navigation_Page
* @uses \Zend\Navigation\Exception
* @uses \Zend\Navigation\Page\Page
* @category Zend
* @package Zend_Navigation
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Navigation_Container implements RecursiveIterator, Countable
abstract class Container implements \RecursiveIterator, \Countable
{
/**
* Contains sub pages
Expand Down Expand Up @@ -104,22 +110,22 @@ public function notifyOrderUpdated()
* This method will inject the container as the given page's parent by
* calling {@link Zend_Navigation_Page::setParent()}.
*
* @param Zend_Navigation_Page|array|Zend_Config $page page to add
* @return Zend_Navigation_Container fluent interface,
* @param Zend_Navigation_Page|array|\Zend\Config\Config $page page to add
* @return \Zend\Navigation\Container fluent interface,
* returns self
* @throws Zend_Navigation_Exception if page is invalid
* @throws \Zend\Navigation\Exception if page is invalid
*/
public function addPage($page)
{
if ($page === $this) {
throw new Zend_Navigation_Exception(
throw new Exception(
'A page cannot have itself as a parent');
}

if (is_array($page) || $page instanceof Zend_Config) {
$page = Zend_Navigation_Page::factory($page);
} elseif (!$page instanceof Zend_Navigation_Page) {
throw new Zend_Navigation_Exception(
if (is_array($page) || $page instanceof Config\Config) {
$page = Page\Page::factory($page);
} elseif (!$page instanceof Page\Page) {
throw new Exception(
'Invalid argument: $page must be an instance of ' .
'Zend_Navigation_Page or Zend_Config, or an array');
}
Expand All @@ -145,18 +151,18 @@ public function addPage($page)
/**
* Adds several pages at once
*
* @param array|Zend_Config $pages pages to add
* @return Zend_Navigation_Container fluent interface, returns self
* @throws Zend_Navigation_Exception if $pages is not array or Zend_Config
* @param array|\Zend\Config\Config $pages pages to add
* @return \Zend\Navigation\Container fluent interface, returns self
* @throws Zend_Navigation_Exception if $pages is not array or \Zend\Config\Config
*/
public function addPages($pages)
{
if ($pages instanceof Zend_Config) {
if ($pages instanceof Config\Config) {
$pages = $pages->toArray();
}

if (!is_array($pages)) {
throw new Zend_Navigation_Exception(
throw new Exception(
'Invalid argument: $pages must be an array or an ' .
'instance of Zend_Config');
}
Expand All @@ -172,7 +178,7 @@ public function addPages($pages)
* Sets pages this container should have, removing existing pages
*
* @param array $pages pages to set
* @return Zend_Navigation_Container fluent interface, returns self
* @return \Zend\Navigation\Container fluent interface, returns self
*/
public function setPages(array $pages)
{
Expand All @@ -183,7 +189,7 @@ public function setPages(array $pages)
/**
* Returns pages in the container
*
* @return array array of Zend_Navigation_Page instances
* @return array array of \Zend\Navigation\Page\Page instances
*/
public function getPages()
{
Expand All @@ -193,14 +199,14 @@ public function getPages()
/**
* Removes the given page from the container
*
* @param Zend_Navigation_Page|int $page page to remove, either a page
* @param \Zend\Navigation\Page\Page|int $page page to remove, either a page
* instance or a specific page order
* @return bool whether the removal was
* successful
*/
public function removePage($page)
{
if ($page instanceof Zend_Navigation_Page) {
if ($page instanceof Page\Page) {
$hash = $page->hashCode();
} elseif (is_int($page)) {
$this->_sort();
Expand All @@ -224,7 +230,7 @@ public function removePage($page)
/**
* Removes all pages in container
*
* @return Zend_Navigation_Container fluent interface, returns self
* @return \Zend\Navigation\Container fluent interface, returns self
*/
public function removePages()
{
Expand All @@ -236,12 +242,12 @@ public function removePages()
/**
* Checks if the container has the given page
*
* @param Zend_Navigation_Page $page page to look for
* @param \Zend\Navigation\Page\Page $page page to look for
* @param bool $recursive [optional] whether to search
* recursively. Default is false.
* @return bool whether page is in container
*/
public function hasPage(Zend_Navigation_Page $page, $recursive = false)
public function hasPage(Page\Page $page, $recursive = false)
{
if (array_key_exists($page->hashCode(), $this->_index)) {
return true;
Expand Down Expand Up @@ -271,12 +277,12 @@ public function hasPages()
*
* @param string $property name of property to match against
* @param mixed $value value to match property against
* @return Zend_Navigation_Page|null matching page or null
* @return \Zend\Navigation\Page\Page|null matching page or null
*/
public function findOneBy($property, $value)
{
$iterator = new RecursiveIteratorIterator($this,
RecursiveIteratorIterator::SELF_FIRST);
$iterator = new \RecursiveIteratorIterator($this,
\RecursiveIteratorIterator::SELF_FIRST);

foreach ($iterator as $page) {
if ($page->get($property) == $value) {
Expand All @@ -293,15 +299,15 @@ public function findOneBy($property, $value)
*
* @param string $property name of property to match against
* @param mixed $value value to match property against
* @return array array containing only Zend_Navigation_Page
* @return array array containing only \Zend\Navigation\Page\Page
* instances
*/
public function findAllBy($property, $value)
{
$found = array();

$iterator = new RecursiveIteratorIterator($this,
RecursiveIteratorIterator::SELF_FIRST);
$iterator = new \RecursiveIteratorIterator($this,
\RecursiveIteratorIterator::SELF_FIRST);

foreach ($iterator as $page) {
if ($page->get($property) == $value) {
Expand All @@ -323,7 +329,7 @@ public function findAllBy($property, $value)
* matching pages are found. If false, null will
* be returned if no matching page is found.
* Default is false.
* @return Zend_Navigation_Page|null matching page or null
* @return \Zend\Navigation\Page\Page|null matching page or null
*/
public function findBy($property, $value, $all = false)
{
Expand All @@ -347,15 +353,15 @@ public function findBy($property, $value, $all = false)
*
* @param string $method method name
* @param array $arguments method arguments
* @throws Zend_Navigation_Exception if method does not exist
* @throws \Zend\Navigation\Exception if method does not exist
*/
public function __call($method, $arguments)
{
if (@preg_match('/(find(?:One|All)?By)(.+)/', $method, $match)) {
return $this->{$match[1]}($match[2], $arguments[0]);
}

throw new Zend_Navigation_Exception(sprintf(
throw new Exception(sprintf(
'Bad method call: Unknown method %s::%s',
get_class($this),
$method));
Expand Down Expand Up @@ -386,8 +392,8 @@ public function toArray()
*
* Implements RecursiveIterator interface.
*
* @return Zend_Navigation_Page current page or null
* @throws Zend_Navigation_Exception if the index is invalid
* @return \Zend\Navigation\Page\Page current page or null
* @throws \Zend\Navigation\Exception if the index is invalid
*/
public function current()
{
Expand All @@ -398,7 +404,7 @@ public function current()
if (isset($this->_pages[$hash])) {
return $this->_pages[$hash];
} else {
throw new Zend_Navigation_Exception(
throw new Exception(
'Corruption detected in container; ' .
'invalid key found in internal iterator');
}
Expand Down Expand Up @@ -473,7 +479,7 @@ public function hasChildren()
*
* Implements RecursiveIterator interface.
*
* @return Zend_Navigation_Page|null
* @return \Zend\Navigation\Page\Page|null
*/
public function getChildren()
{
Expand Down
9 changes: 7 additions & 2 deletions src/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,21 @@
* @version $Id$
*/

/**
* @namespace
*/
namespace Zend\Navigation;

/**
* Navigation exception
*
* @uses Zend_Exception
* @uses \Zend\Exception
* @category Zend
* @package Zend_Navigation
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Navigation_Exception extends Zend_Exception
class Exception extends \Zend\Exception
{

}
55 changes: 55 additions & 0 deletions src/Navigation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Navigation
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id$
*/

/**
* @namespace
*/
namespace Zend\Navigation;

/**
* A simple container class for {@link Zend_Navigation_Page} pages
*
* @uses \Zend\Navigation\Container
* @uses \Zend\Navigation\Exception
* @category Zend
* @package Zend_Navigation
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Navigation extends Container
{
/**
* Creates a new navigation container
*
* @param array|\Zend\Config\Config $pages [optional] pages to add
* @throws \Zend\Navigation\Exception if $pages is invalid
*/
public function __construct($pages = null)
{
if (is_array($pages) || $pages instanceof \Zend\Config\Config) {
$this->addPages($pages);
} elseif (null !== $pages) {
throw new Exception(
'Invalid argument: $pages must be an array, an ' .
'instance of Zend_Config, or null');
}
}
}
Loading

0 comments on commit d18a7ab

Please sign in to comment.