Changeset 38376 for trunk/src/wp-includes/class-wp.php
- Timestamp:
- 08/26/2016 06:10:23 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp.php
r37542 r38376 739 739 } 740 740 } 741 742 /**743 * Helper class to remove the need to use eval to replace $matches[] in query strings.744 *745 * @since 2.9.0746 */747 class WP_MatchesMapRegex {748 /**749 * store for matches750 *751 * @access private752 * @var array753 */754 private $_matches;755 756 /**757 * store for mapping result758 *759 * @access public760 * @var string761 */762 public $output;763 764 /**765 * subject to perform mapping on (query string containing $matches[] references766 *767 * @access private768 * @var string769 */770 private $_subject;771 772 /**773 * regexp pattern to match $matches[] references774 *775 * @var string776 */777 public $_pattern = '(\$matches\[[1-9]+[0-9]*\])'; // magic number778 779 /**780 * constructor781 *782 * @param string $subject subject if regex783 * @param array $matches data to use in map784 */785 public function __construct($subject, $matches) {786 $this->_subject = $subject;787 $this->_matches = $matches;788 $this->output = $this->_map();789 }790 791 /**792 * Substitute substring matches in subject.793 *794 * static helper function to ease use795 *796 * @static797 * @access public798 *799 * @param string $subject subject800 * @param array $matches data used for substitution801 * @return string802 */803 public static function apply($subject, $matches) {804 $oSelf = new WP_MatchesMapRegex($subject, $matches);805 return $oSelf->output;806 }807 808 /**809 * do the actual mapping810 *811 * @access private812 * @return string813 */814 private function _map() {815 $callback = array($this, 'callback');816 return preg_replace_callback($this->_pattern, $callback, $this->_subject);817 }818 819 /**820 * preg_replace_callback hook821 *822 * @access public823 * @param array $matches preg_replace regexp matches824 * @return string825 */826 public function callback($matches) {827 $index = intval(substr($matches[0], 9, -1));828 return ( isset( $this->_matches[$index] ) ? urlencode($this->_matches[$index]) : '' );829 }830 }
Note: See TracChangeset
for help on using the changeset viewer.