aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMetalaka <matthieu.de.laubrie@gmail.com>2015-01-26 14:35:26 +0100
committerMetalaka <matthieu.de.laubrie@gmail.com>2015-01-28 10:18:07 +0100
commit6c85ec68199a4ff3bdd888cba056159c5c1f8435 (patch)
tree2a51a472bd1433b3bcb7370ead59bced72c15061
parentdaa05007de3eb0661711024cddaeb432115a1f94 (diff)
downloadRouter-6c85ec68199a4ff3bdd888cba056159c5c1f8435.zip
Router-6c85ec68199a4ff3bdd888cba056159c5c1f8435.tar.gz
Router-6c85ec68199a4ff3bdd888cba056159c5c1f8435.tar.bz2
Remove from/import and update to PHP5.4.
-rw-r--r--Cli.php73
-rw-r--r--Exception/Exception.php14
-rw-r--r--Exception/NotFound.php14
-rw-r--r--Generic.php30
-rw-r--r--Http.php81
-rw-r--r--Router.php18
6 files changed, 69 insertions, 161 deletions
diff --git a/Cli.php b/Cli.php
index 94a5a64..09abb42 100644
--- a/Cli.php
+++ b/Cli.php
@@ -34,33 +34,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Router;
-from('Hoa')
-
-/**
- * \Hoa\Router\Exception
- */
--> import('Router.Exception.~')
-
-/**
- * \Hoa\Router\Exception\NotFound
- */
--> import('Router.Exception.NotFound')
-
-/**
- * \Hoa\Router
- */
--> import('Router.~')
-
-/**
- * \Hoa\Router\Generic
- */
--> import('Router.Generic');
-
-}
-
-namespace Hoa\Router {
+use Hoa\Core;
/**
* Class \Hoa\Router\Cli.
@@ -72,23 +48,23 @@ namespace Hoa\Router {
* @license New BSD License
*/
-class Cli extends Generic implements \Hoa\Core\Parameter\Parameterizable {
+class Cli extends Generic implements Core\Parameter\Parameterizable {
/**
* Parameters.
*
* @var \Hoa\Core\Parameter object
*/
- protected $_parameters = null;
+ protected $_parameters = null;
/**
* CLI methods that the router understand.
*
* @var \Hoa\Router\Http array
*/
- protected static $_methods = array(
+ protected static $_methods = [
'get'
- );
+ ];
@@ -98,15 +74,15 @@ class Cli extends Generic implements \Hoa\Core\Parameter\Parameterizable {
* @access public
* @return void
*/
- public function __construct ( Array $parameters = array() ) {
+ public function __construct ( Array $parameters = [] ) {
- $this->_parameters = new \Hoa\Core\Parameter(
+ $this->_parameters = new Core\Parameter(
$this,
- array(),
- array(
- 'rules.public' => array(),
- 'rules.private' => array()
- )
+ [],
+ [
+ 'rules.public' => [],
+ 'rules.private' => []
+ ]
);
$this->_parameters->setParameters($parameters);
@@ -116,7 +92,7 @@ class Cli extends Generic implements \Hoa\Core\Parameter\Parameterizable {
= $rule;
if(null === $variables)
- $variables = array();
+ $variables = [];
$this->addRule($id, $methods, $pattern, $call, $able, $variables);
}
@@ -127,7 +103,7 @@ class Cli extends Generic implements \Hoa\Core\Parameter\Parameterizable {
= $rule;
if(null === $variables)
- $variables = array();
+ $variables = [];
$this->addPrivateRule(
$id, $methods, $pattern, $call, $able, $variables
@@ -182,10 +158,9 @@ class Cli extends Generic implements \Hoa\Core\Parameter\Parameterizable {
? 'Method %s is'
: 'Methods %s are') .
' invalid for the rule %s (valid methods are: %s).',
- 1, array(implode(', ', $diff), $id,
- implode(', ', self::$_methods)));
+ 1, [implode(', ', $diff), $id, implode(', ', self::$_methods)]);
- $this->_rules[$id] = array(
+ $this->_rules[$id] = [
Router::RULE_VISIBILITY => $visibility,
Router::RULE_ID => $id,
Router::RULE_METHODS => $methods,
@@ -193,7 +168,7 @@ class Cli extends Generic implements \Hoa\Core\Parameter\Parameterizable {
Router::RULE_CALL => $call,
Router::RULE_ABLE => $able,
Router::RULE_VARIABLES => $variables
- );
+ ];
return $this;
}
@@ -281,7 +256,7 @@ class Cli extends Generic implements \Hoa\Core\Parameter\Parameterizable {
* @param array $variables Variables.
* @return string
*/
- public function unroute ( $id, Array $variables = array() ) {
+ public function unroute ( $id, Array $variables = [] ) {
$rule = $this->getRule($id);
$pattern = $rule[Router::RULE_PATTERN];
@@ -301,14 +276,14 @@ class Cli extends Generic implements \Hoa\Core\Parameter\Parameterizable {
);
return str_replace(
- array(
+ [
'\.', '\\\\', '\+', '\*', '\?', '\[', '\]', '\^', '\$', '\(',
'\)', '\{', '\}', '\=', '\!', '\<', '\>', '\|', '\:', '\-'
- ),
- array(
+ ],
+ [
'.', '\\', '+', '*', '?', '[', ']', '^', '$', '(',
')', '{', '}', '=', '!', '<', '>', '|', ':', '-'
- ),
+ ],
$out
);
}
@@ -382,5 +357,3 @@ class Cli extends Generic implements \Hoa\Core\Parameter\Parameterizable {
return ltrim($out);
}
}
-
-}
diff --git a/Exception/Exception.php b/Exception/Exception.php
index a377ef8..4f33147 100644
--- a/Exception/Exception.php
+++ b/Exception/Exception.php
@@ -34,7 +34,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace Hoa\Router\Exception {
+namespace Hoa\Router\Exception;
+
+use Hoa\Core;
/**
* Class \Hoa\Router\Exception.
@@ -46,15 +48,9 @@ namespace Hoa\Router\Exception {
* @license New BSD License
*/
-class Exception extends \Hoa\Core\Exception { }
-
-}
-
-namespace {
+class Exception extends Core\Exception { }
/**
* Flex entity.
*/
-Hoa\Core\Consistency::flexEntity('Hoa\Router\Exception\Exception');
-
-}
+Core\Consistency::flexEntity('Hoa\Router\Exception\Exception');
diff --git a/Exception/NotFound.php b/Exception/NotFound.php
index 5274976..25af9a8 100644
--- a/Exception/NotFound.php
+++ b/Exception/NotFound.php
@@ -34,18 +34,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-from('Hoa')
-
-/**
- * \Hoa\Router\Exception
- */
--> import('Router.Exception.~');
-
-}
-
-namespace Hoa\Router\Exception {
+namespace Hoa\Router\Exception;
/**
* Class \Hoa\Router\Exception\NotFound.
@@ -58,5 +48,3 @@ namespace Hoa\Router\Exception {
*/
class NotFound extends Exception { }
-
-}
diff --git a/Generic.php b/Generic.php
index ab1739f..29e6b3c 100644
--- a/Generic.php
+++ b/Generic.php
@@ -34,23 +34,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
-
-from('Hoa')
-
-/**
- * \Hoa\Router\Exception
- */
--> import('Router.Exception.~')
-
-/**
- * \Hoa\Router
- */
--> import('Router.~');
-
-}
-
-namespace Hoa\Router {
+namespace Hoa\Router;
/**
* Class \Hoa\Router\Generic.
@@ -69,7 +53,7 @@ abstract class Generic implements Router {
*
* @var \Hoa\Router\Generic array
*/
- protected $_rules = array();
+ protected $_rules = [];
/**
* The routed rule.
@@ -83,7 +67,7 @@ abstract class Generic implements Router {
*
* @var \Hoa\Router\Generic array
*/
- protected static $_methods = array();
+ protected static $_methods = [];
@@ -120,7 +104,7 @@ abstract class Generic implements Router {
* @throw \Hoa\Router\Exception
*/
public function addRule ( $id, Array $methods, $pattern, $call = null,
- $able = null, Array $variables = array() ) {
+ $able = null, Array $variables = [] ) {
return $this->_addRule(
Router::VISIBILITY_PUBLIC,
@@ -147,7 +131,7 @@ abstract class Generic implements Router {
* @throw \Hoa\Router\Exception
*/
public function addPrivateRule ( $id, Array $methods, $pattern, $call = null,
- $able = null, Array $variables = array() ) {
+ $able = null, Array $variables = [] ) {
return $this->_addRule(
Router::VISIBILITY_PRIVATE,
@@ -197,7 +181,7 @@ abstract class Generic implements Router {
$arguments[0] = $arguments[1];
$arguments[1] = $handle;
- return call_user_func_array(array($this, $method), $arguments);
+ return call_user_func_array([$this, $method], $arguments);
}
/**
@@ -265,5 +249,3 @@ abstract class Generic implements Router {
return $this->_rule;
}
}
-
-}
diff --git a/Http.php b/Http.php
index cde6f77..38d829b 100644
--- a/Http.php
+++ b/Http.php
@@ -34,33 +34,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace {
+namespace Hoa\Router;
-from('Hoa')
-
-/**
- * \Hoa\Router\Exception
- */
--> import('Router.Exception.~')
-
-/**
- * \Hoa\Router\Exception\NotFound
- */
--> import('Router.Exception.NotFound')
-
-/**
- * \Hoa\Router
- */
--> import('Router.~')
-
-/**
- * \Hoa\Router\Generic
- */
--> import('Router.Generic');
-
-}
-
-namespace Hoa\Router {
+use Hoa\Core;
/**
* Class \Hoa\Router\Http.
@@ -72,7 +48,7 @@ namespace Hoa\Router {
* @license New BSD License
*/
-class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
+class Http extends Generic implements Core\Parameter\Parameterizable {
/**
* Secure connection.
@@ -121,7 +97,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
*
* @var \Hoa\Router\Http array
*/
- protected static $_methods = array(
+ protected static $_methods = [
'get',
'post',
'put',
@@ -129,7 +105,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
'delete',
'head',
'options'
- );
+ ];
/**
* Subdomain stack: static or dynamic.
@@ -156,16 +132,16 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
* @access public
* @return void
*/
- public function __construct ( Array $parameters = array() ) {
+ public function __construct ( Array $parameters = [] ) {
- $this->_parameters = new \Hoa\Core\Parameter(
+ $this->_parameters = new Core\Parameter(
$this,
- array(),
- array(
+ [],
+ [
'prefix' => null,
- 'rules.public' => array(),
- 'rules.private' => array()
- )
+ 'rules.public' => [],
+ 'rules.private' => []
+ ]
);
$this->_parameters->setParameters($parameters);
@@ -182,7 +158,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
= $rule;
if(null === $variables)
- $variables = array();
+ $variables = [];
$this->addRule($id, $methods, $pattern, $call, $able, $variables);
}
@@ -193,7 +169,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
= $rule;
if(null === $variables)
- $variables = array();
+ $variables = [];
$this->addPrivateRule(
$id, $methods, $pattern, $call, $able, $variables
@@ -250,14 +226,13 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
? 'Method %s is'
: 'Methods %s are') .
' invalid for the rule %s (valid methods are: %s).',
- 1, array(implode(', ', $diff), $id,
- implode(', ', self::$_methods)));
+ 1, [implode(', ', $diff), $id, implode(', ', self::$_methods)]);
if( _static == $this->_subdomainStack
&& false != strpos($pattern, '@'))
$this->_subdomainStack = _dynamic;
- $this->_rules[$id] = array(
+ $this->_rules[$id] = [
Router::RULE_VISIBILITY => $visibility,
Router::RULE_ID => $id,
Router::RULE_METHODS => $methods,
@@ -265,7 +240,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
Router::RULE_CALL => $call,
Router::RULE_ABLE => $able,
Router::RULE_VARIABLES => $variables
- );
+ ];
return $this;
}
@@ -310,7 +285,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
if(0 === preg_match('#^' . $prefix . '(.*)?$#', $uri, $matches))
throw new Exception\NotFound(
'Cannot match the path prefix %s in the URI %s.',
- 3, array($prefix, $uri));
+ 3, [$prefix, $uri]);
$uri = ltrim($matches[1], '/');
}
@@ -392,7 +367,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
$msubdomain
);
else
- $msubdomain = array();
+ $msubdomain = [];
array_shift($muri);
$sub = array_shift($msubdomain) ?: null;
@@ -450,7 +425,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
* @return string
* @throw \Hoa\Router\Exception
*/
- public function unroute ( $id, Array $variables = array(),
+ public function unroute ( $id, Array $variables = [],
$secured = null, $prefix = null ) {
if(null === $prefix)
@@ -607,7 +582,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
throw new Exception(
'Variable %s is empty and it is not allowed when ' .
'unrouting rule %s.',
- 7, array($m, $id));
+ 7, [$m, $id]);
return $variables[$m];
},
@@ -628,14 +603,14 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
$out = preg_replace('#(.)(?<![\)\\\])[\?\*\+]#', '\1', $out);
return str_replace(
- array(
+ [
'\.', '\\\\', '\+', '\*', '\?', '\[', '\]', '\^', '\$', '\(',
'\)', '\{', '\}', '\=', '\!', '\<', '\>', '\|', '\:', '\-'
- ),
- array(
+ ],
+ [
'.', '\\', '+', '*', '?', '[', ']', '^', '$', '(',
')', '{', '}', '=', '!', '<', '>', '|', ':', '-'
- ),
+ ],
$out
);
}
@@ -701,7 +676,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
public static function getQuery ( ) {
if('cli' === php_sapi_name())
- return array();
+ return [];
if(!isset($_SERVER['REQUEST_URI']))
throw new Exception(
@@ -710,7 +685,7 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
$uri = $_SERVER['REQUEST_URI'];
if(false === $pos = strpos($uri, '?'))
- return array();
+ return [];
parse_str(substr($uri, $pos + 1), $out);
@@ -969,5 +944,3 @@ class Http extends Generic implements \Hoa\Core\Parameter\Parameterizable {
: static::UNSECURE;
}
}
-
-}
diff --git a/Router.php b/Router.php
index 5df970c..d92cedd 100644
--- a/Router.php
+++ b/Router.php
@@ -34,7 +34,9 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-namespace Hoa\Router {
+namespace Hoa\Router;
+
+use Hoa\Core;
/**
* Interface \Hoa\Router.
@@ -124,7 +126,7 @@ interface Router {
* @return \Hoa\Router
*/
public function addRule ( $id, Array $methods, $pattern, $call = null,
- $able = null, Array $variables = array() );
+ $able = null, Array $variables = [] );
/**
* Add a private rule.
@@ -139,7 +141,7 @@ interface Router {
* @return \Hoa\Router
*/
public function addPrivateRule ( $id, Array $methods, $pattern, $call = null,
- $able = null, Array $variables = array() );
+ $able = null, Array $variables = [] );
/**
* Remove a rule.
@@ -184,7 +186,7 @@ interface Router {
* @param array $variables Variables.
* @return string
*/
- public function unroute ( $id, Array $variables = array() );
+ public function unroute ( $id, Array $variables = [] );
/**
* Get method or mode where the router is called.
@@ -203,13 +205,7 @@ interface Router {
public function isAsynchronous ( );
}
-}
-
-namespace {
-
/**
* Flex entity.
*/
-Hoa\Core\Consistency::flexEntity('Hoa\Router\Router');
-
-}
+Core\Consistency::flexEntity('Hoa\Router\Router');