From 05ffe66adbf9856edea20914023377e10c8117c2 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Sun, 5 Oct 2014 11:17:56 +0200 Subject: [PATCH] Remove from/import and update to PHP5.4. --- Basic.php | 51 +++++++++++++++++-------------------------------- Dispatcher.php | 52 +++++++++++++++++--------------------------------- Exception.php | 8 ++++---- Kit.php | 13 +++++++------ 4 files changed, 46 insertions(+), 78 deletions(-) diff --git a/Basic.php b/Basic.php index 4ee6134..9f4d094 100644 --- a/Basic.php +++ b/Basic.php @@ -34,23 +34,10 @@ * POSSIBILITY OF SUCH DAMAGE. */ -namespace { +namespace Hoa\Dispatcher; -from('Hoa') - -/** - * \Hoa\Dispatcher\Exception - */ --> import('Dispatcher.Exception') - -/** - * \Hoa\Dispatcher - */ --> import('Dispatcher.~'); - -} - -namespace Hoa\Dispatcher { +use Hoa\Router; +use Hoa\View; /** * Class \Hoa\Dispatcher\Basic. @@ -75,23 +62,23 @@ class Basic extends Dispatcher { * @return mixed * @throw \Hoa\Dispatcher\Exception */ - protected function resolve ( Array $rule, \Hoa\Router $router, - \Hoa\View\Viewable $view = null ) { + protected function resolve ( Array $rule, Router $router, + View\Viewable $view = null ) { $called = null; - $variables = &$rule[\Hoa\Router::RULE_VARIABLES]; + $variables = &$rule[Router::RULE_VARIABLES]; $call = isset($variables['controller']) ? $variables['controller'] : (isset($variables['_call']) ? $variables['_call'] - : $rule[\Hoa\Router::RULE_CALL]); + : $rule[Router::RULE_CALL]); $able = isset($variables['action']) ? $variables['action'] : (isset($variables['_able']) ? $variables['_able'] - : $rule[\Hoa\Router::RULE_ABLE]); - $rtv = array($router, $this, $view); - $arguments = array(); + : $rule[Router::RULE_ABLE]); + $rtv = [$router, $this, $view]; + $arguments = []; $reflection = null; if($call instanceof \Closure) { @@ -128,7 +115,7 @@ protected function resolve ( Array $rule, \Hoa\Router $router, 'The closured action for the rule with pattern %s needs ' . 'a value for the parameter $%s and this value does not ' . 'exist.', - 1, array($rule[\Hoa\Router::RULE_PATTERN], $name)); + 1, [$rule[Router::RULE_PATTERN], $name]); } } elseif(is_string($call) && null === $able) { @@ -164,7 +151,7 @@ protected function resolve ( Array $rule, \Hoa\Router $router, 'The functional action for the rule with pattern %s needs ' . 'a value for the parameter $%s and this value does not ' . 'exist.', - 3, array($rule[\Hoa\Router::RULE_PATTERN], $name)); + 3, [$rule[Router::RULE_PATTERN], $name]); } } else { @@ -201,8 +188,8 @@ protected function resolve ( Array $rule, \Hoa\Router $router, throw new Exception( 'Controller %s is not found ' . '(method: %s, asynchronous: %s).', - 4, array($controller, strtoupper($router->getMethod()), - true === $async ? 'true': 'false'), $e); + 4, [$controller, strtoupper($router->getMethod()), + true === $async ? 'true': 'false'], $e); } $kitname = $this->getKitName(); @@ -218,9 +205,9 @@ protected function resolve ( Array $rule, \Hoa\Router $router, throw new Exception( 'Action %s does not exist on the controller %s ' . '(method: %s, asynchronous: %s).', - 5, array($action, get_class($controller), - strtoupper($router->getMethod()), - true === $async ? 'true': 'false')); + 5, [$action, get_class($controller), + strtoupper($router->getMethod()), + true === $async ? 'true': 'false']); $called = $controller; $reflection = new \ReflectionMethod($controller, $action); @@ -239,7 +226,7 @@ protected function resolve ( Array $rule, \Hoa\Router $router, throw new Exception( 'The action %s on the controller %s needs a value for ' . 'the parameter $%s and this value does not exist.', - 6, array($action, get_class($controller), $name)); + 6, [$action, get_class($controller), $name]); } } @@ -251,5 +238,3 @@ protected function resolve ( Array $rule, \Hoa\Router $router, return $return; } } - -} diff --git a/Dispatcher.php b/Dispatcher.php index 2ffb917..77f6ce6 100644 --- a/Dispatcher.php +++ b/Dispatcher.php @@ -34,23 +34,11 @@ * POSSIBILITY OF SUCH DAMAGE. */ -namespace { +namespace Hoa\Dispatcher; -from('Hoa') - -/** - * \Hoa\Dispatcher\Exception - */ --> import('Dispatcher.Exception') - -/** - * \Hoa\Router - */ --> import('Router.~'); - -} - -namespace Hoa\Dispatcher { +use Hoa\Core; +use Hoa\Router; +use Hoa\View; /** * Class \Hoa\Dispatcher. @@ -62,7 +50,7 @@ * @license New BSD License */ -abstract class Dispatcher implements \Hoa\Core\Parameter\Parameterizable { +abstract class Dispatcher implements Core\Parameter\Parameterizable { /** * Parameters. @@ -94,16 +82,16 @@ abstract class Dispatcher implements \Hoa\Core\Parameter\Parameterizable { * @param array $parameters Parameters. * @return void */ - public function __construct ( Array $parameters = array() ) { + public function __construct ( Array $parameters = [] ) { - $this->_parameters = new \Hoa\Core\Parameter( + $this->_parameters = new Core\Parameter( __CLASS__, - array( + [ 'controller' => 'main', 'action' => 'main', 'method' => null - ), - array( + ], + [ 'synchronous.controller' => 'Application\Controller\(:controller:U:)', 'synchronous.action' => '(:action:U:)Action', @@ -115,7 +103,7 @@ public function __construct ( Array $parameters = array() ) { * * 'variables.…' => … */ - ) + ] ); $this->_parameters->setParameters($parameters); @@ -142,8 +130,8 @@ public function getParameters ( ) { * @return mixed * @throw \Hoa\Controller\Exception */ - public function dispatch ( \Hoa\Router $router, - \Hoa\View\Viewable $view = null ) { + public function dispatch ( Router $router, + View\Viewable $view = null ) { $rule = $router->getTheRule(); @@ -161,7 +149,7 @@ public function dispatch ( \Hoa\Router $router, $parameters = $this->_parameters; $this->_parameters = clone $this->_parameters; - foreach($rule[\Hoa\Router::RULE_VARIABLES] as $key => $value) + foreach($rule[Router::RULE_VARIABLES] as $key => $value) $this->_parameters->setParameter('variables.' . $key, $value); $this->_parameters->setKeyword('method', $router->getMethod()); @@ -183,8 +171,8 @@ public function dispatch ( \Hoa\Router $router, * @return mixed * @throw \Hoa\Dispatcher\Exception */ - abstract protected function resolve ( Array $rule, \Hoa\Router $router, - \Hoa\View\Viewable $view = null ); + abstract protected function resolve ( Array $rule, Router $router, + View\Viewable $view = null ); /** * Set kit's name. @@ -214,13 +202,7 @@ public function getKitName ( ) { } } -} - -namespace { - /** * Flex entity. */ -Hoa\Core\Consistency::flexEntity('Hoa\Dispatcher\Dispatcher'); - -} +Core\Consistency::flexEntity('Hoa\Dispatcher\Dispatcher'); diff --git a/Exception.php b/Exception.php index 2f0f937..5aea101 100644 --- a/Exception.php +++ b/Exception.php @@ -34,7 +34,9 @@ * POSSIBILITY OF SUCH DAMAGE. */ -namespace Hoa\Dispatcher { +namespace Hoa\Dispatcher; + +use Hoa\Core; /** * Class \Hoa\Dispatcher\Exception. @@ -46,6 +48,4 @@ * @license New BSD License */ -class Exception extends \Hoa\Core\Exception { } - -} +class Exception extends Core\Exception { } diff --git a/Kit.php b/Kit.php index 5b68b76..81b47ce 100644 --- a/Kit.php +++ b/Kit.php @@ -34,7 +34,10 @@ * POSSIBILITY OF SUCH DAMAGE. */ -namespace Hoa\Dispatcher { +namespace Hoa\Dispatcher; + +use Hoa\Router; +use Hoa\View; /** * Class \Hoa\Dispatcher\Kit. @@ -87,9 +90,9 @@ class Kit { * @param \Hoa\View\Viewable $view The view. * @return void */ - public function __construct ( \Hoa\Router $router, - Dispatcher $dispatcher, - \Hoa\View\Viewable $view = null ) { + public function __construct ( Router $router, + Dispatcher $dispatcher, + View\Viewable $view = null ) { $this->router = $router; $this->dispatcher = $dispatcher; @@ -112,5 +115,3 @@ public function construct ( ) { return; } } - -}