Permalink
Browse files

removing current View class (duplicated a lot from Template)

  • Loading branch information...
1 parent 3dcde8f commit 89b96112a5bec65312b616ea0d0a975a806f7c8f @enygma committed Aug 10, 2012
Showing with 0 additions and 253 deletions.
  1. +0 −197 Shield/View.php
  2. +0 −56 Shield/tests/Shield/ViewTest.php
View
@@ -1,197 +0,0 @@
-<?php
-
-namespace Shield;
-
-class View extends Base
-{
- /**
- * Container for the values to replace in the array
- * @var array
- */
- private $values = array();
-
- /**
- * View directory path
- * @var string
- */
- private $_viewDir = null;
-
- /**
- * Default Content-Type
- * @var string
- */
- private $contentType = 'text/html';
-
- /**
- * Default Character Set
- * @var string
- */
- private $charset = 'UTF-8';
-
- /**
- * Template object instance
- * @var object
- */
- public $template = null;
-
- /**
- * A \Shield\Config object
- * @var object
- */
- private $config = null;
-
- /**
- * Init the object and create a Template instance
- *
- * @param object $di DI container
- */
- public function __construct(\Shield\Config $config, \Shield\Template $template)
- {
- //$this->template = new Template($di);
- $this->config = $config;
- $this->template = $template;
- $this->setViewDir();
-
- //parent::__construct($di);
- }
-
- /**
- * Set the directory to look for views in
- *
- * @param string $dir Direcotry path
- */
- public function setViewDir($dir=null)
- {
- // see if the path is valid
- $viewPath = ($dir !== null) ? $dir : __DIR__.'/../app/views';
-
- if (realpath($viewPath) !== false) {
- $this->_viewDir = realpath($viewPath);
- }
- return $this;
- }
-
- /**
- * Get the current path for view files
- *
- * @return string View path
- */
- public function getViewDir()
- {
- return $this->_viewDir;
- }
-
- /**
- * Set a new value into the view instance
- *
- * @param string $index String to replace
- * @param string $value Value for the view
- * @param bool $escape Whether to escape the value
- *
- * @return null
- */
- public function set($index, $value, $escape=true)
- {
- if (!is_array($index)) {
- $index = array($index => $value);
- }
- foreach ($index as $i => $value) {
- if ($escape === true) {
- // escape all values
- $value = htmlspecialchars($value, ENT_QUOTES);
- }
- $this->values[$i] = $value;
- }
-
- return $this;
- }
-
- /**
- * Get a value out of the currently set View values
- *
- * @param string $index Name of value to get
- *
- * @return mixed Found value or NULL
- */
- public function get($index)
- {
- return (isset($this->values[$index])) ? $this->values[$index] : null;
- }
-
- /**
- * Set the Content-Type for the View response
- *
- * @param string $type Content-Type
- */
- public function setContentType($type)
- {
- $this->contentType = $type;
- return $this;
- }
-
- /**
- * Get the current Content-Type value
- *
- * @return string Content-Type value
- */
- public function getContentType()
- {
- //$cfg = $this->di->get('Config', true)->get('view.content-type');
- $cfg = $this->config->get('view.content-type');
- return ($cfg !== null) ? $cfg : $this->contentType;
- }
-
- /**
- * Set the Character Set for the response
- *
- * @param string $charset Character set type
- */
- public function setCharset($charset)
- {
- $this->charset = $charset;
- return $this;
- }
-
- /**
- * Get the current Character Set valuse
- *
- * @return string Current Character Set
- */
- public function getCharset()
- {
- // see if its in the config first
- //$cfg = $this->di->get('Config', true)->get('view.charset');
- $cfg = $this->config->get('view.charset');
- return ($cfg !== null) ? $cfg : $this->charset;
- }
-
- /**
- * Get the complete list of View values
- *
- * @return array List of values (array)
- */
- private function getValues()
- {
- return $this->values;
- }
-
- /**
- * Render the view, do the substitution too
- *
- * @param string $content View contents
- *
- * @return string $content Formatted content
- */
- public function render($content)
- {
- $charset = $this->getCharset();
- $contentType = $this->getContentType();
-
- header('Content-Type: '.$contentType.'; charset='.$charset);
-
- foreach ($this->getValues() as $index => $value) {
- $content = str_replace('['.$index.']', $value, $content);
- }
- return $content;
- }
-}
@@ -1,56 +0,0 @@
-<?php
-
-namespace Shield;
-
-class ViewTest extends \PHPUnit_Framework_TestCase
-{
- private $_view = null;
- private $_di = null;
- private $_config = null;
-
- public function setUp()
- {
- $this->_di = new Di();
- $this->_config = new Config($this->_di);
- $template = new Template($this->_config);
-
- $this->_view = new View($this->_config, $template);
- }
- public function tearDown()
- {
- $this->_di = null;
- $this->_view = null;
- $this->_config = null;
- }
-
- /**
- * Test that a value is correctly set into the View
- *
- * @return null
- */
- public function testViewValueSet()
- {
- $value = 'testing123';
- $this->_view->set('test',$value);
- $this->assertEquals(
- $value,$this->_view->get('test')
- );
- }
-
- /**
- * Test that the templating replaces the value correctly
- *
- * @return null
- */
- public function testTemplateReplace()
- {
- $value = 'testing123';
- $this->_view->set('test',$value);
- $output = $this->_view->render('my test: [test]');
-
- $this->assertEquals(
- $output,'my test: testing123'
- );
- }
-
-}

0 comments on commit 89b9611

Please sign in to comment.