fruffl icon

HTML5 Factory

fruffl | 06/11/13 01:43:10 PM UTC | 0 ⭐ | 274 👁️ | Never ⏰ | []
PHP |

1.89 KB

|

None

|

0 👍

/

0 👎

 
        /**
         * copy element including content, wai, attributes
         *
         *  $a = Element::create('a')->attr('href', 'http://google.de')->attr('id', 'google-link')->wai('role', 'button')
         *      ->content($span = Element::create('span')->content('link'));
         *
         *  $copy = $a->copy(Element::COPY_WAI | Element::COPY_CONTENT);
         *
         *  $span->content = 'Gooooooooooooooogle';
         *
         *  var_dump($a->render(), $copy->render());
         *      string(94) "<a role="button" id="google-link" href="http://google.de"><span>Gooooooooooooooogle</span></a>"
         *      string(38) "<a role="button"><span>link</span></a>"
         *
         */
        public function copy($__flag)
        {
        
            static $__STATIC_map;
            isset($__STATIC_map) ?: $__STATIC_map = function($__value)
            {
                return is_object($__value) ? clone $__value : $__value;
            };
            
            $Copy = new $this;
            
            $Copy->__Element = new $this->__Element
            (
                #! copy ADT attribute/wai/content
                $this->__Element->getTupleGC([__type_Element::parent, __type_Element::attribute, __type_Element::wai]),
                #! clone or create empty __type_Element sub tuple
                [
                    __type_Element::attribute   => self::COPY_ATTR === ($__flag & self::COPY_ATTR) ? clone $this->__Element->get()[__type_Element::attribute] : Invoke::emitClass($this->__ElementSetup[__type_Element::attribute]),
                    __type_Element::wai     => self::COPY_WAI === ($__flag & self::COPY_WAI) ? clone $this->__Element->get()[__type_Element::wai] : Invoke::emitClass($this->__ElementSetup[__type_Element::wai]),
                    __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]) : []])
                    
                ]
                #! use element defaults
                + $this->__ElementSetup
            );
            
            return $Copy;
        }

Comments