示例#1
0
 public function handle($e)
 {
     $app = App::getInstance();
     while (ob_get_level() > 0) {
         ob_end_clean();
     }
     // header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
     if ($app->config('bono.debug') !== true) {
         if (isset($app->response)) {
             $app->response->setStatus(500);
         }
         if (isset($app->theme)) {
             $view = $app->theme->getView();
             $errorTemplate = 'error';
         } else {
             $view = new View();
             $errorTemplate = '../templates/error.php';
             if (is_readable($errorTemplate)) {
                 $view->setTemplatesDirectory('.');
             }
         }
         return $view->display($errorTemplate, array('error' => $e), 500);
     }
     return call_user_func_array(array($app->whoops, Run::EXCEPTION_HANDLER), func_get_args());
 }
示例#2
0
 public function __invoke()
 {
     $user = $this->userRepository->authenticate($this->username, $this->password);
     if (false !== $user) {
         $this->session->set(LoginContext::LOGIN_VAR, $user->id());
         $this->redir->redirect(303, '/games');
         return;
     }
     $this->view->display('home.html', ['msg' => 'Invalid login']);
 }
示例#3
0
 public function __invoke()
 {
     $games = $this->gameRepository->findAll();
     $viewGames = [];
     /** @var Game $game */
     foreach ($games as $game) {
         $viewGames[$game->owner()->displayName()][] = $game->title();
     }
     $viewData['gamesList'] = $viewGames;
     $this->view->display('games.html', $viewData);
 }
示例#4
0
 /**
  * Render markdown input
  *
  * @param  string $markDownSyntax Markdown syntax to put inside textarea
  * @param  string $template       Template name
  * @return string HTML string
  */
 public function renderInput($markdownSyntax = '', $template = '_markdown/form')
 {
     $this->view->set('app', $this->app);
     $this->view->set('id', $this->random());
     $this->view->set('markdown', $markdownSyntax);
     $counter = count(explode('.php', $template));
     $bladeCounter = count(explode('.blade.php', $template));
     if ($counter == 1 and $bladeCounter == 1) {
         $template .= '.php';
     }
     return $this->view->fetch($template);
 }
示例#5
0
 /**
  * Render template
  * @var string Template to be rendered (optional)
  */
 public function render($template = '')
 {
     $template = is_string($template) ? $template . '.php' : null;
     if ($template) {
         $this->appendData(array('global' => $this->global));
         $content = parent::render($template);
     } else {
         $content = '';
     }
     // make sure buffers flushed
     ob_end_flush();
     if (ob_get_length() !== false) {
         ob_flush();
     }
     ob_start();
     extract(array('content' => $content, 'global' => $this->global));
     if ($this->layout) {
         $layoutPath = $this->getTemplatesDirectory() . '/' . ltrim($this->layout, '/');
         if (!is_readable($layoutPath)) {
             throw new RuntimeException('View cannot render layout `' . $layoutPath);
         }
         require $layoutPath;
     } else {
         echo $content;
     }
     return ob_get_clean();
 }
示例#6
0
 /**
  * @param array [$options]
  * @return void
  */
 public function __construct($options = array())
 {
     parent::__construct();
     foreach (array_intersect_key($options, array_flip($this->allowedOptions)) as $key => $value) {
         $this->{$key} = $value;
     }
 }
示例#7
0
 public function fetch($template, $data = null)
 {
     $data = is_array($data) ? $data : [];
     $data['css_files'] = $this->cssFiles;
     $data['js_files'] = $this->jsFiles;
     return parent::fetch($template, $data);
 }
示例#8
0
文件: Json.php 项目: WebDevBr/MvcRest
 public function render($template = [], $data = null)
 {
     if (is_string($template)) {
         return parent::render($template, $data);
     }
     return json_encode($this->data[0]);
 }
