Exemplo n.º 1
0
 /**
  * Wraps/nests an $el as specified by $opts 
  * @param stringable|array $el - text or dom element or array of elements to be wrapped
  *   if array, entire array nested / wrapped as specified by $opts
  * Example: $this->nest(['<h2>Simple Text</h2>','<h3>H3 Header</h3>'],'section');
  * @param string|array $opts - simplest, if just string, wrap $el
  * Example: $tpp->wrap('Simple Text','section')=>"<div class'section'>Simple Text</div>"
  * in a div of class $opts -
  * if $opts array, might have 'tag' key - the rest are html attributes
  * Example: $opts = ['tag'=>'h2', 'class'=>'site-header',...]
  *   return "<h2 class='site-header'>$el</h2>"
  * 
  */
 public function nest($el, $opts = [])
 {
     $ret = new PkTree();
     if (is_simple($opts)) {
         //return $ret->div($el,$opts);
         $ret->div($el, $opts);
         return $ret;
     }
     if (is_array($opts)) {
         $tag = keyVal('tag', $opts, 'div');
         unset($opts['tag']);
         //return $ret->$tag($el, $opts);
         $ret->{$tag}($el, $opts);
         return $ret->up();
     }
     throw new \Exception("Invalid argument for OPTS: " . print_r($opts, 1));
 }
Exemplo n.º 2
0
 /** Initializes/resets any member attributes that have a key in $args,
  * then calls parent construct with NO args.
  * @param type $args
  */
 public function __construct($args = [])
 {
     foreach ($args as $key => $val) {
         if (property_exists($this, $key)) {
             $this->{$key} = $val;
         }
     }
     parent::__construct();
 }