* - Matches /edit/Foo style urls and sets action=edit
* $router->add( '/$2/$1',
* - Matches /edit/Foo style urls and sets action=edit
* $router->add( '/$2/$1',
- * array( 'variant' => '$2' ),
- * array( '$2' => array( 'zh-hant', 'zh-hans' )
+ * [ 'variant' => '$2' ],
+ * [ '$2' => [ 'zh-hant', 'zh-hans' ] ]
* - Matches /Foo, adds the key 'foo' with the value 'bar' to the data array
* and calls functionname( &$matches, $data );
*
* - Matches /Foo, adds the key 'foo' with the value 'bar' to the data array
* and calls functionname( &$matches, $data );
*
* - The default behavior is equivalent to `array( 'title' => '$1' )`,
* if you don't want the title parameter you can explicitly use `array( 'title' => false )`
* - You can specify a value that won't have replacements in it
* - The default behavior is equivalent to `array( 'title' => '$1' )`,
* if you don't want the title parameter you can explicitly use `array( 'title' => false )`
* - You can specify a value that won't have replacements in it
/**
* 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.
/**
* 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.
*/
protected function doAdd( $path, $params, $options, $key = null ) {
// Make sure all paths start with a /
*/
protected function doAdd( $path, $params, $options, $key = null ) {
// Make sure all paths start with a /
foreach ( $options as $optionName => $optionData ) {
if ( preg_match( '/^\$\d+$/u', $optionName ) ) {
if ( !is_array( $optionData ) ) {
foreach ( $options as $optionName => $optionData ) {
if ( preg_match( '/^\$\d+$/u', $optionName ) ) {
if ( !is_array( $optionData ) ) {
* @param array $params The params for this path pattern
* @param array $options The options for this path pattern
*/
* @param array $params The params for this path pattern
* @param array $options The options for this path pattern
*/
if ( is_array( $path ) ) {
foreach ( $path as $key => $onePath ) {
$this->doAdd( $onePath, $params, $options, $key );
if ( is_array( $path ) ) {
foreach ( $path as $key => $onePath ) {
$this->doAdd( $onePath, $params, $options, $key );
$options['strict'] = true;
$this->add( $path, $params, $options );
}
$options['strict'] = true;
$this->add( $path, $params, $options );
}
* (most heavily weighted) patterns are at the start of the array.
*/
protected function sortByWeight() {
* (most heavily weighted) patterns are at the start of the array.
*/
protected function sortByWeight() {
// 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
// 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
$regexp = preg_replace( '#\\\\\$(\d+)#u', '(?P<par$1>.+?)', $regexp );
$regexp = "#^{$regexp}$#";
$regexp = preg_replace( '#\\\\\$(\d+)#u', '(?P<par$1>.+?)', $regexp );
$regexp = "#^{$regexp}$#";
// Try to match the path we were asked to parse with our regexp
if ( preg_match( $regexp, $path, $m ) ) {
// Try to match the path we were asked to parse with our regexp
if ( preg_match( $regexp, $path, $m ) ) {
// If this match includes a callback, execute it
if ( isset( $pattern->options['callback'] ) ) {
// If this match includes a callback, execute it
if ( isset( $pattern->options['callback'] ) ) {
* 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.
* 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.
- $value = preg_replace_callback( '/\$(\d+|key)/u', array( $this, 'callback' ), $value );
+ $value = preg_replace_callback( '/\$(\d+|key)/u', [ $this, 'callback' ], $value );