Skip to content

Commit 1e8d9ea

Browse files
committed
Updates some methods and code optimizations.
1 parent d37f581 commit 1e8d9ea

File tree

4 files changed

+47
-22
lines changed

4 files changed

+47
-22
lines changed

src/Router.php

+24-10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
namespace Buki;
1313

14+
use Closure;
1415
use ReflectionMethod;
1516
use Buki\Router\RouterRequest;
1617
use Buki\Router\RouterCommand;
@@ -19,22 +20,22 @@
1920
class Router
2021
{
2122
/**
22-
* @var $baseFolder Pattern definations for parameters of Route
23+
* @var string $baseFolder Pattern definations for parameters of Route
2324
*/
2425
protected $baseFolder;
2526

2627
/**
27-
* @var $routes Routes list
28+
* @var array $routes Routes list
2829
*/
2930
protected $routes = [];
3031

3132
/**
32-
* @var $groups List of group routes
33+
* @var array $groups List of group routes
3334
*/
3435
protected $groups = [];
3536

3637
/**
37-
* @var $patterns Pattern definations for parameters of Route
38+
* @var array $patterns Pattern definations for parameters of Route
3839
*/
3940
protected $patterns = [
4041
'{a}' => '([^/]+)',
@@ -47,33 +48,33 @@ class Router
4748
];
4849

4950
/**
50-
* @var $namespaces Namespaces of Controllers and Middlewares files
51+
* @var array $namespaces Namespaces of Controllers and Middlewares files
5152
*/
5253
protected $namespaces = [
5354
'middlewares' => '',
5455
'controllers' => ''
5556
];
5657

5758
/**
58-
* @var $path Paths of Controllers and Middlewares files
59+
* @var array $path Paths of Controllers and Middlewares files
5960
*/
6061
protected $paths = [
6162
'controllers' => 'Controllers',
6263
'middlewares' => 'Middlewares'
6364
];
6465

6566
/**
66-
* @var $mainMethod Main method for controller
67+
* @var string $mainMethod Main method for controller
6768
*/
6869
protected $mainMethod = 'main';
6970

7071
/**
71-
* @var $errorCallback Route error callback function
72+
* @var Closure $errorCallback Route error callback function
7273
*/
7374
protected $errorCallback;
7475

7576
/**
76-
* Router constructer method.
77+
* Router constructor method.
7778
*
7879
* @param array $params
7980
*
@@ -97,6 +98,8 @@ function __construct(array $params = [])
9798
/**
9899
* Set paths and namespaces for Controllers and Middlewares.
99100
*
101+
* @param array $params
102+
*
100103
* @return void
101104
*/
102105
protected function setPaths($params)
@@ -138,7 +141,11 @@ protected function setPaths($params)
138141
* Add route method;
139142
* Get, Post, Put, Delete, Patch, Any, Ajax...
140143
*
144+
* @param $method
145+
* @param $params
146+
*
141147
* @return void
148+
* @throws
142149
*/
143150
public function __call($method, $params)
144151
{
@@ -223,6 +230,7 @@ public function add($methods, $route, $settings, $callback = null)
223230
* @param null|string $attr
224231
*
225232
* @return void
233+
* @throws
226234
*/
227235
public function pattern($pattern, $attr = null)
228236
{
@@ -249,7 +257,7 @@ public function pattern($pattern, $attr = null)
249257
* Run Routes
250258
*
251259
* @return void
252-
* @throw Exception
260+
* @throws
253261
*/
254262
public function run()
255263
{
@@ -408,6 +416,7 @@ public function group($name, $settings = null, $callback = null)
408416
* @param null|string $controller
409417
*
410418
* @return void
419+
* @throws
411420
*/
412421
public function controller($route, $settings, $controller = null)
413422
{
@@ -457,6 +466,8 @@ public function controller($route, $settings, $controller = null)
457466
}
458467
unset($r);
459468
}
469+
470+
return;
460471
}
461472

462473
/**
@@ -528,6 +539,8 @@ private function addRoute($uri, $method, $callback, $settings)
528539
/**
529540
* Run Route Command; Controller or Closure
530541
*
542+
* @param $command
543+
* @param $params
531544
* @return null
532545
*/
533546
private function runRouteCommand($command, $params = null)
@@ -612,6 +625,7 @@ public function getRoutes()
612625
* @param $message
613626
*
614627
* @return RouterException
628+
* @throws
615629
*/
616630
public function exception($message = '')
617631
{

src/Router/RouterCommand.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@
1010

1111
namespace Buki\Router;
1212

13-
use Buki\Router\RouterException;
14-
1513
class RouterCommand
1614
{
1715
/**
18-
* @var Class instance variable
16+
* @var RouterCommand|null Class instance variable
1917
*/
2018
protected static $instance = null;
2119

2220
/**
2321
* Get class instance
2422
*
25-
* @return PdoxObject
23+
* @return RouterCommand
2624
*/
2725
public static function getInstance()
2826
{
@@ -36,7 +34,9 @@ public static function getInstance()
3634
* Throw new Exception for Router Error
3735
*
3836
* @param $message
37+
*
3938
* @return RouterException
39+
* @throws
4040
*/
4141
public function exception($message = '')
4242
{
@@ -50,7 +50,8 @@ public function exception($message = '')
5050
* @param $path
5151
* @param $namespace
5252
*
53-
* @return void
53+
* @return mixed|void
54+
* @throws
5455
*/
5556
public function beforeAfter($command, $path = '', $namespace = '')
5657
{
@@ -81,6 +82,7 @@ public function beforeAfter($command, $path = '', $namespace = '')
8182
* @param $namespace
8283
*
8384
* @return void
85+
* @throws
8486
*/
8587
public function runRoute($command, $params = null, $path = '', $namespace = '')
8688
{
@@ -117,6 +119,7 @@ public function runRoute($command, $params = null, $path = '', $namespace = '')
117119
* @param $namespace
118120
*
119121
* @return object
122+
* @throws
120123
*/
121124
protected function resolveClass($class, $path, $namespace)
122125
{

src/Router/RouterException.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
class RouterException
1616
{
1717
/**
18-
* @var $debug Debug mode
18+
* @var bool $debug Debug mode
1919
*/
2020
public static $debug = false;
2121

2222
/**
2323
* Create Exception Class.
2424
*
25+
* @param $message
26+
*
2527
* @return string
26-
* @throw Exception
28+
* @throws Exception
2729
*/
2830
public function __construct($message)
2931
{

src/Router/RouterRequest.php

+11-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
class RouterRequest
1414
{
1515
/**
16-
* @var $validMethods Valid methods for Requests
16+
* @var string $validMethods Valid methods for Requests
1717
*/
1818
public static $validMethods = 'GET|POST|PUT|DELETE|HEAD|OPTIONS|PATCH|ANY|AJAX|AJAXP';
1919

2020
/**
2121
* Request method validation
2222
*
23+
* @param string $data
24+
* @param string $method
25+
*
2326
* @return bool
2427
*/
2528
public static function validMethod($data, $method)
@@ -42,7 +45,10 @@ public static function validMethod($data, $method)
4245
/**
4346
* check method valid
4447
*
45-
* @return true|false
48+
* @param string $value
49+
* @param string $method
50+
*
51+
* @return bool
4652
*/
4753
protected static function checkMethods($value, $method)
4854
{
@@ -83,7 +89,7 @@ protected static function getRequestHeaders()
8389
// Method getallheaders() not available: manually extract 'm
8490
$headers = [];
8591
foreach ($_SERVER as $name => $value) {
86-
if ((substr($name, 0, 5) == 'HTTP_') || ($name === 'CONTENT_TYPE') || ($name === 'CONTENT_LENGTH')) {
92+
if (substr($name, 0, 5) == 'HTTP_' || $name === 'CONTENT_TYPE' || $name === 'CONTENT_LENGTH') {
8793
$headers[str_replace([' ', 'Http'], ['-', 'HTTP'], ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
8894
}
8995
}
@@ -102,10 +108,10 @@ public static function getRequestMethod()
102108
$method = $_SERVER['REQUEST_METHOD'];
103109
// If it's a HEAD request override it to being GET and prevent any output, as per HTTP Specification
104110
// @url http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4
105-
if ($method == 'HEAD') {
111+
if ($method === 'HEAD') {
106112
ob_start();
107113
$method = 'GET';
108-
} elseif ($method == 'POST') {
114+
} elseif ($method === 'POST') {
109115
$headers = self::getRequestHeaders();
110116
if (isset($headers['X-HTTP-Method-Override']) && in_array($headers['X-HTTP-Method-Override'], ['PUT', 'DELETE', 'PATCH', 'OPTIONS'])) {
111117
$method = $headers['X-HTTP-Method-Override'];

0 commit comments

Comments
 (0)