Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * -----------------------------------------------------------------------------
- *
- * PHP version 5
- *
- * @author Setyo Nugroho < email@nsetyo.net >
- * @copyright 2014 Setyo Nugroho
- * @license The MIT License (MIT), see LISENSI.txt
- * @link https://github.com/nsetyo/tulang
- *
- * -----------------------------------------------------------------------------
- */
- namespace Bones;
- use Symfony\Component\HttpFoundation\Response;
- use Bones\Helpers\Url;
- /**
- * -----------------------------------------------------------------------------
- * Framework output control
- *
- * -----------------------------------------------------------------------------
- */
- class View
- {
- protected $assets_dir;
- protected $assets_url;
- protected $variables = array();
- /**
- * -------------------------------------------------------------------------
- * Construct
- * @param string $assets_dir Assets directory path
- * @param string $assets_url Assets base url
- *
- * -------------------------------------------------------------------------
- */
- public function __construct($assets_dir, $assets_url)
- {
- $this->assets_dir = realpath($assets_dir);
- $this->assets_url = Url::getBaseUrl() . trim($assets_url, "/");
- }
- /**
- * -------------------------------------------------------------------------
- * Store variable
- * @param array $variables Variable to store
- *
- * -------------------------------------------------------------------------
- */
- public function setVar(array $variables)
- {
- $this->variables = array_merge($this->variables, $variables);
- }
- /**
- * -------------------------------------------------------------------------
- * Render output with setted variable
- * @param string $template Template filename without extention
- * @param integer $status The response status code
- * @return Response Response instance
- *
- * -------------------------------------------------------------------------
- */
- public function render($template, $status = 200)
- {
- ob_start();
- extract($this->variables);
- $content_buf = require $this->assets_dir . '/' . $template . '.php';
- $content_var = ob_get_clean();
- $response = new Response($content_var, (int) $status);
- return $response;
- }
- /**
- * -------------------------------------------------------------------------
- * Return the assets file url
- * @param string $assets_file The assets file
- * @return string The assets file URL
- *
- * -------------------------------------------------------------------------
- */
- public function assetsUrl($assets_file)
- {
- $assets_file = "/" . ltrim($assets_file, "/");
- return $this->assets_url . $assets_file;
- }
- /**
- * -------------------------------------------------------------------------
- * Alias of assetsUrl
- * @param string $assets_file The assets file
- * @return string The assets file URL
- *
- * -------------------------------------------------------------------------
- */
- public function assets($assets_url)
- {
- return $this->assetsUrl($assets_url);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement