@@ -245,7 +245,7 @@ public function setConfig(array $config)
245245 */
246246 public function __call ($ method , array $ args )
247247 {
248- if (\in_array (strtoupper ($ method ), self ::ALLOWED_METHODS , true )) {
248+ if (\in_array (\ strtoupper ($ method ), self ::ALLOWED_METHODS , true )) {
249249 if (\count ($ args ) < 2 ) {
250250 throw new \InvalidArgumentException ("The method [ $ method] parameters is missing. " );
251251 }
@@ -275,7 +275,7 @@ public function __call($method, array $args)
275275 */
276276 public function rest (string $ prefix , string $ controllerClass , array $ map = [], array $ opts = []): AbstractRouter
277277 {
278- $ map = array_merge ([
278+ $ map = \ array_merge ([
279279 'index ' => ['GET ' ],
280280 'create ' => ['POST ' ],
281281 'view ' => ['GET ' , '{id} ' , ['id ' => '[1-9]\d* ' ]],
@@ -388,10 +388,10 @@ public function validateArguments($methods, $handler): array
388388 $ allow = self ::ALLOWED_METHODS_STR . ', ' ;
389389 $ hasAny = false ;
390390
391- $ methods = array_map (function ($ m ) use ($ allow , &$ hasAny ) {
392- $ m = strtoupper (trim ($ m ));
391+ $ methods = \ array_map (function ($ m ) use ($ allow , &$ hasAny ) {
392+ $ m = \ strtoupper (trim ($ m ));
393393
394- if (!$ m || false === strpos ($ allow , $ m . ', ' )) {
394+ if (!$ m || false === \ strpos ($ allow , $ m . ', ' )) {
395395 throw new \InvalidArgumentException ("The method [ $ m] is not supported, Allow: " . trim ($ allow , ', ' ));
396396 }
397397
@@ -412,7 +412,7 @@ public function validateArguments($methods, $handler): array
412412 */
413413 public static function isStaticRoute (string $ route ): bool
414414 {
415- return strpos ($ route , '{ ' ) === false && strpos ($ route , '[ ' ) === false ;
415+ return \ strpos ($ route , '{ ' ) === false && \ strpos ($ route , '[ ' ) === false ;
416416 }
417417
418418 /**
@@ -423,16 +423,16 @@ public static function isStaticRoute(string $route): bool
423423 protected function formatUriPath (string $ path , $ ignoreLastSlash ): string
424424 {
425425 // clear '//', '///' => '/'
426- if (false !== strpos ($ path , '// ' )) {
427- $ path = (string )preg_replace ('#\/\/+# ' , '/ ' , $ path );
426+ if (false !== \ strpos ($ path , '// ' )) {
427+ $ path = (string )\ preg_replace ('#\/\/+# ' , '/ ' , $ path );
428428 }
429429
430430 // decode
431- $ path = rawurldecode ($ path );
431+ $ path = \ rawurldecode ($ path );
432432
433433 // setting 'ignoreLastSlash'
434434 if ($ path !== '/ ' && $ ignoreLastSlash ) {
435- $ path = rtrim ($ path , '/ ' );
435+ $ path = \ rtrim ($ path , '/ ' );
436436 }
437437
438438 return $ path ;
@@ -450,11 +450,11 @@ protected function filterMatches(array $matches, array &$conf)
450450 }
451451
452452 // clear all int key
453- $ matches = array_filter ($ matches , '\is_string ' , ARRAY_FILTER_USE_KEY );
453+ $ matches = \ array_filter ($ matches , '\is_string ' , ARRAY_FILTER_USE_KEY );
454454
455455 // apply some default param value
456456 if (isset ($ conf ['option ' ]['defaults ' ])) {
457- $ conf ['matches ' ] = array_merge ($ conf ['option ' ]['defaults ' ], $ matches );
457+ $ conf ['matches ' ] = \ array_merge ($ conf ['option ' ]['defaults ' ], $ matches );
458458 } else {
459459 $ conf ['matches ' ] = $ matches ;
460460 }
@@ -474,28 +474,28 @@ public function parseParamRoute(string $route, array $params, array $conf): arra
474474 $ noOptional = null ;
475475
476476 // 解析可选参数位
477- if (false !== ($ pos = strpos ($ route , '[ ' ))) {
477+ if (false !== ($ pos = \ strpos ($ route , '[ ' ))) {
478478 // $hasOptional = true;
479- $ noOptional = substr ($ route , 0 , $ pos );
480- $ withoutClosingOptionals = rtrim ($ route , '] ' );
479+ $ noOptional = \ substr ($ route , 0 , $ pos );
480+ $ withoutClosingOptionals = \ rtrim ($ route , '] ' );
481481 $ optionalNum = \strlen ($ route ) - \strlen ($ withoutClosingOptionals );
482482
483- if ($ optionalNum !== substr_count ($ withoutClosingOptionals , '[ ' )) {
483+ if ($ optionalNum !== \ substr_count ($ withoutClosingOptionals , '[ ' )) {
484484 throw new \LogicException ('Optional segments can only occur at the end of a route ' );
485485 }
486486
487487 // '/hello[/{name}]' -> '/hello(?:/{name})?'
488- $ route = str_replace (['[ ' , '] ' ], ['(?: ' , ')? ' ], $ route );
488+ $ route = \ str_replace (['[ ' , '] ' ], ['(?: ' , ')? ' ], $ route );
489489 }
490490
491491 // quote '.','/' to '\.','\/'
492- if (false !== strpos ($ route , '. ' )) {
492+ if (false !== \ strpos ($ route , '. ' )) {
493493 // $route = preg_quote($route, '/');
494- $ route = str_replace ('. ' , '\. ' , $ route );
494+ $ route = \ str_replace ('. ' , '\. ' , $ route );
495495 }
496496
497497 // 解析参数,替换为对应的 正则
498- if (preg_match_all ('#\{([a-zA-Z_][a-zA-Z0-9_-]*)\}# ' , $ route , $ m )) {
498+ if (\ preg_match_all ('#\{([a-zA-Z_][a-zA-Z0-9_-]*)\}# ' , $ route , $ m )) {
499499 /** @var array[] $m */
500500 $ replacePairs = [];
501501
@@ -508,7 +508,7 @@ public function parseParamRoute(string $route, array $params, array $conf): arra
508508 // $replacePairs[$key] = '(' . $regex . ')';
509509 }
510510
511- $ route = strtr ($ route , $ replacePairs );
511+ $ route = \ strtr ($ route , $ replacePairs );
512512 }
513513
514514 // 分析路由字符串是否是有规律的
@@ -517,7 +517,7 @@ public function parseParamRoute(string $route, array $params, array $conf): arra
517517
518518 // first node is a normal string
519519 // e.g '/user/{id}' first: 'user', '/a/{post}' first: 'a'
520- if (preg_match ('#^/([\w-]+)/[\w-]*/?# ' , $ bak , $ m )) {
520+ if (\ preg_match ('#^/([\w-]+)/[\w-]*/?# ' , $ bak , $ m )) {
521521 $ first = $ m [1 ];
522522 $ conf ['start ' ] = $ m [0 ];
523523
@@ -528,14 +528,14 @@ public function parseParamRoute(string $route, array $params, array $conf): arra
528528 $ include = null ;
529529
530530 if ($ noOptional ) {
531- if (strpos ($ noOptional , '{ ' ) === false ) {
531+ if (\ strpos ($ noOptional , '{ ' ) === false ) {
532532 $ include = $ noOptional ;
533533 } else {
534534 $ bak = $ noOptional ;
535535 }
536536 }
537537
538- if (!$ include && preg_match ('#/([\w-]+)/?[\w-]*# ' , $ bak , $ m )) {
538+ if (!$ include && \ preg_match ('#/([\w-]+)/?[\w-]*# ' , $ bak , $ m )) {
539539 $ include = $ m [0 ];
540540 }
541541
@@ -569,39 +569,39 @@ abstract protected function findInVagueRoutes(array $routesData, string $path, s
569569 */
570570 public function matchAutoRoute (string $ path )
571571 {
572- if (!$ cnp = trim ($ this ->controllerNamespace )) {
572+ if (!$ cnp = \ trim ($ this ->controllerNamespace )) {
573573 return false ;
574574 }
575575
576- $ sfx = trim ($ this ->controllerSuffix );
577- $ tmp = trim ($ path , '/- ' );
576+ $ sfx = \ trim ($ this ->controllerSuffix );
577+ $ tmp = \ trim ($ path , '/- ' );
578578
579579 // one node. eg: 'home'
580- if (!strpos ($ tmp , '/ ' )) {
580+ if (!\ strpos ($ tmp , '/ ' )) {
581581 $ tmp = self ::convertNodeStr ($ tmp );
582- $ class = "$ cnp \\" . ucfirst ($ tmp ) . $ sfx ;
582+ $ class = "$ cnp \\" . \ ucfirst ($ tmp ) . $ sfx ;
583583
584- return class_exists ($ class ) ? $ class : false ;
584+ return \ class_exists ($ class ) ? $ class : false ;
585585 }
586586
587- $ ary = array_map ([self ::class, 'convertNodeStr ' ], explode ('/ ' , $ tmp ));
587+ $ ary = \ array_map ([self ::class, 'convertNodeStr ' ], \ explode ('/ ' , $ tmp ));
588588 $ cnt = \count ($ ary );
589589
590590 // two nodes. eg: 'home/test' 'admin/user'
591591 if ($ cnt === 2 ) {
592592 list ($ n1 , $ n2 ) = $ ary ;
593593
594594 // last node is an controller class name. eg: 'admin/user'
595- $ class = "$ cnp \\$ n1 \\" . ucfirst ($ n2 ) . $ sfx ;
595+ $ class = "$ cnp \\$ n1 \\" . \ ucfirst ($ n2 ) . $ sfx ;
596596
597- if (class_exists ($ class )) {
597+ if (\ class_exists ($ class )) {
598598 return $ class ;
599599 }
600600
601601 // first node is an controller class name, second node is a action name,
602- $ class = "$ cnp \\" . ucfirst ($ n1 ) . $ sfx ;
602+ $ class = "$ cnp \\" . \ ucfirst ($ n1 ) . $ sfx ;
603603
604- return class_exists ($ class ) ? "$ class@ $ n2 " : false ;
604+ return \ class_exists ($ class ) ? "$ class@ $ n2 " : false ;
605605 }
606606
607607 // max allow 5 nodes
@@ -610,18 +610,18 @@ public function matchAutoRoute(string $path)
610610 }
611611
612612 // last node is an controller class name
613- $ n2 = array_pop ($ ary );
614- $ class = sprintf ('%s \\%s \\%s ' , $ cnp , implode ('\\' , $ ary ), ucfirst ($ n2 ) . $ sfx );
613+ $ n2 = \ array_pop ($ ary );
614+ $ class = \ sprintf ('%s \\%s \\%s ' , $ cnp , \ implode ('\\' , $ ary ), \ ucfirst ($ n2 ) . $ sfx );
615615
616- if (class_exists ($ class )) {
616+ if (\ class_exists ($ class )) {
617617 return $ class ;
618618 }
619619
620620 // last second is an controller class name, last node is a action name,
621- $ n1 = array_pop ($ ary );
622- $ class = sprintf ('%s \\%s \\%s ' , $ cnp , implode ('\\' , $ ary ), ucfirst ($ n1 ) . $ sfx );
621+ $ n1 = \ array_pop ($ ary );
622+ $ class = \ sprintf ('%s \\%s \\%s ' , $ cnp , \ implode ('\\' , $ ary ), \ ucfirst ($ n1 ) . $ sfx );
623623
624- return class_exists ($ class ) ? "$ class@ $ n2 " : false ;
624+ return \ class_exists ($ class ) ? "$ class@ $ n2 " : false ;
625625 }
626626
627627 /**
@@ -649,13 +649,13 @@ public function getAvailableParams(array $tmpParams): array
649649 */
650650 public static function convertNodeStr ($ str ): string
651651 {
652- $ str = trim ($ str , '- ' );
652+ $ str = \ trim ($ str , '- ' );
653653
654654 // convert 'first-second' to 'firstSecond'
655- if (strpos ($ str , '- ' )) {
656- $ str = (string )preg_replace_callback ('/-+([a-z])/ ' , function ($ c ) {
657- return strtoupper ($ c [1 ]);
658- }, trim ($ str , '- ' ));
655+ if (\ strpos ($ str , '- ' )) {
656+ $ str = (string )\ preg_replace_callback ('/-+([a-z])/ ' , function ($ c ) {
657+ return \ strtoupper ($ c [1 ]);
658+ }, \ trim ($ str , '- ' ));
659659 }
660660
661661 return $ str ;
@@ -677,7 +677,7 @@ public function addGlobalParams(array $params)
677677 */
678678 public function addGlobalParam ($ name , $ pattern )
679679 {
680- $ name = trim ($ name , '{} ' );
680+ $ name = \ trim ($ name , '{} ' );
681681 self ::$ globalParams [$ name ] = $ pattern ;
682682 }
683683
0 commit comments