示例#1
0
文件: HTML.php 项目: rocketphp/html
 /**
  * Constructor
  *
  * @param string $name Node name
  * @param array  $args Node arguments
  * @throws InvalidArgumentException If $name is not a string
  * @throws InvalidArgumentException If $args is not a string
  */
 public function __construct($name = null, $args = null)
 {
     if (!is_null($name) && !is_string($name) || $name === "") {
         throw new InvalidArgumentException("Expected string for node name (e.g. `p`)", 1);
     }
     if (!is_null($args) && !is_string($args) || $args === "") {
         throw new InvalidArgumentException("Expected string for node args (e.g. `id=\"foo\"`)", 1);
     }
     parent::__construct();
 }
示例#2
0
 /**
  * Constructor
  *
  * @param string $tagname Tagname
  * @param string $args    Arguments
  */
 public function __construct($tagname, array $args = null)
 {
     parent::__construct();
     $this->_tagname = $tagname;
     if (strpos(HTML::VOID_ELEMENTS . ',', "{$tagname},") !== false) {
         $this->_kind = self::VOID;
     } else {
         $this->_kind = self::NORMAL;
     }
     if ($args) {
         $count = count($args);
         if ($count === 2) {
             $this->text($args[0]);
             $this->_attr = $args[1];
         } elseif ($count === 1) {
             if (preg_match("/(.*)=\"(.*)\"/", $args[0]) === 1) {
                 $this->_attr = $args[0];
             } else {
                 $this->text($args[0]);
             }
         }
     }
 }