예제 #1
0
 /**
  * @param Node|string|array|\Traversable|array $symbol
  * @return Node|string|array|\Traversable|array
  */
 public function push($symbol)
 {
     if ($symbol === false || $symbol === null || $symbol === '') {
         return $symbol;
     }
     if ($symbol instanceof Buffer) {
         $this->push($symbol->toValue());
     } elseif ($symbol instanceof Node) {
         $this->parts[] = $symbol;
         $this->length++;
     } elseif (is_string($symbol)) {
         $len = count($this->parts);
         if ($len > 0 && is_string($this->parts[$len - 1])) {
             $this->parts[$len - 1] .= $symbol;
         } else {
             $this->parts[] = $symbol;
         }
         $this->length += strlen($symbol);
         $this->strLength += strlen($symbol);
     } elseif ($symbol instanceof \Traversable || is_array($symbol)) {
         $ret = [];
         foreach ($symbol as $part) {
             $ret[] = $this->push($part);
         }
         return $ret;
     } else {
         throw new \InvalidArgumentException(sprintf('Part type unsupported: %s', get_class($symbol)));
     }
     return $symbol;
 }