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); }
/** * Translate a native string in a locale string. * * @param string $native The native string to translate. * @param array $args * @param array $options * * @return string The translated string, or the same native string if no translation could be * found. */ public function __invoke($native, array $args = array(), array $options = array()) { $native = (string) $native; $messages = $this->messages; $translated = null; $suffix = null; if ($args && array_key_exists(':count', $args)) { $count = $args[':count']; if ($count == 0) { $suffix = '.none'; } else { if ($count == 1) { $suffix = '.one'; } else { $suffix = '.other'; } } } $scope = I18n::get_scope(); if (isset($options['scope'])) { if ($scope) { $scope .= '.'; } $scope .= is_array($options['scope']) ? implode('.', $options['scope']) : $options['scope']; } $prefix = $scope; while ($scope) { $try = $scope . '.' . $native . $suffix; if (isset($messages[$try])) { $translated = $messages[$try]; break; } $pos = strpos($scope, '.'); if ($pos === false) { break; } $scope = substr($scope, $pos + 1); } if (!$translated) { if (isset($messages[$native . $suffix])) { $translated = $messages[$native . $suffix]; } } if (!$translated) { self::$missing[] = ($prefix ? $prefix . '.' : '') . $native; if (!empty($options['default'])) { $default = $options['default']; if (!$default instanceof \Closure) { return $default; } $native = $default($this, $native, $options, $args) ?: $native; } # # We couldn't find any translation for the native string provided, in order to avoid # another search for the same string, we store the native string as the translation in # the locale messages. # $this->messages[($prefix ? $prefix . '.' : '') . $native] = $native; $translated = $native; } if ($args) { $translated = \ICanBoogie\format($translated, $args); } return $translated; }
/** * Renders the inner HTML of the view. * * If the data provided implements {@link \Brickrouge\CSSClassNames}, the class names of the * record are added those of the view element. * * @param Context $context * * @throws \Exception * * @return string The inner HTML of the view element. */ protected function render_inner_html(Context $context) { $this->data = $bind = $this->resolve_bind(); if (!$bind && $this->renders != ViewOptions::RENDERS_OTHER) { $this->element->add_class('empty'); $html = (string) $this->render_empty_inner_html(); $this->fire_render_empty_inner_html($html); return $html; } if (is_array($bind) && reset($bind) instanceof Node) { new \BlueTihi\Context\LoadedNodesEvent($context, $bind); } elseif ($bind instanceof Node) { new \BlueTihi\Context\LoadedNodesEvent($context, [$bind]); } elseif ($bind instanceof \Brickrouge\CSSClassNames) { $this->element['class'] .= ' ' . $bind->css_class; } /* @var $template_resolver \ICanBoogie\Render\TemplateResolver */ $template_resolver = clone $this->app->template_resolver; $engines = $this->app->template_engines; $tries = []; $this->template_tries =& $tries; $template_pathname = $template_resolver->resolve($this->id, $engines->extensions, $tries); if (!$template_pathname) { throw new TemplateNotFound("Unable to find template for {$this->id}.", $tries); } $this->template_pathname = $template_pathname; I18n::push_scope($this->module->flat_id); try { $html = $engines->render($template_pathname, $bind, $this->resolve_variables()); I18n::pop_scope(); return $html; } catch (\Exception $e) { I18n::pop_scope(); throw $e; } }