--- a/web/lib/Zend/Navigation/Page/Mvc.php Thu Mar 21 17:31:31 2013 +0100
+++ b/web/lib/Zend/Navigation/Page/Mvc.php Thu Mar 21 19:50:53 2013 +0100
@@ -15,9 +15,9 @@
* @category Zend
* @package Zend_Navigation
* @subpackage Page
- * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id: Mvc.php 20096 2010-01-06 02:05:09Z bkarwin $
+ * @version $Id: Mvc.php 25213 2013-01-11 08:19:09Z frosch $
*/
/**
@@ -44,7 +44,7 @@
* @category Zend
* @package Zend_Navigation
* @subpackage Page
- * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @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 Zend_Navigation_Page_Mvc extends Zend_Navigation_Page
@@ -95,6 +95,29 @@
protected $_resetParams = true;
/**
+ * Whether href should be encoded when assembling URL
+ *
+ * @see getHref()
+ * @var bool
+ */
+ protected $_encodeUrl = true;
+
+ /**
+ * Whether this page should be considered active
+ *
+ * @var bool
+ */
+ protected $_active = null;
+
+ /**
+ * Scheme to use when assembling URL
+ *
+ * @see getHref()
+ * @var string
+ */
+ protected $_scheme;
+
+ /**
* Cached href
*
* The use of this variable minimizes execution time when getHref() is
@@ -113,6 +136,14 @@
*/
protected static $_urlHelper = null;
+ /**
+ * View helper for assembling URLs with schemes
+ *
+ * @see getHref()
+ * @var Zend_View_Helper_ServerUrl
+ */
+ protected static $_schemeHelper = null;
+
// Accessors:
/**
@@ -128,39 +159,57 @@
*/
public function isActive($recursive = false)
{
- if (!$this->_active) {
- $front = Zend_Controller_Front::getInstance();
- $reqParams = $front->getRequest()->getParams();
-
- if (!array_key_exists('module', $reqParams)) {
- $reqParams['module'] = $front->getDefaultModule();
+ if (null === $this->_active) {
+ $front = Zend_Controller_Front::getInstance();
+ $request = $front->getRequest();
+ $reqParams = array();
+ if ($request) {
+ $reqParams = $request->getParams();
+ if (!array_key_exists('module', $reqParams)) {
+ $reqParams['module'] = $front->getDefaultModule();
+ }
}
$myParams = $this->_params;
+ if ($this->_route) {
+ $route = $front->getRouter()->getRoute($this->_route);
+ if(method_exists($route, 'getDefaults')) {
+ $myParams = array_merge($route->getDefaults(), $myParams);
+ }
+ }
+
if (null !== $this->_module) {
$myParams['module'] = $this->_module;
- } else {
+ } elseif(!array_key_exists('module', $myParams)) {
$myParams['module'] = $front->getDefaultModule();
}
if (null !== $this->_controller) {
$myParams['controller'] = $this->_controller;
- } else {
+ } elseif(!array_key_exists('controller', $myParams)) {
$myParams['controller'] = $front->getDefaultControllerName();
}
if (null !== $this->_action) {
$myParams['action'] = $this->_action;
- } else {
+ } elseif(!array_key_exists('action', $myParams)) {
$myParams['action'] = $front->getDefaultAction();
}
+ foreach($myParams as $key => $value) {
+ if(null === $value) {
+ unset($myParams[$key]);
+ }
+ }
+
if (count(array_intersect_assoc($reqParams, $myParams)) ==
count($myParams)) {
$this->_active = true;
return true;
}
+
+ $this->_active = false;
}
return parent::isActive($recursive);
@@ -201,8 +250,26 @@
$url = self::$_urlHelper->url($params,
$this->getRoute(),
- $this->getResetParams());
+ $this->getResetParams(),
+ $this->getEncodeUrl());
+ // Use scheme?
+ $scheme = $this->getScheme();
+ if (null !== $scheme) {
+ if (null === self::$_schemeHelper) {
+ require_once 'Zend/View/Helper/ServerUrl.php';
+ self::$_schemeHelper = new Zend_View_Helper_ServerUrl();
+ }
+
+ $url = self::$_schemeHelper->setScheme($scheme)->serverUrl($url);
+ }
+
+ // Add the fragment identifier if it is set
+ $fragment = $this->getFragment();
+ if (null !== $fragment) {
+ $url .= '#' . $fragment;
+ }
+
return $this->_hrefCache = $url;
}
@@ -309,33 +376,109 @@
}
/**
- * Sets params to use when assembling URL
+ * Set multiple parameters (to use when assembling URL) at once
+ *
+ * URL options passed to the url action helper for assembling URLs.
+ * Overwrites any previously set parameters!
+ *
+ * @see getHref()
+ *
+ * @param array|null $params [optional] paramters as array
+ * ('name' => 'value'). Default is null
+ * which clears all params.
+ * @return Zend_Navigation_Page_Mvc fluent interface, returns self
+ */
+ public function setParams(array $params = null)
+ {
+ $this->clearParams();
+
+ if (is_array($params)) {
+ $this->addParams($params);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Set parameter (to use when assembling URL)
+ *
+ * URL option passed to the url action helper for assembling URLs.
*
* @see getHref()
*
- * @param array|null $params [optional] page params. Default is null
- * which sets no params.
- * @return Zend_Navigation_Page_Mvc fluent interface, returns self
+ * @param string $name parameter name
+ * @param mixed $value parameter value
+ * @return Zend_Navigation_Page_Mvc fluent interface, returns self
*/
- public function setParams(array $params = null)
+ public function setParam($name, $value)
{
- if (null === $params) {
- $this->_params = array();
- } else {
- // TODO: do this more intelligently?
- $this->_params = $params;
- }
+ $name = (string) $name;
+ $this->_params[$name] = $value;
$this->_hrefCache = null;
return $this;
}
/**
- * Returns params to use when assembling URL
+ * Add multiple parameters (to use when assembling URL) at once
+ *
+ * URL options passed to the url action helper for assembling URLs.
+ *
+ * @see getHref()
*
+ * @param array $params paramters as array ('name' => 'value')
+ * @return Zend_Navigation_Page_Mvc fluent interface, returns self
+ */
+ public function addParams(array $params)
+ {
+ foreach ($params as $name => $value) {
+ $this->setParam($name, $value);
+ }
+
+ return $this;
+ }
+
+ /**
+ * Remove parameter (to use when assembling URL)
+ *
* @see getHref()
*
- * @return array page params
+ * @param string $name
+ * @return bool
+ */
+ public function removeParam($name)
+ {
+ if (array_key_exists($name, $this->_params)) {
+ unset($this->_params[$name]);
+
+ $this->_hrefCache = null;
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Clear all parameters (to use when assembling URL)
+ *
+ * @see getHref()
+ *
+ * @return Zend_Navigation_Page_Mvc fluent interface, returns self
+ */
+ public function clearParams()
+ {
+ $this->_params = array();
+
+ $this->_hrefCache = null;
+ return $this;
+ }
+
+ /**
+ * Retrieve all parameters (to use when assembling URL)
+ *
+ * @see getHref()
+ *
+ * @return array parameters as array ('name' => 'value')
*/
public function getParams()
{
@@ -343,6 +486,25 @@
}
/**
+ * Retrieve a single parameter (to use when assembling URL)
+ *
+ * @see getHref()
+ *
+ * @param string $name parameter name
+ * @return mixed
+ */
+ public function getParam($name)
+ {
+ $name = (string) $name;
+
+ if (!array_key_exists($name, $this->_params)) {
+ return null;
+ }
+
+ return $this->_params[$name];
+ }
+
+ /**
* Sets route name to use when assembling URL
*
* @see getHref()
@@ -405,6 +567,68 @@
}
/**
+ * Sets whether href should be encoded when assembling URL
+ *
+ * @see getHref()
+ *
+ * @param bool $resetParams whether href should be encoded when
+ * assembling URL
+ * @return Zend_Navigation_Page_Mvc fluent interface, returns self
+ */
+ public function setEncodeUrl($encodeUrl)
+ {
+ $this->_encodeUrl = (bool) $encodeUrl;
+ $this->_hrefCache = null;
+
+ return $this;
+ }
+
+ /**
+ * Returns whether herf should be encoded when assembling URL
+ *
+ * @see getHref()
+ *
+ * @return bool whether herf should be encoded when assembling URL
+ */
+ public function getEncodeUrl()
+ {
+ return $this->_encodeUrl;
+ }
+
+ /**
+ * Sets scheme to use when assembling URL
+ *
+ * @see getHref()
+ *
+ * @param string|null $scheme scheme
+ * @return Zend_Navigation_Page_Mvc fluent interface, returns self
+ */
+ public function setScheme($scheme)
+ {
+ if (null !== $scheme && !is_string($scheme)) {
+ require_once 'Zend/Navigation/Exception.php';
+ throw new Zend_Navigation_Exception(
+ 'Invalid argument: $scheme must be a string or null'
+ );
+ }
+
+ $this->_scheme = $scheme;
+ return $this;
+ }
+
+ /**
+ * Returns scheme to use when assembling URL
+ *
+ * @see getHref()
+ *
+ * @return string|null scheme or null
+ */
+ public function getScheme()
+ {
+ return $this->_scheme;
+ }
+
+ /**
* Sets action helper for assembling URLs
*
* @see getHref()
@@ -417,6 +641,19 @@
self::$_urlHelper = $uh;
}
+ /**
+ * Sets view helper for assembling URLs with schemes
+ *
+ * @see getHref()
+ *
+ * @param Zend_View_Helper_ServerUrl $sh scheme helper
+ * @return void
+ */
+ public static function setSchemeHelper(Zend_View_Helper_ServerUrl $sh)
+ {
+ self::$_schemeHelper = $sh;
+ }
+
// Public methods:
/**
@@ -434,7 +671,10 @@
'module' => $this->getModule(),
'params' => $this->getParams(),
'route' => $this->getRoute(),
- 'reset_params' => $this->getResetParams()
- ));
+ 'reset_params' => $this->getResetParams(),
+ 'encodeUrl' => $this->getEncodeUrl(),
+ 'scheme' => $this->getScheme(),
+ )
+ );
}
}