Subversion Repositories PHPX

Compare Revisions

Last modification

Ignore whitespace Rev 69 → Rev 70

/trunk/View.php
32,12 → 32,27
protected $_template_vars = array();
 
/**
* Stylesheets to be inserted into the <code>head</code> element
*
* @var array
*/
protected $_stylesheets = array();
 
/**
* Scripts to be inserted into the <code>head</code> or
* <code>body</code> element
*
* @var array
*/
protected $_scripts = array();
 
/**
* Creates a new view
*
* @param string $template
* Template resource path
*/
public function __construct($template)
public function __construct ($template)
{
$this->_template = $template;
}
50,7 → 65,7
* @param mixed $value
* Variable value
*/
public function __set($name, $value)
public function __set ($name, $value)
{
$this->_template_vars[$name] = $value;
}
61,7 → 76,7
* @param string $name
* Variable name
*/
public function __get($name)
public function __get ($name)
{
return $this->_template_vars[$name];
}
75,7 → 90,7
*
* @param mixed $value
*/
public function escape($value)
public function escape ($value)
{
if (is_array($value))
{
123,7 → 138,7
* @return mixed The assigned value (after possible HTML encoding)
* @see View::escape()
*/
public function assign($name, $value, $escape = false)
public function assign ($name, $value, $escape = false)
{
if ($escape)
{
135,6 → 150,54
}
 
/**
* Adds a CSS resource (stylesheet) to the list of external
* stylesheets
*
* @param string $uri
* Stylesheet URI
* @param mixed $key (optional)
* Array key for the script. May be used later to exclude
* or include the code for a specific stylesheet.
*/
public function addStylesheet ($uri, $key = null)
{
$stylesheets =& $this->_stylesheets;
 
if ($key !== null)
{
$stylesheets[$key] = $uri;
}
else
{
$stylesheets[] = $uri;
}
}
 
/**
* Adds an ECMAScript resource (script) to the list of external
* scripts
*
* @param string $uri
* Script URI
* @param mixed $key (optional)
* Array key for the script. May be used later to exclude
* or include the code for a specific script.
*/
public function addScript ($uri, $key = null)
{
$scripts =& $this->_scripts;
 
if ($key !== null)
{
$scripts[$key] = $uri;
}
else
{
$scripts[] = $uri;
}
}
 
/**
* Renders the view by including a template
*
* @param string $template
142,7 → 205,7
* If not provided, the default template ($template property) will be used.
* @throws Exception if no template has been defined before
*/
public function render($template = null, $content = null)
public function render ($template = null, $content = null)
{
if (!is_null($content))
{
167,9 → 230,67
}
 
/**
* Returns the code for including all stylesheets,
* with exclusions.
*
* @param array $exclusions (optional, future)
* The keys of the stylesheets that should be excluded
* @return string
*/
public function getStylesheets ($exclusions = array())
{
return (
implode(PHP_EOL, array_map(function ($uri) {
return '<link rel="stylesheet" href="' . $this->escape($uri) . '">';
}, array_diff_key($this->_stylesheets, array_flip($exclusions))))
. PHP_EOL);
}
 
/**
* Returns the code for including a specific stylesheet
*
* @param mixed $key
* @return string
*/
public function getStylesheet ($key)
{
return '<link rel="stylesheet" href="'
. $this->escape($this->_stylesheets[$key])
. '">' . PHP_EOL;
}
 
/**
* Returns the code for including all stylesheets,
* with exclusions.
*
* @param array $exclusions (optional, future)
* The keys of the scripts that should be excluded.
* Usually you would specify those scripts that you
* want to include with {@link #getScript()}.
* @return string
*/
public function getScripts ($exclusions = array())
{
return (
implode(PHP_EOL, array_map(function ($uri) {
return '<script type="text/javascript" src="'
. $this->escape($uri)
. '"></script>';
}, array_diff_key($this->_scripts, array_flip($exclusions))))
. PHP_EOL);
}
 
public function getScript ($key)
{
return '<link rel="stylesheet" href="'
. $this->escape($this->_scripts[$key])
. '">' . PHP_EOL;
}
 
/**
* Returns the content for insertion into the template
*/
public function getContent()
public function getContent ()
{
return $this->_content;
}
180,7 → 301,7
* @param int[optional] $id
* @see Application::getURL()
*/
public function getURL($controller = null, $action = null, $id = null)
public function getURL ($controller = null, $action = null, $id = null)
{
return Application::getInstance()->getURL($controller, $action, $id);
}
/trunk/Controller.php
44,7 → 44,7
*
* @see View::__construct()
*/
protected function __construct($viewClass = 'View', $template = null)
protected function __construct ($viewClass = 'View', $template = null)
{
$this->_view = new $viewClass($template);
 
73,29 → 73,33
}
 
/**
* Assigns a value to a template variable (after this,
* <var>$value</var> is available through
* <code>$this-><var>$name</var></code> in the view's template).
* <code>Controller</code>s should call this method instead of
* {@link View::assign()}.
*
* @param string $name
* Variable name
* @param mixed $value
* Variable value
* @param bool $encodeHTML
* If <code>true</code>, replace all potentially conflicting
* characters in <var>$value</var> with their HTML entity
* references. The default is <code>false</code>.
* @return mixed The assigned value (after possible HTML encoding)
* @see View::encodeHTML()
* (non-PHPDoc)
* @see View::assign()
*/
protected function assign($name, $value, $encodeHTML = false)
protected function assign ($name, $value, $encodeHTML = false)
{
return $this->_view->assign($name, $value, $encodeHTML);
}
 
/**
* (non-PHPDoc)
* @see View::addStylesheet()
*/
protected function addStylesheet ($uri, $key = null)
{
return $this->_view->addStylesheet($uri, $key);
}
 
/**
* (non-PHPDoc)
* @see View::addSscript()
*/
protected function addScript ($uri, $key = null)
{
return $this->_view->addScript ($uri, $key);
}
 
/**
* Renders the {@link View} associated with this controller
* by including the <code>View</code>'s template.
* <code>Controller</code>s should call this method instead of
107,7 → 111,7
* <code>View</code>'s <code>$template</code> property)
* will be used.
*/
public function render($template = null, $content = null)
public function render ($template = null, $content = null)
{
$this->_view->render($template, $content);
}