Subversion Repositories oidplus

Rev

Blame | Last modification | View Log | RSS feed

  1. <?php
  2.  
  3. namespace RobRichards\XMLSecLibs\Utils;
  4.  
  5. class XPath
  6. {
  7.     const ALPHANUMERIC = '\w\d';
  8.     const NUMERIC = '\d';
  9.     const LETTERS = '\w';
  10.     const EXTENDED_ALPHANUMERIC = '\w\d\s\-_:\.';
  11.  
  12.     const SINGLE_QUOTE = '\'';
  13.     const DOUBLE_QUOTE = '"';
  14.     const ALL_QUOTES = '[\'"]';
  15.  
  16.  
  17.     /**
  18.      * Filter an attribute value for save inclusion in an XPath query.
  19.      *
  20.      * @param string $value The value to filter.
  21.      * @param string $quotes The quotes used to delimit the value in the XPath query.
  22.      *
  23.      * @return string The filtered attribute value.
  24.      */
  25.     public static function filterAttrValue($value, $quotes = self::ALL_QUOTES)
  26.     {
  27.         return preg_replace('#'.$quotes.'#', '', $value);
  28.     }
  29.  
  30.  
  31.     /**
  32.      * Filter an attribute name for save inclusion in an XPath query.
  33.      *
  34.      * @param string $name The attribute name to filter.
  35.      * @param mixed $allow The set of characters to allow. Can be one of the constants provided by this class, or a
  36.      * custom regex excluding the '#' character (used as delimiter).
  37.      *
  38.      * @return string The filtered attribute name.
  39.      */
  40.     public static function filterAttrName($name, $allow = self::EXTENDED_ALPHANUMERIC)
  41.     {
  42.         return preg_replace('#[^'.$allow.']#', '', $name);
  43.     }
  44. }
  45.