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

Commit

Permalink
Merge remote-tracking branch 'SpiffyJr/pr/navigation-hotfixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 3 deletions.
57 changes: 54 additions & 3 deletions src/Service/AbstractNavigationFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Navigation
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Navigation\Service;

Expand All @@ -11,21 +30,42 @@
use Zend\ServiceManager\ServiceLocatorInterface;
use Zend\View\Helper\Url as UrlHelper;

/**
* Abstract navigation factory
*
* @category Zend
* @package Zend_Navigation
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class AbstractNavigationFactory implements FactoryInterface
{
/**
* @var array
*/
protected $pages;

/**
* @param ServiceLocatorInterface $serviceLocator
* @return \Zend\Navigation\Navigation
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$pages = $this->getPages($serviceLocator);
return new Navigation($pages);
}

/**
* @abstract
* @return string
*/
abstract protected function getName();

/**
* @param ServiceLocatorInterface $serviceLocator
* @return array
* @throws \Zend\Navigation\Exception\InvalidArgumentException
*/
protected function getPages(ServiceLocatorInterface $serviceLocator)
{
if (null === $this->pages) {
Expand All @@ -51,6 +91,11 @@ protected function getPages(ServiceLocatorInterface $serviceLocator)
return $this->pages;
}

/**
* @param string|\Zend\Config\Config|array $config
* @return array|null|\Zend\Config\Config
* @throws \Zend\Navigation\Exception\InvalidArgumentException
*/
protected function getPagesFromConfig($config = null)
{
if (is_string($config)) {
Expand All @@ -73,15 +118,21 @@ protected function getPagesFromConfig($config = null)
return $config;
}

protected function injectComponents($pages, RouteMatch $routeMatch, UrlHelper $urlHelper)
/**
* @param array $pages
* @param RouteMatch $routeMatch
* @param UrlHelper $urlHelper
* @return mixed
*/
protected function injectComponents(array $pages, RouteMatch $routeMatch = null, UrlHelper $urlHelper = null)
{
foreach($pages as &$page) {
$hasMvc = isset($page['action']) || isset($page['controller']) || isset($page['route']);
if ($hasMvc) {
if (!isset($page['routeMatch'])) {
if (!isset($page['routeMatch']) && $routeMatch) {
$page['routeMatch'] = $routeMatch;
}
if (!isset($page['urlHelper'])) {
if (!isset($page['urlHelper']) && $urlHelper) {
$page['urlHelper'] = $urlHelper;
}
}
Expand Down
37 changes: 37 additions & 0 deletions src/Service/ConstructedNavigationFactory.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Navigation
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Navigation\Service;

use Zend\ServiceManager\ServiceLocatorInterface;

/**
* Constructed factory to set pages during construction.
*
* @category Zend
* @package Zend_Navigation
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class ConstructedNavigationFactory extends AbstractNavigationFactory
{
/**
* @param string|\Zend\Config\Config|array $config
*/
public function __construct($config)
{
$this->pages = $this->getPagesFromConfig($config);
}

/**
* @param ServiceLocatorInterface $serviceLocator
* @return array|null|\Zend\Config\Config
*/
public function getPages(ServiceLocatorInterface $serviceLocator)
{
return $this->pages;
}

/**
* @return string
*/
public function getName()
{
return 'constructed';
Expand Down
30 changes: 30 additions & 0 deletions src/Service/DefaultNavigationFactory.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Navigation
* @subpackage Exception
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Navigation\Service;

/**
* Default navigation factory.
*
* @category Zend
* @package Zend_Navigation
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class DefaultNavigationFactory extends AbstractNavigationFactory
{
/**
* @return string
*/
protected function getName()
{
return 'default';
Expand Down
57 changes: 57 additions & 0 deletions src/View/HelperConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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 license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Navigation
* @subpackage View
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Navigation\View;

use Zend\ServiceManager\ConfigurationInterface;
use Zend\ServiceManager\ServiceManager;

/**
* Service manager configuration for navigation view helpers
*
* @category Zend
* @package Zend_Navigation
* @subpackage View
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class HelperConfiguration implements ConfigurationInterface
{
/**
* Configure the provided service manager instance with the configuration
* in this class.
*
* In addition to using each of the internal properties to configure the
* service manager, also adds an initializer to inject ServiceManagerAware
* classes with the service manager.
*
* @param ServiceManager $serviceManager
* @return void
*/
public function configureServiceManager(ServiceManager $serviceManager)
{
$serviceManager->setFactory('navigation', function($sm) {
$helper = new \Zend\View\Helper\Navigation;
$helper->setServiceLocator($sm);
return $helper;
});
}
}

0 comments on commit b9f38cc

Please sign in to comment.