Advertisement
fruffl

HTML5 Factory

Jun 11th, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.89 KB | None | 0 0
  1.  
  2.         /**
  3.          * copy element including content, wai, attributes
  4.          *
  5.          *  $a = Element::create('a')->attr('href', 'http://google.de')->attr('id', 'google-link')->wai('role', 'button')
  6.          *      ->content($span = Element::create('span')->content('link'));
  7.          *
  8.          *  $copy = $a->copy(Element::COPY_WAI | Element::COPY_CONTENT);
  9.          *
  10.          *  $span->content = 'Gooooooooooooooogle';
  11.          *
  12.          *  var_dump($a->render(), $copy->render());
  13.          *      string(94) "<a role="button" id="google-link" href="http://google.de"><span>Gooooooooooooooogle</span></a>"
  14.          *      string(38) "<a role="button"><span>link</span></a>"
  15.          *
  16.          */
  17.         public function copy($__flag)
  18.         {
  19.        
  20.             static $__STATIC_map;
  21.             isset($__STATIC_map) ?: $__STATIC_map = function($__value)
  22.             {
  23.                 return is_object($__value) ? clone $__value : $__value;
  24.             };
  25.            
  26.             $Copy = new $this;
  27.            
  28.             $Copy->__Element = new $this->__Element
  29.             (
  30.                 #! copy ADT attribute/wai/content
  31.                 $this->__Element->getTupleGC([__type_Element::parent, __type_Element::attribute, __type_Element::wai]),
  32.                 #! clone or create empty __type_Element sub tuple
  33.                 [
  34.                     __type_Element::attribute   => self::COPY_ATTR === ($__flag & self::COPY_ATTR) ? clone $this->__Element->get()[__type_Element::attribute] : Invoke::emitClass($this->__ElementSetup[__type_Element::attribute]),
  35.                     __type_Element::wai     => self::COPY_WAI === ($__flag & self::COPY_WAI) ? clone $this->__Element->get()[__type_Element::wai] : Invoke::emitClass($this->__ElementSetup[__type_Element::wai]),
  36.                     __type_Element::content     => Invoke::emitClass($this->__ElementSetup[__type_Element::content], [static::$__tContent, self::COPY_CONTENT === ($__flag & self::COPY_CONTENT) ? FsbCollection::fromArray($this->__Element->get()[__type_Element::content]->get())->map($__STATIC_map, ['collect' => FALSE]) : []])
  37.                    
  38.                 ]
  39.                 #! use element defaults
  40.                 + $this->__ElementSetup
  41.             );
  42.            
  43.             return $Copy;
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement