X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2FPathRouter.php;h=005c34138c3efbd8d1a1b3be56f00857e243e021;hb=55fc2a9bd247ec82f9aa5e99af95855d28eea326;hp=d367e4da3aafdf85579c1b3528851eb6e933901a;hpb=968f3cd2d801c6358ad2da54968d77e11f6bc6b5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/PathRouter.php b/includes/PathRouter.php index d367e4da3a..005c34138c 100644 --- a/includes/PathRouter.php +++ b/includes/PathRouter.php @@ -75,17 +75,17 @@ class PathRouter { /** * @var array */ - private $patterns = array(); + private $patterns = []; /** * Protected helper to do the actual bulk work of adding a single pattern. * This is in a separate method so that add() can handle the difference between * a single string $path and an array() $path that contains multiple path * patterns each with an associated $key to pass on. - * @param $path string - * @param $params array - * @param $options array - * @param $key null|string + * @param string $path + * @param array $params + * @param array $options + * @param null|string $key */ protected function doAdd( $path, $params, $options, $key = null ) { // Make sure all paths start with a / @@ -124,9 +124,9 @@ class PathRouter { // of a pattern for a little more efficiency $paramArrKey = 'value'; } - $params[$paramName] = array( + $params[$paramName] = [ $paramArrKey => $paramData - ); + ]; } } @@ -135,17 +135,17 @@ class PathRouter { foreach ( $options as $optionName => $optionData ) { if ( preg_match( '/^\$\d+$/u', $optionName ) ) { if ( !is_array( $optionData ) ) { - $options[$optionName] = array( $optionData ); + $options[$optionName] = [ $optionData ]; } } } - $pattern = (object)array( + $pattern = (object)[ 'path' => $path, 'params' => $params, 'options' => $options, 'key' => $key, - ); + ]; $pattern->weight = self::makeWeight( $pattern ); $this->patterns[] = $pattern; } @@ -157,7 +157,7 @@ class PathRouter { * @param array $params The params for this path pattern * @param array $options The options for this path pattern */ - public function add( $path, $params = array(), $options = array() ) { + public function add( $path, $params = [], $options = [] ) { if ( is_array( $path ) ) { foreach ( $path as $key => $onePath ) { $this->doAdd( $onePath, $params, $options, $key ); @@ -170,11 +170,11 @@ class PathRouter { /** * Add a new path pattern to the path router with the strict option on * @see self::add - * @param $path string|array - * @param $params array - * @param $options array + * @param string|array $path + * @param array $params + * @param array $options */ - public function addStrict( $path, $params = array(), $options = array() ) { + public function addStrict( $path, $params = [], $options = [] ) { $options['strict'] = true; $this->add( $path, $params, $options ); } @@ -184,7 +184,7 @@ class PathRouter { * (most heavily weighted) patterns are at the start of the array. */ protected function sortByWeight() { - $weights = array(); + $weights = []; foreach ( $this->patterns as $key => $pattern ) { $weights[$key] = $pattern->weight; } @@ -192,7 +192,7 @@ class PathRouter { } /** - * @param $pattern object + * @param object $pattern * @return float|int */ protected static function makeWeight( $pattern ) { @@ -233,7 +233,7 @@ class PathRouter { * Parse a path and return the query matches for the path * * @param string $path The path to parse - * @return Array The array of matches for the path + * @return array The array of matches for the path */ public function parse( $path ) { // Make sure our patterns are sorted by weight so the most specific @@ -253,12 +253,12 @@ class PathRouter { // array() (a match with no data) but our WebRequest caller // expects array() even when we have no matches so return // a array() when we have null - return is_null( $matches ) ? array() : $matches; + return is_null( $matches ) ? [] : $matches; } /** - * @param $path string - * @param $pattern string + * @param string $path + * @param string $pattern * @return array|null */ protected static function extractTitle( $path, $pattern ) { @@ -270,8 +270,8 @@ class PathRouter { $regexp = preg_replace( '#\\\\\$(\d+)#u', '(?P.+?)', $regexp ); $regexp = "#^{$regexp}$#"; - $matches = array(); - $data = array(); + $matches = []; + $data = []; // Try to match the path we were asked to parse with our regexp if ( preg_match( $regexp, $path, $m ) ) { @@ -342,7 +342,7 @@ class PathRouter { // If this match includes a callback, execute it if ( isset( $pattern->options['callback'] ) ) { - call_user_func_array( $pattern->options['callback'], array( &$matches, $data ) ); + call_user_func_array( $pattern->options['callback'], [ &$matches, $data ] ); } } else { // Our regexp didn't match, return null to signify no match. @@ -363,12 +363,12 @@ class PathRouterPatternReplacer { * We do this inside of a replacement callback because after replacement we can't tell the * difference between a $1 that was not replaced and a $1 that was part of * the content a $1 was replaced with. - * @param $value string + * @param string $value * @return string */ public function replace( $value ) { $this->error = false; - $value = preg_replace_callback( '/\$(\d+|key)/u', array( $this, 'callback' ), $value ); + $value = preg_replace_callback( '/\$(\d+|key)/u', [ $this, 'callback' ], $value ); if ( $this->error ) { return false; } @@ -376,7 +376,7 @@ class PathRouterPatternReplacer { } /** - * @param $m array + * @param array $m * @return string */ protected function callback( $m ) {