public function render($viewId = null, $defines = array())
 {
     if ($viewId === null) {
         throw new ZException('ViewId must defined at call of ' . get_class($this) . '#render().');
     }
     /*
      * Binding viewId to the composition's
      */
     $this->viewId = $viewId;
     $this->coreLibrary = $this->getAspect()->getLibraryNamespace(self::CORE_LIBRARY);
     $this->insertTagname = empty($this->coreLibrary) ? self::INSERT_TAGNAME : $this->coreLibrary . ':' . self::INSERT_TAGNAME;
     $inserts = ZXmlUtil::getElementsByName($this->getDocumentTree(), self::INSERT_TAGNAME, $this->coreLibrary);
     $inserts = $this->getNameAttributeBinded($inserts);
     $defines = $this->getNameAttributeBinded($defines);
     foreach ($inserts as &$insert) {
         if (!array_key_exists(ZXml::TAG_ATTRIBUTES_KEY, $insert) || !array_key_exists(self::INSERT_NAME_ATTRIBUTE, $insert[ZXml::TAG_ATTRIBUTES_KEY])) {
             throw new ZElementException('Insert element must have "' . self::INSERT_NAME_ATTRIBUTE . '" attribute.');
         }
         $name = $insert[ZXml::TAG_ATTRIBUTES_KEY][self::INSERT_NAME_ATTRIBUTE];
         /*
          * Replace children if matches any define element.
          */
         if (array_key_exists($name, $defines) && array_key_exists(ZXml::TAG_CHILDREN_KEY, $defines[$name])) {
             $insert[ZXml::TAG_CHILDREN_KEY] = $defines[$name][ZXml::TAG_CHILDREN_KEY];
         }
     }
     /*
      * Binding own meta insert.
      */
     $this->bindInserts($inserts, $this->document[1]);
     return parent::render();
 }
 public function init()
 {
     if ($this->template == null) {
         throw new ZElementException('Composition must have template');
     }
     $this->templateDocument = $this->getAspect()->createTemplateDocument(APP_PATH . $this->template);
     $coreNamespace = $this->getAspect()->getLibraryNamespace('core');
     $mySelf = array(ZXml::TAG_NAME_KEY => $this->fullName, ZXml::TAG_CHILDREN_KEY => $this->children);
     $defineElements = ZXmlUtil::getElementsByName($mySelf, 'define', $coreNamespace);
     $this->defines = $defineElements;
     $params = ZXmlUtil::getElementsByName($mySelf, 'param', $coreNamespace);
     foreach ($params as $param) {
         if (!isset($param[ZXml::TAG_ATTRIBUTES_KEY]['name']) || !isset($param[ZXml::TAG_ATTRIBUTES_KEY]['name'])) {
             throw new ZElementException('Param element must have "name" and "value" attributes.');
         }
         $key = $param[ZXml::TAG_ATTRIBUTES_KEY]['name'];
         $value = $param[ZXml::TAG_ATTRIBUTES_KEY]['value'];
         $value = $this->evaluateZX($value);
         $this->templateDocument->setContext($key, $value);
     }
 }