Skip to content

Commit

Permalink
CS fixes in Zend_Controller_Router
Browse files Browse the repository at this point in the history
  • Loading branch information
froschdesign authored and Dimitris Giotas committed Jun 17, 2016
1 parent 829886d commit ecda52d
Show file tree
Hide file tree
Showing 12 changed files with 231 additions and 141 deletions.
14 changes: 9 additions & 5 deletions library/Zend/Controller/Router/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* @version $Id$
*/


/** Zend_Controller_Router_Interface */
require_once 'Zend/Controller/Router/Interface.php';

Expand All @@ -40,16 +39,18 @@ abstract class Zend_Controller_Router_Abstract implements Zend_Controller_Router
* URI delimiter
*/
const URI_DELIMITER = '/';

/**
* Front controller instance
*
* @var Zend_Controller_Front
*/
protected $_frontController;

/**
* Array of invocation parameters to use when instantiating action
* controllers
*
* @var array
*/
protected $_invokeParams = array();
Expand All @@ -73,8 +74,9 @@ public function __construct(array $params = array())
*/
public function setParam($name, $value)
{
$name = (string) $name;
$name = (string)$name;
$this->_invokeParams[$name] = $value;

return $this;
}

Expand All @@ -87,6 +89,7 @@ public function setParam($name, $value)
public function setParams(array $params)
{
$this->_invokeParams = array_merge($this->_invokeParams, $params);

return $this;
}

Expand All @@ -98,7 +101,7 @@ public function setParams(array $params)
*/
public function getParam($name)
{
if(isset($this->_invokeParams[$name])) {
if (isset($this->_invokeParams[$name])) {
return $this->_invokeParams[$name];
}

Expand Down Expand Up @@ -156,6 +159,7 @@ public function getFrontController()

require_once 'Zend/Controller/Front.php';
$this->_frontController = Zend_Controller_Front::getInstance();

return $this->_frontController;
}

Expand All @@ -168,7 +172,7 @@ public function getFrontController()
public function setFrontController(Zend_Controller_Front $controller)
{
$this->_frontController = $controller;

return $this;
}

}
5 changes: 2 additions & 3 deletions library/Zend/Controller/Router/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/


/** Zend_Controller_Exception */
require_once 'Zend/Controller/Exception.php';


