22
33/**
44 * Class Router
5- *
65 * Router class is the main class which developers must interactive with to
76 * dispatch all website routes.
87 *
98 * @package MiladRahimi\PHPRouter
10- *
119 * @author Milad Rahimi <[email protected] > 1210 */
1311class Router
@@ -92,15 +90,16 @@ class Router
9290 private $ response ;
9391
9492 /**
95- * @param string $base_uri
93+ * Constructor
9694 *
95+ * @param string $base_uri
9796 * @throw \InvalidArgumentException
9897 */
9998 public function __construct ($ base_uri = "" )
10099 {
101100 // Set Base URI
102101 if (!is_string ($ base_uri ))
103- throw new \ InvalidArgumentException (' Neatplex PHPRouter: $base_uri must be a string value' );
102+ throw new InvalidArgumentException (" Base URI must be a string value" );
104103 $ this ->base_uri = $ base_uri ;
105104 // New Request
106105 $ this ->request = Request::getInstance ($ this );
@@ -120,11 +119,14 @@ public function __toString()
120119 *
121120 * @param array|callable|string $options
122121 * @param callable $body
123- *
124122 * @throws PHPRouterError
125123 */
126124 public function group ($ options , $ body )
127125 {
126+ if (!isset ($ options ))
127+ throw new InvalidArgumentException ("Options must be set " );
128+ if (!isset ($ body ))
129+ throw new InvalidArgumentException ("Body must be set " );
128130 if (is_array ($ options )) {
129131 if (isset ($ options ["middleware " ]))
130132 if (!is_array ($ options ["middleware " ]))
@@ -235,7 +237,6 @@ private function checkBaseURI()
235237 * Convert route to regex pattern and extract the parameters
236238 *
237239 * @param string $route Route ro compile
238- *
239240 * @return string Pattern
240241 */
241242 private function convertToRegex ($ route )
@@ -247,9 +248,7 @@ private function convertToRegex($route)
247248 * Check whether the set domain is correct or not
248249 *
249250 * @param string $domain Set Domain
250- *
251251 * @return array arguments
252- *
253252 * @throws HttpError
254253 */
255254 private function checkDomain ($ domain )
@@ -267,7 +266,6 @@ private function checkDomain($domain)
267266 *
268267 * @param callable $function
269268 * @param array $arguments
270- *
271269 * @return array
272270 */
273271 private function arrangeFuncArgs ($ function , $ arguments )
@@ -293,7 +291,6 @@ function (\ReflectionParameter $param) use ($arguments) {
293291 * @param object $class
294292 * @param callable $method
295293 * @param array $arguments
296- *
297294 * @return array
298295 */
299296 private function arrangeMethodArgs ($ class , $ method , $ arguments )
@@ -344,11 +341,16 @@ public function get($routes = null, $controller = null, $middleware = null)
344341 * @param string|array $routes
345342 * @param string|callable $controller
346343 * @param callable|string|null $middleware
347- *
348344 * @throws PHPRouterError
349345 */
350346 public function map ($ methods , $ routes , $ controller , $ middleware = null )
351347 {
348+ if (!isset ($ methods ))
349+ throw new InvalidArgumentException ("Methods must be set " );
350+ if (!isset ($ routes ))
351+ throw new InvalidArgumentException ("Routes must be set " );
352+ if (!isset ($ controller ))
353+ throw new InvalidArgumentException ("Controllers must be set " );
352354 if (!is_array ($ methods ))
353355 $ methods = array ($ methods );
354356 if (!is_array ($ routes ))
@@ -377,7 +379,6 @@ public function map($methods, $routes, $controller, $middleware = null)
377379 * Escape undesired regex from the given content
378380 *
379381 * @param string $content
380- *
381382 * @return string
382383 */
383384 private function safeRegex ($ content )
@@ -416,15 +417,14 @@ public function post($routes = null, $controller = null, $middleware = null)
416417 *
417418 * @param string $parameter_name Desired parameter for changing it's regex pattern
418419 * @param string $regex Desired regex pattern for related parameter
419- *
420420 * @throw \InvalidArgumentException
421421 */
422422 public function define ($ parameter_name , $ regex )
423423 {
424- if (!is_string ($ parameter_name ))
425- throw new \InvalidArgumentException (' Neatplex PHPRouter: $parameter_name must be a string value' );
426- if (!is_string ($ regex ))
427- throw new \InvalidArgumentException (' Neatplex PHPRouter: $regex must be a string value' );
424+ if (!isset ( $ parameter_name ) || ! is_string ($ parameter_name ))
425+ throw new \InvalidArgumentException (" Parameter name must be a string value" );
426+ if (!isset ( $ regex ) || ! is_string ($ regex ))
427+ throw new \InvalidArgumentException (" Regex must be a string value" );
428428 $ this ->parameters [$ parameter_name ] = $ this ->safeRegex ($ regex );
429429 }
430430
@@ -440,7 +440,6 @@ public function getBaseURI()
440440 * Return the regex pattern of given parameter
441441 *
442442 * @param string $name Parameter Name
443- *
444443 * @return string Pattern
445444 */
446445 private function regexParameter ($ name )
0 commit comments