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() |