/**
* @package Zend_Controller
* @subpackage Router
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Controller_Router_Exception extends Zend_Controller_Exception
{}
{
}

9 changes: 4 additions & 5 deletions library/Zend/Controller/Router/Interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function route(Zend_Controller_Request_Abstract $dispatcher);
* Encode tells to url encode resulting path parts.
*
* @param array $userParams Options passed by a user used to override parameters
* @param mixed $name The name of a Route to use
* @param bool $reset Whether to reset to the route defaults ignoring URL params
* @param bool $encode Tells to encode URL parts on output
* @param mixed $name The name of a Route to use
* @param bool $reset Whether to reset to the route defaults ignoring URL params
* @param bool $encode Tells to encode URL parts on output
* @throws Zend_Controller_Router_Exception
* @return string Resulting URL path
*/
Expand All @@ -81,7 +81,7 @@ public function setFrontController(Zend_Controller_Front $controller);
* Add or modify a parameter with which to instantiate any helper objects
*
* @param string $name
* @param mixed $value
* @param mixed $value
* @return Zend_Controller_Router_Interface
*/
public function setParam($name, $value);
Expand Down Expand Up @@ -120,5 +120,4 @@ public function getParams();
* @return Zend_Controller_Router_Interface
*/
public function clearParams($name = null);

}
71 changes: 42 additions & 29 deletions library/Zend/Controller/Router/Rewrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function addDefaultRoutes()
{
if (!$this->hasRoute('default')) {
$dispatcher = $this->getFrontController()->getDispatcher();
$request = $this->getFrontController()->getRequest();
$request = $this->getFrontController()->getRequest();

require_once 'Zend/Controller/Router/Route/Module.php';
$compat = new Zend_Controller_Router_Route_Module(array(), $dispatcher, $request);
Expand All @@ -106,8 +106,8 @@ public function addDefaultRoutes()
*
* If route contains method setRequest(), it is initialized with a request object
*
* @param string $name Name of the route
* @param Zend_Controller_Router_Route_Interface $route Instance of the route
* @param string $name Name of the route
* @param Zend_Controller_Router_Route_Interface $route Instance of the route
* @return Zend_Controller_Router_Rewrite
*/
public function addRoute($name, Zend_Controller_Router_Route_Interface $route)
Expand All @@ -127,7 +127,8 @@ public function addRoute($name, Zend_Controller_Router_Route_Interface $route)
* @param array $routes Array of routes with names as keys and routes as values
* @return Zend_Controller_Router_Rewrite
*/
public function addRoutes($routes) {
public function addRoutes($routes)
{
foreach ($routes as $name => $route) {
$this->addRoute($name, $route);
}
Expand Down Expand Up @@ -215,7 +216,12 @@ protected function _getRouteFromConfig(Zend_Config $info)
Zend_Loader::loadClass($class);
}

$route = call_user_func(array($class, 'getInstance'), $info);
$route = call_user_func(
array(
$class,
'getInstance'
), $info
);

if (isset($info->abstract) && $info->abstract && method_exists($route, 'isAbstract')) {
$route->isAbstract(true);
Expand All @@ -232,9 +238,11 @@ protected function _getRouteFromConfig(Zend_Config $info)
* @param Zend_Config $childRoutesInfo
* @return void
*/
protected function _addChainRoutesFromConfig($name,
Zend_Controller_Router_Route_Interface $route,
Zend_Config $childRoutesInfo)
protected function _addChainRoutesFromConfig(
$name,
Zend_Controller_Router_Route_Interface $route,
Zend_Config $childRoutesInfo
)
{
foreach ($childRoutesInfo as $childRouteName => $childRouteInfo) {
if (is_string($childRouteInfo)) {
Expand Down Expand Up @@ -332,6 +340,7 @@ public function getCurrentRoute()
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception("Current route is not defined");
}

return $this->getRoute($this->_currentRoute);
}

Expand All @@ -347,6 +356,7 @@ public function getCurrentRouteName()
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception("Current route is not defined");
}

return $this->_currentRoute;
}

Expand All @@ -372,7 +382,9 @@ public function route(Zend_Controller_Request_Abstract $request)
{
if (!$request instanceof Zend_Controller_Request_Http) {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception('Zend_Controller_Router_Rewrite requires a Zend_Controller_Request_Http-based request object');
throw new Zend_Controller_Router_Exception(
'Zend_Controller_Router_Rewrite requires a Zend_Controller_Request_Http-based request object'
);
}

if ($this->_useDefaultRoutes) {
Expand Down Expand Up @@ -403,20 +415,19 @@ public function route(Zend_Controller_Request_Abstract $request)
}
}

if (!$routeMatched) {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception('No route matched the request', 404);
}
if (!$routeMatched) {
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception('No route matched the request', 404);
}

if($this->_useCurrentParamsAsGlobal) {
if ($this->_useCurrentParamsAsGlobal) {
$params = $request->getParams();
foreach($params as $param => $value) {
foreach ($params as $param => $value) {
$this->setGlobalParam($param, $value);
}
}

return $request;

}

/**
Expand All @@ -442,17 +453,16 @@ protected function _setRequestParams($request, $params)
if ($param === $request->getActionKey()) {
$request->setActionName($value);
}

}
}

/**
* Generates a URL path that can be used in URL creation, redirection, etc.
*
* @param array $userParams Options passed by a user used to override parameters
* @param mixed $name The name of a Route to use
* @param bool $reset Whether to reset to the route defaults ignoring URL params
* @param bool $encode Tells to encode URL parts on output
* @param mixed $name The name of a Route to use
* @param bool $reset Whether to reset to the route defaults ignoring URL params
* @param bool $encode Tells to encode URL parts on output
* @throws Zend_Controller_Router_Exception
* @return string Resulting absolute URL path
*/
Expand All @@ -462,7 +472,7 @@ public function assemble($userParams, $name = null, $reset = false, $encode = tr
require_once 'Zend/Controller/Router/Exception.php';
throw new Zend_Controller_Router_Exception('userParams must be an array');
}

if ($name == null) {
try {
$name = $this->getCurrentRouteName();
Expand All @@ -488,7 +498,7 @@ public function assemble($userParams, $name = null, $reset = false, $encode = tr
* Set a global parameter
*
* @param string $name
* @param mixed $value
* @param mixed $value
* @return Zend_Controller_Router_Rewrite
*/
public function setGlobalParam($name, $value)
Expand All @@ -504,7 +514,8 @@ public function setGlobalParam($name, $value)
* @param string $separator The separator to use
* @return Zend_Controller_Router_Rewrite
*/
public function setChainNameSeparator($separator) {
public function setChainNameSeparator($separator)
{
$this->_chainNameSeparator = $separator;

return $this;
Expand All @@ -515,27 +526,29 @@ public function setChainNameSeparator($separator) {
*
* @return string
*/
public function getChainNameSeparator() {
public function getChainNameSeparator()
{
return $this->_chainNameSeparator;
}

/**
* Determines/returns whether to use the request parameters as global parameters.
*
* @param boolean|null $use
* Null/unset when you want to retrieve the current state.
* True when request parameters should be global, false otherwise
* Null/unset when you want to retrieve the current state.
* True when request parameters should be global, false otherwise
* @return boolean|Zend_Controller_Router_Rewrite
* Returns a boolean if first param isn't set, returns an
* instance of Zend_Controller_Router_Rewrite otherwise.
*
*/
public function useRequestParametersAsGlobal($use = null) {
if($use === null) {
public function useRequestParametersAsGlobal($use = null)
{
if ($use === null) {
return $this->_useCurrentParamsAsGlobal;
}

$this->_useCurrentParamsAsGlobal = (bool) $use;
$this->_useCurrentParamsAsGlobal = (bool)$use;

return $this;
}
Expand Down
Loading

0 comments on commit ecda52d

Please sign in to comment.