code
stringlengths 17
296k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public static function include_in_response(HTTPResponse $response)
{
Requirements::backend()->includeInResponse($response);
} | Attach requirements inclusion to X-Include-JS and X-Include-CSS headers on the given
HTTP Response
@param HTTPResponse $response | include_in_response | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public static function add_i18n_javascript($langDir, $return = false)
{
return Requirements::backend()->add_i18n_javascript($langDir, $return);
} | Add i18n files from the given javascript directory. SilverStripe expects that the given
directory will contain a number of JavaScript files named by language: en_US.js, de_DE.js,
etc.
@param string $langDir The JavaScript lang directory, relative to the site root, e.g.,
'framework/javascript/lang'
@param bool $return Return all relative file paths rather than including them in
requirements
@return array | add_i18n_javascript | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public static function get_combine_files()
{
return Requirements::backend()->getCombinedFiles();
} | Return all combined files; keys are the combined file names, values are lists of
associative arrays with 'files', 'type', and 'media' keys for details about this
combined file.
@return array | get_combine_files | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public static function delete_all_combined_files()
{
Requirements::backend()->deleteAllCombinedFiles();
} | Deletes all generated combined files in the configured combined files directory,
but doesn't delete the directory itself | delete_all_combined_files | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public static function process_combined_files()
{
Requirements::backend()->processCombinedFiles();
} | Do the heavy lifting involved in combining the combined files. | process_combined_files | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public static function get_write_js_to_body()
{
return Requirements::backend()->getWriteJavascriptToBody();
} | Set whether you want to write the JS to the body of the page rather than at the end of the
head tag.
@return bool | get_write_js_to_body | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public static function set_write_js_to_body($var)
{
Requirements::backend()->setWriteJavascriptToBody($var);
} | Set whether you want to write the JS to the body of the page rather than at the end of the
head tag.
@param bool $var | set_write_js_to_body | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public static function get_force_js_to_bottom()
{
return Requirements::backend()->getForceJSToBottom();
} | Get whether to force the JavaScript to end of the body. Useful if you use inline script tags
that don't rely on scripts included via {@link Requirements::javascript()).
@return bool | get_force_js_to_bottom | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public static function set_force_js_to_bottom($var)
{
Requirements::backend()->setForceJSToBottom($var);
} | Set whether to force the JavaScript to end of the body. Useful if you use inline script tags
that don't rely on scripts included via {@link Requirements::javascript()).
@param bool $var If true, force the JavaScript to be included at the bottom of the page | set_force_js_to_bottom | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public static function get_minify_combined_js_files()
{
return Requirements::backend()->getMinifyCombinedJSFiles();
} | Check if JS minification is enabled
@return bool | get_minify_combined_js_files | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public static function set_minify_combined_js_files($minify)
{
Requirements::backend()->setMinifyCombinedJSFiles($minify);
} | Enable or disable js minification
@param bool $minify | set_minify_combined_js_files | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public static function get_write_header_comments()
{
return Requirements::backend()->getWriteHeaderComment();
} | Check if header comments are written
@return bool | get_write_header_comments | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public function set_write_header_comments($write)
{
Requirements::backend()->setWriteHeaderComment($write);
} | Flag whether header comments should be written for each combined file
@param bool $write | set_write_header_comments | php | silverstripe/silverstripe-framework | src/View/Requirements.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php | BSD-3-Clause |
public function __construct($closedBlocks = [], $openBlocks = [])
{
parent::__construct(null);
$this->setClosedBlocks($closedBlocks);
$this->setOpenBlocks($openBlocks);
} | Allow the injection of new closed & open block callables
@param array $closedBlocks
@param array $openBlocks | __construct | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
function construct($matchrule, $name, $arguments = null)
{
Deprecation::noticeWithNoReplacment(
'5.4.0',
'Will be renamed to SilverStripe\TemplateEngine\SSTemplateParser',
Deprecation::SCOPE_CLASS
);
$res = parent::construct($matchrule, $name, $arguments);
if (!isset($res['php'])) {
$res['php'] = '';
}
return $res;
} | Override the function that constructs the result arrays to also prepare a 'php' item in the array | construct | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
public function addClosedBlock($name, $callable)
{
$this->validateExtensionBlock($name, $callable, 'Closed block');
$this->closedBlocks[$name] = $callable;
} | Add a closed block callable to allow <% name %><% end_name %> syntax
@param string $name The name of the token to be used in the syntax <% name %><% end_name %>
@param callable $callable The function that modifies the generation of template code
@throws InvalidArgumentException | addClosedBlock | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
public function addOpenBlock($name, $callable)
{
$this->validateExtensionBlock($name, $callable, 'Open block');
$this->openBlocks[$name] = $callable;
} | Add a closed block callable to allow <% name %> syntax
@param string $name The name of the token to be used in the syntax <% name %>
@param callable $callable The function that modifies the generation of template code
@throws InvalidArgumentException | addOpenBlock | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
function CallArguments_Argument(&$res, $sub)
{
if ($res['php'] !== '') {
$res['php'] .= ', ';
}
$res['php'] .= ($sub['ArgumentMode'] == 'default') ? $sub['string_php'] :
str_replace('$$FINAL', 'XML_val', $sub['php'] ?? '');
} | Values are bare words in templates, but strings in PHP. We rely on PHP's type conversion to back-convert
strings to numbers when needed. | CallArguments_Argument | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
function Lookup_AddLookupStep(&$res, $sub, $method)
{
$res['LookupSteps'][] = $sub;
$property = $sub['Call']['Method']['text'];
if (isset($sub['Call']['CallArguments']) && isset($sub['Call']['CallArguments']['php'])) {
$arguments = $sub['Call']['CallArguments']['php'];
$res['php'] .= "->$method('$property', [$arguments], true)";
} else {
$res['php'] .= "->$method('$property', null, true)";
}
} | The basic generated PHP of LookupStep and LastLookupStep is the same, except that LookupStep calls 'obj' to
get the next ViewableData in the sequence, and LastLookupStep calls different methods (XML_val, hasValue, obj)
depending on the context the lookup is used in. | Lookup_AddLookupStep | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
function Argument_DollarMarkedLookup(&$res, $sub)
{
$res['ArgumentMode'] = 'lookup';
$res['php'] = $sub['Lookup']['php'];
} | If we get a bare value, we don't know enough to determine exactly what php would be the translation, because
we don't know if the position of use indicates a lookup or a string argument.
Instead, we record 'ArgumentMode' as a member of this matches results node, which can be:
- lookup if this argument was unambiguously a lookup (marked as such)
- string is this argument was unambiguously a string (marked as such, or impossible to parse as lookup)
- default if this argument needs to be handled as per 2.4
In the case of 'default', there is no php member of the results node, but instead 'lookup_php', which
should be used by the parent if the context indicates a lookup, and 'string_php' which should be used
if the context indicates a string | Argument_DollarMarkedLookup | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
function ClosedBlock__construct(&$res)
{
$res['ArgumentCount'] = 0;
} | As mentioned in the parser comment, block handling is kept fairly generic for extensibility. The match rule
builds up two important elements in the match result array:
'ArgumentCount' - how many arguments were passed in the opening tag
'Arguments' an array of the Argument match rule result arrays
Once a block has successfully been matched against, it will then look for the actual handler, which should
be on this class (either defined or extended on) as ClosedBlock_Handler_Name(&$res), where Name is the
tag name, first letter captialized (i.e Control, Loop, With, etc).
This function will be called with the match rule result array as it's first argument. It should return
the php result of this block as it's return value, or throw an error if incorrect arguments were passed. | ClosedBlock__construct | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
function ClosedBlock_Handle_Loop(&$res)
{
if ($res['ArgumentCount'] > 1) {
throw new SSTemplateParseException('Too many arguments in control block. Must be one or no' .
'arguments only.', $this);
}
//loop without arguments loops on the current scope
if ($res['ArgumentCount'] == 0) {
$on = '$scope->locally()->obj(\'Me\', null, true)';
} else { //loop in the normal way
$arg = $res['Arguments'][0];
if ($arg['ArgumentMode'] == 'string') {
throw new SSTemplateParseException('Control block cant take string as argument.', $this);
}
$on = str_replace(
'$$FINAL',
'obj',
($arg['ArgumentMode'] == 'default') ? $arg['lookup_php'] : $arg['php']
);
}
return
$on . '; $scope->pushScope(); while (($key = $scope->next()) !== false) {' . PHP_EOL .
$res['Template']['php'] . PHP_EOL .
'}; $scope->popScope(); ';
} | This is an example of a block handler function. This one handles the loop tag. | ClosedBlock_Handle_Loop | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
function ClosedBlock_Handle_With(&$res)
{
if ($res['ArgumentCount'] != 1) {
throw new SSTemplateParseException('Either no or too many arguments in with block. Must be one ' .
'argument only.', $this);
}
$arg = $res['Arguments'][0];
if ($arg['ArgumentMode'] == 'string') {
throw new SSTemplateParseException('Control block cant take string as argument.', $this);
}
$on = str_replace('$$FINAL', 'obj', ($arg['ArgumentMode'] == 'default') ? $arg['lookup_php'] : $arg['php']);
return
$on . '; $scope->pushScope();' . PHP_EOL .
$res['Template']['php'] . PHP_EOL .
'; $scope->popScope(); ';
} | The closed block handler for with blocks | ClosedBlock_Handle_With | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
function OpenBlock_Handle_Base_tag(&$res)
{
if ($res['ArgumentCount'] != 0) {
throw new SSTemplateParseException('Base_tag takes no arguments', $this);
}
$code = '$isXhtml = preg_match(\'/<!DOCTYPE[^>]+xhtml/i\', $val);';
$code .= PHP_EOL . '$val .= \\SilverStripe\\View\\SSViewer::getBaseTag($isXhtml);';
return $code;
} | This is an open block handler, for the <% base_tag %> tag | OpenBlock_Handle_Base_tag | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
function OpenBlock_Handle_Current_page(&$res)
{
if ($res['ArgumentCount'] != 0) {
throw new SSTemplateParseException('Current_page takes no arguments', $this);
}
return '$val .= $_SERVER[SCRIPT_URL];';
} | This is an open block handler, for the <% current_page %> tag | OpenBlock_Handle_Current_page | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
function TopTemplate__construct(&$res)
{
$res['php'] = "<?php" . PHP_EOL;
} | The TopTemplate also includes the opening stanza to start off the template | TopTemplate__construct | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
public function compileString($string, $templateName = "", $includeDebuggingComments = false, $topTemplate = true)
{
if (!trim($string ?? '')) {
$code = '';
} else {
parent::__construct($string);
$this->includeDebuggingComments = $includeDebuggingComments;
// Ignore UTF8 BOM at beginning of string. TODO: Confirm this is needed, make sure SSViewer handles UTF
// (and other encodings) properly
if (substr($string ?? '', 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) {
$this->pos = 3;
}
// Match the source against the parser
if ($topTemplate) {
$result = $this->match_TopTemplate();
} else {
$result = $this->match_Template();
}
if (!$result) {
throw new SSTemplateParseException('Unexpected problem parsing template', $this);
}
// Get the result
$code = $result['php'];
}
// Include top level debugging comments if desired
if ($includeDebuggingComments && $templateName && stripos($code ?? '', "<?xml") === false) {
$code = $this->includeDebuggingComments($code, $templateName);
}
return $code;
} | Compiles some passed template source code into the php code that will execute as per the template source.
@throws SSTemplateParseException
@param string $string The source of the template
@param string $templateName The name of the template, normally the filename the template source was loaded from
@param bool $includeDebuggingComments True is debugging comments should be included in the output
@param bool $topTemplate True if this is a top template, false if it's just a template
@return mixed|string The php that, when executed (via include or exec) will behave as per the template source | compileString | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
public function compileFile($template)
{
return $this->compileString(file_get_contents($template ?? ''), $template);
} | Compiles some file that contains template source code, and returns the php code that will execute as per that
source
@static
@param $template - A file path that contains template source code
@return mixed|string - The php that, when executed (via include or exec) will behave as per the template source | compileFile | php | silverstripe/silverstripe-framework | src/View/SSTemplateParser.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParser.php | BSD-3-Clause |
public function getAssetHandler()
{
return $this->assetHandler;
} | Gets the backend storage for generated files
@return GeneratedAssetHandler | getAssetHandler | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function setAssetHandler(GeneratedAssetHandler $handler)
{
$this->assetHandler = $handler;
} | Set a new asset handler for this backend
@param GeneratedAssetHandler $handler | setAssetHandler | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function setCombinedFilesEnabled($enable)
{
$this->combinedFilesEnabled = (bool)$enable;
} | Enable or disable the combination of CSS and JavaScript files
@param bool $enable | setCombinedFilesEnabled | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getWriteHeaderComment()
{
return $this->writeHeaderComment;
} | Check if header comments are written
@return bool | getWriteHeaderComment | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function setWriteHeaderComment($write)
{
$this->writeHeaderComment = $write;
return $this;
} | Flag whether header comments should be written for each combined file
@param bool $write
@return $this | setWriteHeaderComment | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function setCombinedFilesFolder($folder)
{
$this->combinedFilesFolder = $folder;
} | Set the folder to save combined files in. By default they're placed in _combinedfiles,
however this may be an issue depending on your setup, especially for CSS files which often
contain relative paths.
This must not include any 'assets' prefix
@param string $folder | setCombinedFilesFolder | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getCombinedFilesFolder()
{
if ($this->combinedFilesFolder) {
return $this->combinedFilesFolder;
}
return Config::inst()->get(__CLASS__, 'default_combined_files_folder');
} | Retrieve the combined files folder prefix
@return string | getCombinedFilesFolder | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function setSuffixRequirements($var)
{
$this->suffixRequirements = $var;
} | Set whether to add caching query params to the requests for file-based requirements.
Eg: themes/myTheme/js/main.js?m=123456789. The parameter is a timestamp generated by
filemtime. This has the benefit of allowing the browser to cache the URL infinitely,
while automatically busting this cache every time the file is changed.
@param bool $var | setSuffixRequirements | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getSuffixRequirements()
{
return $this->suffixRequirements;
} | Check whether we want to suffix requirements
@return bool | getSuffixRequirements | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function setWriteJavascriptToBody($var)
{
$this->writeJavascriptToBody = $var;
return $this;
} | Set whether you want to write the JS to the body of the page rather than at the end of the
head tag.
@param bool $var
@return $this | setWriteJavascriptToBody | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getWriteJavascriptToBody()
{
return $this->writeJavascriptToBody;
} | Check whether you want to write the JS to the body of the page rather than at the end of the
head tag.
@return bool | getWriteJavascriptToBody | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function setForceJSToBottom($var)
{
$this->forceJSToBottom = $var;
return $this;
} | Forces the JavaScript requirements to the end of the body, right before the closing tag
@param bool $var
@return $this | setForceJSToBottom | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getForceJSToBottom()
{
return $this->forceJSToBottom;
} | Check if the JavaScript requirements are written to the end of the body, right before the closing tag
@return bool | getForceJSToBottom | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function javascript($file, $options = [])
{
$file = ModuleResourceLoader::singleton()->resolvePath($file);
// Get type
$type = null;
if (isset($this->javascript[$file]['type'])) {
$type = $this->javascript[$file]['type'];
}
if (isset($options['type'])) {
$type = $options['type'];
}
// make sure that async/defer is set if it is set once even if file is included multiple times
$async = (
isset($options['async']) && $options['async']
|| (
isset($this->javascript[$file])
&& isset($this->javascript[$file]['async'])
&& $this->javascript[$file]['async']
)
);
$defer = (
isset($options['defer']) && $options['defer']
|| (
isset($this->javascript[$file])
&& isset($this->javascript[$file]['defer'])
&& $this->javascript[$file]['defer']
)
);
$integrity = $options['integrity'] ?? null;
$crossorigin = $options['crossorigin'] ?? null;
$this->javascript[$file] = [
'async' => $async,
'defer' => $defer,
'type' => $type,
'integrity' => $integrity,
'crossorigin' => $crossorigin,
];
// Record scripts included in this file
if (isset($options['provides'])) {
$this->providedJavascript[$file] = array_values($options['provides'] ?? []);
}
} | Register the given JavaScript file as required.
@param string $file Either relative to docroot or in the form "vendor/package:resource"
@param array $options List of options. Available options include:
- 'provides' : List of scripts files included in this file
- 'async' : Boolean value to set async attribute to script tag
- 'defer' : Boolean value to set defer attribute to script tag
- 'type' : Override script type= value.
- 'integrity' : SubResource Integrity hash
- 'crossorigin' : Cross-origin policy for the resource | javascript | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
protected function unsetJavascript($file)
{
unset($this->javascript[$file]);
} | Remove a javascript requirement
@param string $file | unsetJavascript | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getProvidedScripts()
{
$providedScripts = [];
$includedScripts = [];
foreach ($this->javascript as $script => $options) {
// Ignore scripts that are explicitly blocked
if (isset($this->blocked[$script])) {
continue;
}
// At this point, the file is included.
// This might also be combined at this point, potentially.
$includedScripts[$script] = true;
// Record any files this provides, EXCEPT those already included by now
if (isset($this->providedJavascript[$script])) {
foreach ($this->providedJavascript[$script] as $provided) {
if (!isset($includedScripts[$provided])) {
$providedScripts[$provided] = $provided;
}
}
}
}
return $providedScripts;
} | Gets all scripts that are already provided by prior scripts.
This follows these rules:
- Files will not be considered provided if they are separately
included prior to the providing file.
- Providing files can be blocked, and don't provide anything
- Provided files can't be blocked (you need to block the provider)
- If a combined file includes files that are provided by prior
scripts, then these should be excluded from the combined file.
- If a combined file includes files that are provided by later
scripts, then these files should be included in the combined
file, but we can't block the later script either (possible double
up of file).
@return array Array of provided files (map of $path => $path) | getProvidedScripts | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getJavascript()
{
return array_diff_key(
$this->javascript ?? [],
$this->getBlocked(),
$this->getProvidedScripts()
);
} | Returns an array of required JavaScript, excluding blocked
and duplicates of provided files.
@return array | getJavascript | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
protected function getAllJavascript()
{
return $this->javascript;
} | Gets all javascript, including blocked files. Unwraps the array into a non-associative list
@return array Indexed array of javascript files | getAllJavascript | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function customScript($script, $uniquenessID = null)
{
if ($uniquenessID) {
if (isset($this->customScriptAttributes[$uniquenessID])) {
unset($this->customScriptAttributes[$uniquenessID]);
}
$this->customScript[$uniquenessID] = $script;
} else {
$this->customScript[] = $script;
}
} | Register the given JavaScript code into the list of requirements
@param string $script The script content as a string (without enclosing `<script>` tag)
@param string $uniquenessID A unique ID that ensures a piece of code is only added once | customScript | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function customScriptWithAttributes(string $script, array $attributes = [], string|int|null $uniquenessID = null)
{
$attrs = [];
foreach (['type', 'crossorigin'] as $attrKey) {
if (isset($attributes[$attrKey])) {
$attrs[$attrKey] = strtolower($attributes[$attrKey]);
}
}
if ($uniquenessID) {
$this->customScript[$uniquenessID] = $script;
$this->customScriptAttributes[$uniquenessID] = $attrs;
} else {
$this->customScript[] = $script;
$index = count($this->customScript) - 1;
$this->customScriptAttributes[$index] = $attrs;
}
} | Register the given Javascript code into the list of requirements with optional tag
attributes.
@param string $script The script content as a string (without enclosing `<script>` tag)
@param array $options List of options. Available options include:
- 'type' : Specifies the type of script
- 'crossorigin' : Cross-origin policy for the resource
@param string|int $uniquenessID A unique ID that ensures a piece of code is only added once | customScriptWithAttributes | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getCustomScripts()
{
return array_diff_key($this->customScript ?? [], $this->blocked);
} | Return all registered custom scripts
@return array | getCustomScripts | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function customCSS($script, $uniquenessID = null)
{
if ($uniquenessID) {
$this->customCSS[$uniquenessID] = $script;
} else {
$this->customCSS[] = $script;
}
} | Register the given CSS styles into the list of requirements
@param string $script CSS selectors as a string (without enclosing `<style>` tag)
@param string $uniquenessID A unique ID that ensures a piece of code is only added once | customCSS | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getCustomCSS()
{
return array_diff_key($this->customCSS ?? [], $this->blocked);
} | Return all registered custom CSS
@return array | getCustomCSS | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function insertHeadTags($html, $uniquenessID = null)
{
if ($uniquenessID) {
$this->customHeadTags[$uniquenessID] = $html;
} else {
$this->customHeadTags[] = $html;
}
} | Add the following custom HTML code to the `<head>` section of the page
@param string $html Custom HTML code
@param string $uniquenessID A unique ID that ensures a piece of code is only added once | insertHeadTags | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function css($file, $media = null, $options = [])
{
$file = ModuleResourceLoader::singleton()->resolvePath($file);
$integrity = $options['integrity'] ?? null;
$crossorigin = $options['crossorigin'] ?? null;
$this->css[$file] = [
"media" => $media,
"integrity" => $integrity,
"crossorigin" => $crossorigin,
];
} | Register the given stylesheet into the list of requirements.
@param string $file The CSS file to load, relative to site root
@param string $media Comma-separated list of media types to use in the link tag
(e.g. 'screen,projector')
@param array $options List of options. Available options include:
- 'integrity' : SubResource Integrity hash
- 'crossorigin' : Cross-origin policy for the resource | css | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getCSS()
{
return array_diff_key($this->css ?? [], $this->blocked);
} | Get the list of registered CSS file requirements, excluding blocked files
@return array Associative array of file to spec | getCSS | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
protected function getAllCSS()
{
return $this->css;
} | Gets all CSS files requirements, including blocked
@return array Associative array of file to spec | getAllCSS | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getBlocked()
{
return $this->blocked;
} | Gets the list of all blocked files
@return array | getBlocked | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function clear($fileOrID = null)
{
$types = [
'javascript',
'css',
'customScript',
'customCSS',
'customHeadTags',
'combinedFiles',
];
foreach ($types as $type) {
if ($fileOrID) {
if (isset($this->{$type}[$fileOrID])) {
$this->disabled[$type][$fileOrID] = $this->{$type}[$fileOrID];
unset($this->{$type}[$fileOrID]);
}
} else {
$this->disabled[$type] = $this->{$type};
$this->{$type} = [];
}
}
} | Clear either a single or all requirements
Caution: Clearing single rules added via customCSS and customScript only works if you
originally specified a $uniquenessID.
@param string|int $fileOrID | clear | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function restore()
{
$types = [
'javascript',
'css',
'customScript',
'customCSS',
'customHeadTags',
'combinedFiles',
];
foreach ($types as $type) {
$this->{$type} = $this->disabled[$type];
}
} | Restore requirements cleared by call to Requirements::clear | restore | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function unblock($fileOrID)
{
unset($this->blocked[$fileOrID]);
} | Remove an item from the block list
@param string|int $fileOrID | unblock | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function unblockAll()
{
$this->blocked = [];
} | Removes all items from the block list | unblockAll | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
protected function insertScriptsAtBottom($jsRequirements, $content)
{
// Forcefully put the scripts at the bottom of the body instead of before the first
// script tag.
$content = preg_replace(
'/(<\/body[^>]*>)/i',
$this->escapeReplacement($jsRequirements) . '\\1',
$content ?? ''
);
return $content;
} | Given a block of HTML, insert the given scripts at the bottom before
the closing `</body>` tag
@param string $jsRequirements String containing one or more javascript `<script />` tags
@param string $content HTML body
@return string Merged HTML | insertScriptsAtBottom | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
protected function insertScriptsIntoBody($jsRequirements, $content)
{
// If your template already has script tags in the body, then we try to put our script
// tags just before those. Otherwise, we put it at the bottom.
$bodyTagPosition = stripos($content ?? '', '<body');
$scriptTagPosition = stripos($content ?? '', '<script', $bodyTagPosition ?? 0);
$commentTags = [];
$canWriteToBody = ($scriptTagPosition !== false)
&&
// Check that the script tag is not inside a html comment tag
!(
preg_match('/.*(?|(<!--)|(-->))/U', $content ?? '', $commentTags, 0, $scriptTagPosition ?? 0)
&&
$commentTags[1] == '-->'
);
if ($canWriteToBody) {
// Insert content before existing script tags
$content = substr($content ?? '', 0, $scriptTagPosition)
. $jsRequirements
. substr($content ?? '', $scriptTagPosition ?? 0);
} else {
// Insert content at bottom of page otherwise
$content = $this->insertScriptsAtBottom($jsRequirements, $content);
}
return $content;
} | Given a block of HTML, insert the given scripts inside the `<body></body>`
@param string $jsRequirements String containing one or more javascript `<script />` tags
@param string $content HTML body
@return string Merged HTML | insertScriptsIntoBody | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
protected function insertTagsIntoHead($jsRequirements, $content)
{
$content = preg_replace(
'/(<\/head>)/i',
$this->escapeReplacement($jsRequirements) . '\\1',
$content ?? ''
);
return $content;
} | Given a block of HTML, insert the given code inside the `<head></head>` block
@param string $jsRequirements String containing one or more html tags
@param string $content HTML body
@return string Merged HTML | insertTagsIntoHead | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
protected function escapeReplacement($replacement)
{
return addcslashes($replacement ?? '', '\\$');
} | Safely escape a literal string for use in preg_replace replacement
@param string $replacement
@return string | escapeReplacement | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
protected function pathForFile($fileOrUrl)
{
// Since combined urls could be root relative, treat them as urls here.
if (preg_match('{^(//)|(http[s]?:)}', $fileOrUrl ?? '') || Director::is_root_relative_url($fileOrUrl)) {
return $fileOrUrl;
} else {
return Injector::inst()->get(ResourceURLGenerator::class)->urlForResource($fileOrUrl);
}
} | Finds the path for specified file
@param string $fileOrUrl
@return string|bool | pathForFile | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
protected function parseCombinedFile($file)
{
// Array with path and type keys
if (is_array($file) && isset($file['path']) && isset($file['type'])) {
return [$file['path'], $file['type']];
}
// Extract value from indexed array
if (is_array($file)) {
$path = array_shift($file);
// See if there's a type specifier
if ($file) {
$type = array_shift($file);
return [$path, $type];
}
// Otherwise convent to string
$file = $path;
}
$type = File::get_file_extension($file);
return [$file, $type];
} | Return path and type of given combined file
@param string|array $file Either a file path, or an array spec
@return array array with two elements, path and type of file | parseCombinedFile | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getCombinedFiles()
{
return array_diff_key($this->combinedFiles ?? [], $this->blocked);
} | Return all combined files; keys are the combined file names, values are lists of
associative arrays with 'files', 'type', and 'media' keys for details about this
combined file.
@return array | getCombinedFiles | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
protected function getAllCombinedFiles()
{
return $this->combinedFiles;
} | Includes all combined files, including blocked ones
@return array | getAllCombinedFiles | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function clearCombinedFiles()
{
$this->combinedFiles = [];
} | Clear all registered CSS and JavaScript file combinations | clearCombinedFiles | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
protected function hashedCombinedFilename($combinedFile, $fileList)
{
$name = pathinfo($combinedFile ?? '', PATHINFO_FILENAME);
$hash = $this->hashOfFiles($fileList);
$extension = File::get_file_extension($combinedFile);
return $name . '-' . substr($hash ?? '', 0, 7) . '.' . $extension;
} | Given a filename and list of files, generate a new filename unique to these files
@param string $combinedFile
@param array $fileList
@return string | hashedCombinedFilename | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function getCombinedFilesEnabled()
{
if (isset($this->combinedFilesEnabled)) {
return $this->combinedFilesEnabled;
}
// Non-dev sites are always combined
if (!Director::isDev()) {
return true;
}
// Fallback to default
return Config::inst()->get(__CLASS__, 'combine_in_dev');
} | Check if combined files are enabled
@return bool | getCombinedFilesEnabled | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function themedCSS($name, $media = null)
{
$path = ThemeResourceLoader::inst()->findThemedCSS($name, SSViewer::get_themes());
if ($path) {
$this->css($path, $media);
} else {
throw new InvalidArgumentException(
"The css file doesn't exist. Please check if the file $name.css exists in any context or search for "
. "themedCSS references calling this file in your templates."
);
}
} | Registers the given themeable stylesheet as required.
A CSS file in the current theme path name 'themename/css/$name.css' is first searched for,
and it that doesn't exist and the module parameter is set then a CSS file with that name in
the module is used.
@param string $name The name of the file - eg '/css/File.css' would have the name 'File'
@param string $media Comma-separated list of media types to use in the link tag
(e.g. 'screen,projector') | themedCSS | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function themedJavascript($name, $type = null)
{
$path = ThemeResourceLoader::inst()->findThemedJavascript($name, SSViewer::get_themes());
if ($path) {
$opts = [];
if ($type) {
$opts['type'] = $type;
}
$this->javascript($path, $opts);
} else {
throw new InvalidArgumentException(
"The javascript file doesn't exist. Please check if the file $name.js exists in any "
. "context or search for themedJavascript references calling this file in your templates."
);
}
} | Registers the given themeable javascript as required.
A javascript file in the current theme path name 'themename/javascript/$name.js' is first searched for,
and it that doesn't exist and the module parameter is set then a javascript file with that name in
the module is used.
@param string $name The name of the file - eg '/js/File.js' would have the name 'File'
@param string $type Comma-separated list of types to use in the script tag
(e.g. 'text/javascript,text/ecmascript') | themedJavascript | php | silverstripe/silverstripe-framework | src/View/Requirements_Backend.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements_Backend.php | BSD-3-Clause |
public function __construct($base, $project = null, CacheFactory $cacheFactory = null)
{
$this->base = $base;
$this->project = $project;
$this->cacheFactory = $cacheFactory;
} | Constructs a new template manifest. The manifest is not actually built
or loaded from cache until needed.
@param string $base The base path.
@param string $project Path to application code
@param CacheFactory $cacheFactory Cache factory to generate backend cache with | __construct | php | silverstripe/silverstripe-framework | src/View/ThemeManifest.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/ThemeManifest.php | BSD-3-Clause |
public function getCacheKey($includeTests = false)
{
return sha1(sprintf(
"manifest-%s-%s-%u",
$this->base,
$this->project,
$includeTests
));
} | Generate a unique cache key to avoid manifest cache collisions.
We compartmentalise based on the base path, the given project, and whether
or not we intend to include tests.
@param bool $includeTests
@return string | getCacheKey | php | silverstripe/silverstripe-framework | src/View/ThemeManifest.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/ThemeManifest.php | BSD-3-Clause |
public function handleDirectory($basename, $pathname, $depth)
{
if ($basename !== ThemeManifest::TEMPLATES_DIR) {
return;
}
$dir = trim(substr(dirname($pathname ?? ''), strlen($this->base ?? '')), '/\\');
$this->themes[] = "/" . $dir;
} | Add a directory to the manifest
@param string $basename
@param string $pathname
@param int $depth | handleDirectory | php | silverstripe/silverstripe-framework | src/View/ThemeManifest.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/ThemeManifest.php | BSD-3-Clause |
public function getAttribute($name)
{
$attributes = $this->getAttributes();
if (isset($attributes[$name])) {
return $attributes[$name];
}
return null;
} | Retrieve the value of an HTML attribute
@param string $name
@return mixed|null | getAttribute | php | silverstripe/silverstripe-framework | src/View/AttributesHTML.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/AttributesHTML.php | BSD-3-Clause |
public function getAttributes()
{
$defaultAttributes = $this->getDefaultAttributes();
$attributes = array_merge($defaultAttributes, $this->attributes);
if (method_exists($this, 'extend')) {
$this->extend('updateAttributes', $attributes);
}
return $attributes;
} | Allows customization through an 'updateAttributes' hook on the base class.
Existing attributes are passed in as the first argument and can be manipulated,
but any attributes added through a subclass implementation won't be included.
@return array | getAttributes | php | silverstripe/silverstripe-framework | src/View/AttributesHTML.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/AttributesHTML.php | BSD-3-Clause |
public function __construct($templates, TemplateParser $parser = null)
{
if ($parser) {
Deprecation::noticeWithNoReplacment('5.4.0', 'The $parser parameter is deprecated and will be removed');
$this->setParser($parser);
}
$this->setTemplate($templates);
if (!$this->chosen) {
$message = 'None of the following templates could be found: ';
$message .= print_r($templates, true);
$themes = SSViewer::get_themes();
if (!$themes) {
$message .= ' (no theme in use)';
} else {
$message .= ' in themes "' . print_r($themes, true) . '"';
}
user_error($message ?? '', E_USER_WARNING);
}
} | @param string|array $templates If passed as a string with .ss extension, used as the "main" template.
If passed as an array, it can be used for template inheritance (first found template "wins").
Usually the array values are PHP class names, which directly correlate to template names.
<code>
array('MySpecificPage', 'MyPage', 'Page')
</code>
@param TemplateParser $parser | __construct | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public static function flush()
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flush()');
SSViewer::flush_template_cache(true);
SSViewer::flush_cacheblock_cache(true);
} | Triggered early in the request when someone requests a flush.
@deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flush() | flush | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public static function fromString($content, $cacheTemplate = null)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::renderString()');
$viewer = SSViewer_FromString::create($content);
if ($cacheTemplate !== null) {
$viewer->setCacheTemplate($cacheTemplate);
}
return $viewer;
} | Create a template from a string instead of a .ss file
@param string $content The template content
@param bool|void $cacheTemplate Whether or not to cache the template from string
@return SSViewer
@deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::renderString() | fromString | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public static function set_themes($themes = [])
{
static::$current_themes = $themes;
} | Assign the list of active themes to apply.
If default themes should be included add $default as the last entry.
@param array $themes | set_themes | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public static function add_themes($themes = [])
{
$currentThemes = SSViewer::get_themes();
$finalThemes = array_merge($themes, $currentThemes);
// array_values is used to ensure sequential array keys as array_unique can leave gaps
static::set_themes(array_values(array_unique($finalThemes ?? [])));
} | Add to the list of active themes to apply
@param array $themes | add_themes | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public static function topLevel()
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.');
if (SSViewer::$topLevel) {
return SSViewer::$topLevel[sizeof(SSViewer::$topLevel)-1];
}
return null;
} | Get the current item being processed
@return ViewableData
@deprecated 5.4.0 Will be removed without equivalent functionality to replace it. | topLevel | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public function getRewriteHashLinks()
{
if (isset($this->rewriteHashlinks)) {
return $this->rewriteHashlinks;
}
return static::getRewriteHashLinksDefault();
} | Check if rewrite hash links are enabled on this instance
@return bool | getRewriteHashLinks | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public function setRewriteHashLinks($rewrite)
{
$this->rewriteHashlinks = $rewrite;
return $this;
} | Set if hash links are rewritten for this instance
@param bool $rewrite
@return $this | setRewriteHashLinks | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public static function getRewriteHashLinksDefault()
{
// Check if config overridden
if (isset(static::$current_rewrite_hash_links)) {
return static::$current_rewrite_hash_links;
}
return Config::inst()->get(static::class, 'rewrite_hash_links');
} | Get default value for rewrite hash links for all modules
@return bool | getRewriteHashLinksDefault | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public static function setRewriteHashLinksDefault($rewrite)
{
static::$current_rewrite_hash_links = $rewrite;
} | Set default rewrite hash links
@param bool $rewrite | setRewriteHashLinksDefault | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public static function chooseTemplate($templates)
{
Deprecation::noticeWithNoReplacment('5.4.0');
return ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes());
} | Find the template to use for a given list
@param array|string $templates
@return string
@deprecated 5.4.0 Will be removed without equivalent functionality to replace it | chooseTemplate | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public function setParser(TemplateParser $parser)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::setParser()');
$this->parser = $parser;
} | Set the template parser that will be used in template generation
@param TemplateParser $parser
@deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::setParser() | setParser | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public function getParser()
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::getParser()');
if (!$this->parser) {
$this->setParser(Injector::inst()->get('SilverStripe\\View\\SSTemplateParser'));
}
return $this->parser;
} | Returns the parser that is set for template generation
@return TemplateParser
@deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::getParser() | getParser | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public static function hasTemplate($templates)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::hasTemplate()');
return (bool)ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes());
} | Returns true if at least one of the listed templates exists.
@param array|string $templates
@return bool
@deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::hasTemplate() | hasTemplate | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public static function flush_template_cache($force = false)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flushTemplateCache()');
if (!SSViewer::$template_cache_flushed || $force) {
$dir = dir(TEMP_PATH);
while (false !== ($file = $dir->read())) {
if (strstr($file ?? '', '.cache')) {
unlink(TEMP_PATH . DIRECTORY_SEPARATOR . $file);
}
}
SSViewer::$template_cache_flushed = true;
}
} | Clears all parsed template files in the cache folder.
Can only be called once per request (there may be multiple SSViewer instances).
@param bool $force Set this to true to force a re-flush. If left to false, flushing
may only be performed once a request.
@deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flushTemplateCache() | flush_template_cache | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public static function flush_cacheblock_cache($force = false)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flushCacheBlockCache()');
if (!SSViewer::$cacheblock_cache_flushed || $force) {
$cache = Injector::inst()->get(CacheInterface::class . '.cacheblock');
$cache->clear();
SSViewer::$cacheblock_cache_flushed = true;
}
} | Clears all partial cache blocks.
Can only be called once per request (there may be multiple SSViewer instances).
@param bool $force Set this to true to force a re-flush. If left to false, flushing
may only be performed once a request.
@deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::flushCacheBlockCache() | flush_cacheblock_cache | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public function setPartialCacheStore($cache)
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::setPartialCacheStore()');
$this->partialCacheStore = $cache;
} | Set the cache object to use when storing / retrieving partial cache blocks.
@param CacheInterface $cache
@deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::setPartialCacheStore() | setPartialCacheStore | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public function getPartialCacheStore()
{
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::getPartialCacheStore()');
if ($this->partialCacheStore) {
return $this->partialCacheStore;
}
return Injector::inst()->get(CacheInterface::class . '.cacheblock');
} | Get the cache object to use when storing / retrieving partial cache blocks.
@return CacheInterface
@deprecated 5.4.0 Will be replaced with SilverStripe\TemplateEngine\SSTemplateEngine::getPartialCacheStore() | getPartialCacheStore | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public function includeRequirements($incl = true)
{
$this->includeRequirements = $incl;
} | Flag whether to include the requirements in this response.
@param bool $incl | includeRequirements | php | silverstripe/silverstripe-framework | src/View/SSViewer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer.php | BSD-3-Clause |
public function __isset($property)
{
// getField() isn't a field-specific getter and shouldn't be treated as such
if (strtolower($property ?? '') !== 'field' && $this->hasMethod("get$property")) {
return true;
}
if ($this->hasField($property)) {
return true;
}
if ($this->failover) {
return isset($this->failover->$property);
}
return false;
} | Check if a field exists on this object or its failover.
Note that, unlike the core isset() implementation, this will return true if the property is defined
and set to null.
@param string $property
@return bool | __isset | php | silverstripe/silverstripe-framework | src/View/ViewableData.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/ViewableData.php | BSD-3-Clause |
public function __get($property)
{
// getField() isn't a field-specific getter and shouldn't be treated as such
$method = "get$property";
if (strtolower($property ?? '') !== 'field' && $this->hasMethod($method) && $this->isAccessibleMethod($method)) {
return $this->$method();
}
if ($this->hasField($property)) {
return $this->getField($property);
}
if ($this->failover) {
return $this->failover->$property;
}
return null;
} | Get the value of a property/field on this object. This will check if a method called get{$property} exists, then
check if a field is available using {@link ViewableData::getField()}, then fall back on a failover object.
@param string $property
@return mixed | __get | php | silverstripe/silverstripe-framework | src/View/ViewableData.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/ViewableData.php | BSD-3-Clause |
public function __set($property, $value)
{
$this->objCacheClear();
$method = "set$property";
if ($this->hasMethod($method) && $this->isAccessibleMethod($method)) {
$this->$method($value);
} else {
$this->setField($property, $value);
}
} | Set a property/field on this object. This will check for the existence of a method called set{$property}, then
use the {@link ViewableData::setField()} method.
@param string $property
@param mixed $value | __set | php | silverstripe/silverstripe-framework | src/View/ViewableData.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/ViewableData.php | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.