Preview::build PHP Method

build() protected method

Assemble markup
protected build ( $node ) : string
$node string
return string
    protected function build($node)
    {
        $self = $this;
        return preg_replace_callback('/\\{\\-(.+?)\\-\\}|\\{\\{(.+?)\\}\\}(\\n+)?|(\\{\\*.*?\\*\\})/s', function ($expr) use($self) {
            if ($expr[1]) {
                return $expr[1];
            }
            $str = trim($self->token($expr[2]));
            return empty($expr[4]) ? '<?php echo ' . $str . '; ?>' . (isset($expr[3]) ? $expr[3] . "\n" : '') : '';
        }, preg_replace_callback('/\\{~(.+?)~\\}/s', function ($expr) use($self) {
            return '<?php ' . $self->token($expr[1]) . ' ?>';
        }, $node));
    }

Usage Example

Example #1
0
 /**
  *	Assemble markup
  *	@return string
  *	@param $node array|string
  **/
 function build($node)
 {
     if (is_string($node)) {
         return parent::build($node);
     }
     $out = '';
     foreach ($node as $key => $val) {
         $out .= is_int($key) ? $this->build($val) : $this->{'_' . $key}($val);
     }
     return $out;
 }