示例#9
0
 /**
  * [fetch description]
  *
  * @param [type] $template [description]
  *
  * @return [type] [description]
  */
 public function fetch($template)
 {
     $app = App::getInstance();
     if (empty($template)) {
         return $this->data['body'];
     } else {
         if ($app->theme) {
             $template = $app->theme->resolve($template, $this) ?: $template;
         }
         $html = parent::fetch($template);
         $layoutTemplate = null;
         if ($this->layout) {
             if ($app->theme) {
                 $layoutTemplate = $app->theme->resolve($this->layout, $this->layoutView);
             } else {
                 $layoutTemplate = $this->layout;
             }
         }
         if ($layoutTemplate) {
             $this->layoutView->replace($this->all());
             $this->layoutView->set('body', $html);
             return $this->layoutView->render($layoutTemplate);
         } else {
             return $html;
         }
     }
 }
示例#10
0
 public function __construct($path)
 {
     $this->loader = new \Twig_Loader_Filesystem($path);
     $this->twig = new \Twig_Environment($this->loader);
     $this->twig->addExtension(new \Twig_Extensions_Extension_I18n());
     parent::__construct();
 }
示例#11
0
 /**
  * Constructor
  *
  * @param string $template_dir The base template directory
  * @param string $compile_dir  The directory in which to compile the templates
  * @param string $cache_dir    The directory in which to cache the compiled templates
  * @param string $plugin_dir   The directory containing Smarty plugins
  */
 public function __construct($template_dir, $compile_dir, $cache_dir, $plugin_dir = '')
 {
     parent::__construct();
     $this->template_dir = $template_dir;
     $this->compile_dir = $compile_dir;
     $this->cache_dir = $cache_dir;
     $this->plugin_dir = $plugin_dir;
 }
示例#12
0
 public function __construct(array $options = array())
 {
     parent::__construct();
     $this->options = array_merge($this->options, $options);
     if (!empty($this->options['overwrite'])) {
         $this->options['auto_reload'] = true;
     }
 }
示例#13
0
 /**
  * Render a template
  *
  * Call this method within a GET, POST, PUT, DELETE, NOT FOUND, or ERROR
  * callable to render a template whose output is appended to the
  * current HTTP response body. How the template is rendered is
  * delegated to the current View.
  *
  * @param  string $template The name of the template passed into the view's render() method
  * @param  array  $data     Associative array of data made available to the view
  * @param  int    $status   The HTTP response status code to use (optional)
  */
 public function render($template, $data = array(), $status = null)
 {
     if (!is_null($status)) {
         $this->response->status($status);
     }
     $this->view->appendData($data);
     $this->view->display($template);
 }
示例#14
0
文件: View.php 项目: CFLOVEYR/hook
 public function __construct()
 {
     parent::__construct();
     $this->context = new SplStack();
     $this->yield_blocks = array();
     $this->helpers = new \Slim\Helper\Set($this->getHelpers());
     $this->block_helpers = new \Slim\Helper\Set($this->getBlockHelpers());
 }
示例#15
0
文件: App.php 项目: bd808/SAL
 /**
  * Configure view behavior.
  *
  * @param \Slim\View $view Default view
  */
 protected function configureView(\Slim\View $view)
 {
     $view->parserOptions = ['charset' => 'utf-8', 'cache' => $this->slim->config('view.cache'), 'debug' => $this->slim->config('debug'), 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true];
     // Install twig parser extensions
     $view->parserExtensions = [new \Slim\Views\TwigExtension(), new TwigExtension($this->slim->parsoid), new \Wikimedia\SimpleI18n\TwigExtension($this->slim->i18nContext), new \Twig_Extension_Debug(), new LinkifyExtension(['/(?<=^|\\s)\\b(I[0-9a-f]{6,})\\b(?=\\s|:|,|$)/' => ['https://gerrit.wikimedia.org/r/#/q/$1,n,z', '$1'], '/(?<=^|\\s|\\(|\\[)\\b([0-9a-f]{7,})\\b(?=\\s|:|,|\\)|\\]|$)/' => ['https://gerrit.wikimedia.org/r/#/q/$1,n,z', '$1'], '/\\b([Gg]errit[:|](\\d+))\\b/' => ['https://gerrit.wikimedia.org/r/#/c/$2', '$1'], '#(?<!/)\\b(T\\d+)\\b#' => ['https://phabricator.wikimedia.org/$1', '$1'], '/\\b([Bb]ugzilla[:|](\\d+))\\b/' => ['https://bugzilla.wikimedia.org/show_bug.cgi?id=$2', '$1'], '/(?<=^|\\s)\\br(\\d+)\\b(?=\\s|:|,|$)/' => ['https://www.mediawiki.org/wiki/Special:Code/MediaWiki/$1', '$0'], '#(?<=^|\\s)<?(https?://\\S+)>?(?=\\s|$)#' => ['$1', '$0']])];
     // Set default view data
     $view->replace(['app' => $this->slim, 'i18nCtx' => $this->slim->i18nContext]);
 }
