protected function _render() { $content = null; $elems = View::getObjects(View::PH_DEFAULT); if (is_array($elems)) { foreach ($elems as $elem) { $object = $elem[0]; $params = $elem[1]; if (!is_object($object)) { continue; } /* @var $object t41\View\ViewObject */ switch (get_class($object)) { case 't41\\View\\ListComponent': case 't41\\View\\TableComponent': $object->setDecorator(); $decorator = Decorator::factory($object); $content .= $decorator->render(); break; default: break; } } } return $content; }
protected function _() { $template = file_get_contents($this->_template); // transform some characters $template = str_replace("\t", str_repeat(" ", 15), $template); $template = str_replace("\n", "<br/>", $template); $tagPattern = "/%([a-z0-9]+)\\:([a-z0-9.]*)\\{*([a-zA-Z0-9:,\\\"']*)\\}*%/"; $tags = array(); preg_match_all($tagPattern, $template, $tags, PREG_SET_ORDER); // PHASE 1 foreach ($tags as $key => $tag) { $content = ''; if ($tag[1] == 'env') { $content = \t41\Core::htmlEncode(\t41\View::getEnvData($tag[2])); unset($tag[$key]); } if (isset($tag[0])) { $template = str_replace($tag[0], $content, $template); } } $this->_document->writeHTML($template); // PHASE 2 - other tags foreach ($tags as $tag) { $content = ''; switch ($tag[1]) { case 'container': $elems = \t41\View::getObjects($tag[2]); if (is_array($elems)) { foreach ($elems as $elem) { $object = $elem[0]; $params = $elem[1]; if (!is_object($object)) { continue; } /* @var $object t41_Form_Abstract */ switch (get_class($object)) { case 't41_Form_List': case 't41_View_Table': case 't41_View_Image': case 't41_View_Component': case 't41_View_Error': case 't41_View_Spacer': $decorator = \t41\View\Decorator::factory($object, $params); $decorator->render($this->_document, $this->_width); break; default: break; } } } break; } } }
protected function _render() { $template = file_get_contents($this->_template); $tagPattern = "/%([a-z0-9]+)\\:([a-z0-9.]*)\\{*([a-zA-Z0-9:,\\\"']*)\\}*%/"; $tagPattern = "/%([a-z0-9]+)\\:([a-z0-9_.]*)\\{*([a-zA-Z0-9:_,\\\"']*)\\}*%/"; $tags = array(); preg_match_all($tagPattern, $template, $tags, PREG_SET_ORDER); // PHASE 1: analyse et parsing of content-generating tags foreach ($tags as $tag) { $content = false; switch ($tag[1]) { case 'helper': $tmp = explode('.', $tag[2]); $class = sprintf('%s\\View\\Web\\%s', $tmp[0], ucfirst($tmp[1])); try { $helper = new $class(); $content = $helper->render(); } catch (Exception $e) { if (Core::$env == Core::ENV_DEV) { $content = $e->getMessage(); } } break; case 'container': $elems = View::getObjects($tag[2]); if (is_array($elems)) { foreach ($elems as $elem) { $object = $elem[0]; $params = $elem[1]; if (!is_object($object)) { continue; } // look for a custom decorator $decorator = View\Decorator::factory($object, $params); $content .= $decorator->render(); } } break; } if ($content !== false) { $template = str_replace($tag[0], $content, $template); } } preg_match_all($tagPattern, $template, $tags, PREG_SET_ORDER); // PHASE 2: analyze & parsing of other tags (components linking & env variables) foreach ($tags as $tag) { $content = null; switch ($tag[1]) { case 'components': $content = $this->_renderComponents($tag[2], $tag[3]); break; case 'env': case 'var': $content = View::getEnvData($tag[2]); break; case 'obj': // obj: $tmp = explode('.', $tag[2]); $obj = View::getEnvData($tmp[0]); if ($obj instanceof MediaObject && isset($tmp[1])) { // meta properties handling switch ($tmp[1]) { case '_base64': $content = sprintf('data:%s;base64,%s', $obj->getMime(), base64_encode($obj->loadBlob('media'))); break; case '_icon': $content = 'file-' . $obj->getExtension(); break; case '_size': $content = MediaElement::getDisplaySize($obj->getSize()); break; case '_url': $content = MediaElement::getDownloadUrl($obj->getUri()); break; default: break; } } if (!$content) { if ($obj instanceof BaseObject) { $content = isset($tmp[1]) && $tmp[1] == ObjectUri::IDENTIFIER ? $obj->getIdentifier() : $obj->getProperty($tmp[1]); $content = $content instanceof AbstractProperty ? $content->getDisplayValue() : $content; } else { $content = Core::$env == Core::ENV_DEV ? sprintf("Can't substitute any value to '%s'", $tag[0]) : null; } } break; } $template = str_replace($tag[0], $content, $template); } // PHASE 3: actions attachment $this->actionAttach(); // PHASE 4: events attachment $template = str_replace('</body>', $this->eventAttach() . '</body>', $template); // PHASE 5: display logged errors in dev mode if (Core::$env == Core::ENV_DEV) { $errors = View::getErrors(); if (count($errors) > 0) { $str = "\n"; foreach ($errors as $errorCode => $errorbloc) { $str .= $errorCode . "\n"; foreach ($errorbloc as $error) { $str .= "\t" . $error[0] . "\n"; } } $template = str_replace('</body>', '</body><!--' . $str . ' -->', $template); } } return $template; }