Subversion Repositories PHPX

Compare Revisions

Last modification

Regard whitespace Rev 69 → Rev 70

/trunk/View.php
32,6 → 32,21
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
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
167,6 → 230,64
}
 
/**
* 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()
/trunk/Controller.php
73,22 → 73,8
}
 
/**
* 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)
{
96,6 → 82,24
}
 
/**
* (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