示例#16
0
 protected function render($template, $data = null)
 {
     $contents = parent::render($template, $data);
     if (is_null($this->layoutFile)) {
         return $contents;
     } else {
         return parent::render('layout.php', array('contents' => $contents, 'title' => $this->htmlTitle));
     }
 }
 public function __construct($options)
 {
     parent::__construct();
     // Smarty対応
     self::$smartyDirectory = $options['smartyDirectory'];
     self::$smartyCompileDirectory = $options['smartyCompileDirectory'];
     self::$smartyCacheDirectory = $options['smartyCacheDirectory'];
     self::$smartyTemplatesDirectory = $options['smartyTemplatesDirectory'];
 }
示例#18
0
 /**
  * Render a template
  *
  * Call this method within a GET, POST, PUT, DELETE, NOT FOUND, or ERROR
  * callable to render a template whose output is appended to the
  * current HTTP response body. How the template is rendered is
  * delegated to the current View.
  *
  * @param  string $template The name of the template passed into the view's render() method
  * @param  array  $data     Associative array of data made available to the view
  * @param  int    $status   The HTTP response status code to use (optional)
  */
 public function render($template, $data = array(), $status = null)
 {
     if (!is_null($status)) {
         $this->response->status($status);
     }
     $this->view->setTemplatesDirectory($this->config('templates.path'));
     $this->view->appendData($data);
     $this->view->display($template);
 }
示例#19
0
文件: index.php 项目: kstm-su/ISUCON5
 public function render($template, $data = NULL)
 {
     if ($this->layout) {
         $_html = parent::render($template);
         $this->set('_html', $_html);
         $template = $this->layout;
         $this->layout = null;
     }
     return parent::render($template);
 }
示例#20
0
 public function handle()
 {
     $app = App::getInstance();
     if ($app->config('bono.debug') !== true) {
         if (isset($app->response)) {
             $app->response->setStatus(404);
         }
         if (isset($app->theme)) {
             $view = $app->theme->getView();
             $errorTemplate = 'notFound';
         } else {
             $view = new View();
             $errorTemplate = '../templates/notFound.php';
             if (is_readable($errorTemplate)) {
                 $view->setTemplatesDirectory('.');
             }
         }
         return $view->display($errorTemplate, array(), 404);
     }
     $app->whoops->sendHttpCode(404);
     return call_user_func(array($app->whoops, Run::EXCEPTION_HANDLER), new RuntimeException("404 Resource not found"));
 }
示例#21
0
 public function render($template, $data = null)
 {
     if (!is_array($data)) {
         $data = (array) $data;
     }
     if (isset($data['noWrapper'])) {
         return parent::render($template, $data);
     } else {
         $data['view'] = $this;
         $data['template'] = $template;
         return parent::render("decorator/decorator.phtml", $data);
     }
 }
示例#22
0
文件: View.php 项目: nazati/Slimx
 /**
  * Our (marginally) smarter render function. The layout can be changed by
  * setting a "_layout" data key to the new layout file, or boolean false to
  * disable layout.
  * 
  * @param string $template template name
  * @return string rendered template
  */
 public function render($template)
 {
     $env = \Slim\Environment::getInstance();
     $this->setData('_base', $env['SCRIPT_NAME']);
     $data = $this->getData();
     if (isset($data['_layout'])) {
         $layout = $data['_layout'];
     } else {
         $layout = $this->layout;
     }
     $content = parent::render($template);
     if ($layout !== false) {
         $this->setData($data);
         $this->setData('content', $content);
         $content = parent::render($layout);
     }
     return $content;
 }
示例#23
0
 /**
  * Render template
  * @var string $template Template to be rendered
  */
 public function render($template = '', $data = null)
 {
     $template = is_string($template) ? $template . '.php' : null;
     if ($template) {
         $this->appendData(array('global' => $this->global));
         $content = parent::render($template);
     } else {
         $content = '';
     }
     extract(array('content' => $content, 'global' => $this->global));
     if ($this->layout) {
         $layoutPath = $this->getTemplatesDirectory() . DIRECTORY_SEPARATOR . ltrim($this->layout, '/');
         if (!is_readable($layoutPath)) {
             throw new \RuntimeException('View cannot render layout `' . $layoutPath);
         }
         require $layoutPath;
     } else {
         echo $content;
     }
 }
示例#24
0
 /**
  * Initalizer a.k.a the class constructor
  * Leave the third arguments empty if you won't use any layout
  *
  * @param array  $options  Options for BladeView
  *
  * @return KrisanAlfa\Blade\BladeView
  */
 public function __construct(array $options)
 {
     parent::__construct();
     $this->app = App::getInstance();
     $this->container = new Container();
     $viewPaths = $this->resolvePath($options['viewPaths']);
     $this->container->singleton('view.paths', function () use($viewPaths) {
         return $viewPaths;
     });
     $cachePath = $options['cachePath'];
     $this->container->singleton('cache.path', function () use($cachePath) {
         return $cachePath;
     });
     $this->registerFilesystem();
     $this->registerEvents();
     $this->registerEngineResolver();
     $this->registerViewFinder();
     $this->registerFactory();
     $this->instance = $this->container->make('view');
 }
示例#25
0
 function __construct()
 {
     parent::__construct();
     require_once __DIR__ . '/../../Twig/lib/Twig/Autoloader.php';
     Twig_Autoloader::register();
     $loader = new \Twig_Loader_Filesystem();
     $locations = \Raptor\Raptor::getInstance()->getConfigurationLoader()->getOptions();
     $templates = $locations['location'];
     foreach ($templates as $key => $value) {
         if (!file_exists($value . '/Views')) {
             mkdir($value . '/Views');
         }
         $loader->addPath($value . '/Views', $key);
     }
     //        if (\Raptor\Raptor::getInstance()->getMode() == 'development') {
     if (\Raptor\Raptor::getInstance()->config('debug')) {
         $this->twig = new Twig_Environment($loader, array());
     } else {
         $this->twig = new Twig_Environment($loader, array('cache' => \Raptor\Core\Location::get(\Raptor\Core\Location::CACHE) . '/7u136'));
     }
     $this->register();
 }
示例#26
0
 public function __construct(AssetManager $asset_manager)
 {
     parent::__construct();
     $this->_assetManager = $asset_manager;
     $app = App::i();
     $this->documentMeta = new \ArrayObject();
     $this->bodyClasses = new \ArrayObject();
     $this->bodyProperties = new \ArrayObject();
     $this->jsObject = new \ArrayObject();
     $this->jsObject['baseURL'] = $app->baseUrl;
     $this->jsObject['assetURL'] = $app->assetUrl;
     $this->jsObject['maxUploadSize'] = $app->getMaxUploadSize($useSuffix = false);
     $this->jsObject['maxUploadSizeFormatted'] = $app->getMaxUploadSize();
     $folders = [];
     $class = get_called_class();
     while ($class !== __CLASS__) {
         if (!method_exists($class, 'getThemeFolder')) {
             throw new \Exception("getThemeFolder method is required for theme classes and is not present in {$class} class");
         }
         $folders[] = $class::getThemeFolder() . '/';
         $class = get_parent_class($class);
     }
     $this->path = new \ArrayObject(array_reverse($folders));
 }
示例#27
0
 function getOutput($template, $data = array())
 {
     $this->setData($data);
     return parent::render($template);
 }
示例#28
0
 protected function render($template, $data = null)
 {
     return parent::render($template . '.php', $data);
 }
示例#29
0
 public function __construct(Slim $app)
 {
     parent::__construct();
     $this->app = $app;
     $this->setTemplatesDirectory(__DIR__ . '/../Responder/html');
 }
 /**
  * コンストラクタ
  * 
  * @param Array $options
  */
 public function __construct($options)
 {
     parent::__construct();
     self::$twigOptions = $options;
 }