Load: move `WP_MatchesMapRegex` into its own file.

See #37827.

Built from https://develop.svn.wordpress.org/trunk@38376


git-svn-id: http://core.svn.wordpress.org/trunk@38317 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2016-08-26 18:11:39 +00:00
parent b2c394a330
commit b3d474a6dc
4 changed files with 99 additions and 91 deletions

View File

@ -0,0 +1,97 @@
<?php
/**
* WP_MatchesMapRegex helper class
*
* @package WordPress
* @since 4.7.0
*/
/**
* Helper class to remove the need to use eval to replace $matches[] in query strings.
*
* @since 2.9.0
*/
class WP_MatchesMapRegex {
/**
* store for matches
*
* @access private
* @var array
*/
private $_matches;
/**
* store for mapping result
*
* @access public
* @var string
*/
public $output;
/**
* subject to perform mapping on (query string containing $matches[] references
*
* @access private
* @var string
*/
private $_subject;
/**
* regexp pattern to match $matches[] references
*
* @var string
*/
public $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number
/**
* constructor
*
* @param string $subject subject if regex
* @param array $matches data to use in map
*/
public function __construct($subject, $matches) {
$this->_subject = $subject;
$this->_matches = $matches;
$this->output = $this->_map();
}
/**
* Substitute substring matches in subject.
*
* static helper function to ease use
*
* @static
* @access public
*
* @param string $subject subject
* @param array $matches data used for substitution
* @return string
*/
public static function apply($subject, $matches) {
$oSelf = new WP_MatchesMapRegex($subject, $matches);
return $oSelf->output;
}
/**
* do the actual mapping
*
* @access private
* @return string
*/
private function _map() {
$callback = array($this, 'callback');
return preg_replace_callback($this->_pattern, $callback, $this->_subject);
}
/**
* preg_replace_callback hook
*
* @access public
* @param array $matches preg_replace regexp matches
* @return string
*/
public function callback($matches) {
$index = intval(substr($matches[0], 9, -1));
return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' );
}
}

View File

@ -738,93 +738,3 @@ class WP {
do_action_ref_array( 'wp', array( &$this ) );
}
}
/**
* Helper class to remove the need to use eval to replace $matches[] in query strings.
*
* @since 2.9.0
*/
class WP_MatchesMapRegex {
/**
* store for matches
*
* @access private
* @var array
*/
private $_matches;
/**
* store for mapping result
*
* @access public
* @var string
*/
public $output;
/**
* subject to perform mapping on (query string containing $matches[] references
*
* @access private
* @var string
*/
private $_subject;
/**
* regexp pattern to match $matches[] references
*
* @var string
*/
public $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number
/**
* constructor
*
* @param string $subject subject if regex
* @param array $matches data to use in map
*/
public function __construct($subject, $matches) {
$this->_subject = $subject;
$this->_matches = $matches;
$this->output = $this->_map();
}
/**
* Substitute substring matches in subject.
*
* static helper function to ease use
*
* @static
* @access public
*
* @param string $subject subject
* @param array $matches data used for substitution
* @return string
*/
public static function apply($subject, $matches) {
$oSelf = new WP_MatchesMapRegex($subject, $matches);
return $oSelf->output;
}
/**
* do the actual mapping
*
* @access private
* @return string
*/
private function _map() {
$callback = array($this, 'callback');
return preg_replace_callback($this->_pattern, $callback, $this->_subject);
}
/**
* preg_replace_callback hook
*
* @access public
* @param array $matches preg_replace regexp matches
* @return string
*/
public function callback($matches) {
$index = intval(substr($matches[0], 9, -1));
return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' );
}
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-alpha-38375';
$wp_version = '4.7-alpha-38376';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -92,6 +92,7 @@ wp_set_lang_dir();
// Load early WordPress files.
require( ABSPATH . WPINC . '/compat.php' );
require( ABSPATH . WPINC . '/functions.php' );
require( ABSPATH . WPINC . '/class-wp-matchesmapregex.php' );
require( ABSPATH . WPINC . '/class-wp.php' );
require( ABSPATH . WPINC . '/class-wp-error.php' );
require( ABSPATH . WPINC . '/pomo/mo.php' );