Advertisement
geolim4

PHP crashe on recursive magic method calling

Apr 10th, 2015
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.38 KB | None | 0 0
  1.  
  2. class HtmlTool
  3. {
  4.     /**
  5.      * @var array
  6.      */
  7.     protected static $valid_standard_tags = ['a', 'abbr', 'address', 'area',
  8.  
  9.         'article', 'aside', 'audio', 'b',
  10.  
  11.         'base', 'bdi', 'bdo', 'blockquote',
  12.  
  13.         'body', 'br', 'button', 'canvas',
  14.  
  15.         'caption', 'cite', 'code', 'col',
  16.  
  17.         'colgroup', 'data', 'datalist', 'dd',
  18.  
  19.         'del', 'details', 'dfn', 'dialog',
  20.  
  21.         'div', 'dl', 'dt', 'em',
  22.  
  23.         'embed', 'fieldset', 'figcaption', 'figure',
  24.  
  25.         'footer', 'form', 'h1', 'h2',
  26.  
  27.         'h3', 'h4', 'h5', 'h6',
  28.  
  29.         'head', 'header', 'hgroup', 'hr',
  30.  
  31.         'html', 'i', 'iframe', 'img',
  32.  
  33.         'input', 'ins', 'kbd', 'keygen',
  34.  
  35.         'label', 'legend', 'li', 'link',
  36.  
  37.         'main', 'map', 'mark', 'menu',
  38.  
  39.         'menuitem', 'meta', 'meter', 'nav',
  40.  
  41.         'noscript', 'object', 'ol', 'optgroup',
  42.  
  43.         'option', 'output', 'p', 'param',
  44.  
  45.         'pre', 'progress', 'q', 'rb',
  46.  
  47.         'rp', 'rt', 'rtc', 'ruby',
  48.  
  49.         's', 'samp', 'script', 'section',
  50.  
  51.         'select', 'small', 'source', 'span',
  52.  
  53.         'strong', 'style', 'sub', 'summary',
  54.  
  55.         'sup', 'table', 'tbody', 'td',
  56.  
  57.         'template', 'textarea', 'tfoot', 'th',
  58.  
  59.         'thead', 'time', 'title', 'tr',
  60.  
  61.         'track', 'u', 'ul', 'var',
  62.  
  63.         'video', 'wbr'];
  64.  
  65.     /**
  66.      * @var array
  67.      */
  68.     protected static $valid_self_closed_tags = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
  69.  
  70.     /**
  71.      * @param $str
  72.      * @param $tag
  73.      * @param array $attributes
  74.      * @return string
  75.      */
  76.     public static function wrap($str, $tag, array $attributes = [])/*: String *//* PHP NG */
  77.     {
  78.         if ( in_array( $tag, self::$valid_standard_tags ) )
  79.         {
  80.             if ( in_array( $tag, self::$valid_self_closed_tags ) )
  81.             {
  82.                 return "<{$tag} data-content=\"" . htmlspecialchars( $str, ENT_QUOTES ) . self::generate_attributes( $attributes ) . "\"/>";
  83.             }
  84.             else
  85.             {
  86.                 return "<{$tag}>" . htmlspecialchars( $str ) . self::generate_attributes( $attributes ) . "</{$tag}>";
  87.             }
  88.         }
  89.  
  90.         return $str;
  91.     }
  92.  
  93.     public static function generate_attributes(array $attributes = [])
  94.     {
  95.         $attributes_str = '';
  96.         foreach ( $attributes AS $attr_name => $attr_value )
  97.         {
  98.             $attributes_str .= " {$attr_name}=\"" . htmlspecialchars( $attr_value, ENT_QUOTES ) . '"';
  99.         }
  100.  
  101.         return $attributes_str;
  102.     }
  103.  
  104.     public static function __callStatic($name, array $arguments)
  105.     {
  106.         return call_user_func_array( [__CLASS__, $name], $arguments );
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement