示例#1
0
文件: module.php 项目: icybee/core
 public function getBlock($name)
 {
     global $core;
     $args = func_get_args();
     $class_name = $this->resolve_block_class($name);
     if ($class_name) {
         array_shift($args);
         I18n::push_scope($this->flat_id);
         I18n::push_scope($this->flat_id . '.' . $name);
         try {
             $block = new $class_name($this, array(), $args);
             // 				$rendered_block = $block->render();
         } catch (\ICanBoogie\SecurityException $e) {
             I18n::pop_scope();
             I18n::pop_scope();
             throw $e;
         } catch (\Exception $e) {
             $block = \ICanBoogie\Debug::format_alert($e);
         }
         I18n::pop_scope();
         I18n::pop_scope();
         return $block;
     }
     // 		\ICanBoogie\log_info("Block class not found for <q>$name</q> falling to callbacks.");
     return call_user_func_array(PHP_MAJOR_VERSION > 5 || PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 2 ? 'parent::' . __FUNCTION__ : array($this, 'parent::' . __FUNCTION__), $args);
 }
示例#2
0
 public function __toString()
 {
     try {
         return (string) $this->render();
     } catch (\Exception $e) {
         return \ICanBoogie\Debug::format_alert($e);
     }
 }
示例#3
0
文件: Engine.php 项目: icybee/patron
 public function __invoke($template, $bind = null, array $options = [])
 {
     if (!$template) {
         return null;
     }
     if ($bind !== null) {
         $this->context['this'] = $bind;
     }
     $file = null;
     foreach ($options as $option => $value) {
         switch ((string) $option) {
             case 'variables':
                 foreach ($value as $k => $v) {
                     $this->context[$k] = $v;
                 }
                 break;
             case 'file':
                 $file = $value;
                 break;
             default:
                 trigger_error(\ICanBoogie\format('Suspicious option: %option :value', ['%option' => $option, ':value' => $value]));
                 break;
         }
     }
     if (!$template instanceof Template) {
         if (is_array($template) && isset($template['file'])) {
             $file = $template['file'];
             unset($template['file']);
         }
         if (!is_array($template)) {
             $template = $this->get_compiled($template);
         }
         $template = new Template($template, ['file' => $file]);
     }
     if ($template->file) {
         $this->trace_enter(['file', $template->file]);
     }
     $rc = '';
     foreach ($template as $node) {
         if (!$node instanceof Node) {
             continue;
         }
         try {
             $rc .= $node($this, $this->context);
         } catch (\Exception $e) {
             if (class_exists('ICanBoogie\\Debug')) {
                 $rc .= Debug::format_alert($e);
             } else {
                 $rc .= $e;
             }
         }
         $rc .= $this->fetchErrors();
     }
     $rc .= $this->fetchErrors();
     #
     #
     #
     if ($file) {
         array_shift($this->trace);
     }
     return $rc;
 }
示例#4
0
 public function __toString()
 {
     try {
         return (string) $this->render();
     } catch (\Exception $e) {
         Debug::report($e);
         return Debug::format_alert($e);
     }
 }
示例#5
0
 /**
  * Renders the body of the activerecord into a string.
  *
  * The body is rendered using the editor that was used to edit the content.
  *
  * A cache maybe used to store et retrieve the rendered content.
  *
  * @return string The rendered body.
  */
 public function __toString()
 {
     global $core;
     $rendered_body = $this->rendered_body;
     if ($rendered_body) {
         return $rendered_body;
     }
     $rendered_body = $body = $this->body;
     try {
         $cache = self::obtain_cache();
         if ($cache) {
             $nid = $this->nid;
             $updated_at = $this->updated_at;
             $cached = $cache->select('body')->filter_by_nid_and_updated_at($nid, $updated_at)->rc;
             if ($cached) {
                 return $cached;
             }
             if ($this->editor) {
                 $rendered_body = $this->render_body();
             }
             if ($rendered_body && $rendered_body != $body) {
                 $cache->save(['nid' => $nid, 'updated_at' => $updated_at, 'body' => $rendered_body], null, ['on duplicate' => true]);
             }
         } else {
             if ($this->editor) {
                 $rendered_body = $this->render_body();
             }
         }
     } catch (\Exception $e) {
         $rendered_body = \ICanBoogie\Debug::format_alert($e);
     }
     $this->rendered_body = $rendered_body;
     return $rendered_body;
 }