code
stringlengths
17
247k
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
protected function cacheIteratorProperties() { if (SSViewer_DataPresenter::$iteratorProperties !== null) { return; } SSViewer_DataPresenter::$iteratorProperties = $this->getPropertiesFromProvider( TemplateIteratorProvider::class, 'get_template_iterator_variables', true // Call non-statically ); }
Build cache of global iterator properties
cacheIteratorProperties
php
silverstripe/silverstripe-framework
src/View/SSViewer_DataPresenter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_DataPresenter.php
BSD-3-Clause
public function getInjectedValue($property, array $params, $cast = true) { // Get source for this value $result = $this->getValueSource($property); if (!array_key_exists('source', $result)) { return null; } // Look up the value - either from a callable, or from a directly provided value $source = $result['source']; $res = []; if (isset($source['callable'])) { $res['value'] = $source['callable'](...$params); } elseif (array_key_exists('value', $source)) { $res['value'] = $source['value']; } else { throw new InvalidArgumentException( "Injected property $property doesn't have a value or callable value source provided" ); } // If we want to provide a casted object, look up what type object to use if ($cast) { $res['obj'] = $this->castValue($res['value'], $source); } return $res; }
Look up injected value - it may be part of an "overlay" (arguments passed to <% include %>), set on the current item, part of an "underlay" ($Layout or $Content), or an iterator/global property @param string $property Name of property @param array $params @param bool $cast If true, an object is always returned even if not an object. @return array|null
getInjectedValue
php
silverstripe/silverstripe-framework
src/View/SSViewer_DataPresenter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_DataPresenter.php
BSD-3-Clause
public function pushScope() { $scope = parent::pushScope(); $upIndex = $this->getUpIndex() ?: 0; $itemStack = $this->getItemStack(); $itemStack[$upIndex][SSViewer_Scope::ITEM_OVERLAY] = $this->overlay; $this->setItemStack($itemStack); // Remove the overlay when we're changing to a new scope, as values in // that scope take priority. The exceptions that set this flag are $Up // and $Top as they require that the new scope inherits the overlay if (!$this->preserveOverlay) { $this->overlay = []; } return $scope; }
Store the current overlay (as it doesn't directly apply to the new scope that's being pushed). We want to store the overlay against the next item "up" in the stack (hence upIndex), rather than the current item, because SSViewer_Scope::obj() has already been called and pushed the new item to the stack by this point @return SSViewer_Scope
pushScope
php
silverstripe/silverstripe-framework
src/View/SSViewer_DataPresenter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_DataPresenter.php
BSD-3-Clause
public function popScope() { $upIndex = $this->getUpIndex(); if ($upIndex !== null) { $itemStack = $this->getItemStack(); $this->overlay = $itemStack[$upIndex][SSViewer_Scope::ITEM_OVERLAY]; } return parent::popScope(); }
Now that we're going to jump up an item in the item stack, we need to restore the overlay that was previously stored against the next item "up" in the stack from the current one @return SSViewer_Scope
popScope
php
silverstripe/silverstripe-framework
src/View/SSViewer_DataPresenter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_DataPresenter.php
BSD-3-Clause
public function obj($name, $arguments = [], $cache = false, $cacheName = null) { $overlayIndex = false; switch ($name) { case 'Up': $upIndex = $this->getUpIndex(); if ($upIndex === null) { throw new \LogicException('Up called when we\'re already at the top of the scope'); } $overlayIndex = $upIndex; // Parent scope $this->preserveOverlay = true; // Preserve overlay break; case 'Top': $overlayIndex = 0; // Top-level scope $this->preserveOverlay = true; // Preserve overlay break; default: $this->preserveOverlay = false; break; } if ($overlayIndex !== false) { $itemStack = $this->getItemStack(); if (!$this->overlay && isset($itemStack[$overlayIndex][SSViewer_Scope::ITEM_OVERLAY])) { $this->overlay = $itemStack[$overlayIndex][SSViewer_Scope::ITEM_OVERLAY]; } } parent::obj($name, $arguments, $cache, $cacheName); return $this; }
$Up and $Top need to restore the overlay from the parent and top-level scope respectively. @param string $name @param array $arguments @param bool $cache @param string $cacheName @return $this
obj
php
silverstripe/silverstripe-framework
src/View/SSViewer_DataPresenter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_DataPresenter.php
BSD-3-Clause
protected function processTemplateOverride($property, $overrides) { if (!array_key_exists($property, $overrides)) { return []; } // Detect override type $override = $overrides[$property]; // Late-evaluate this value if (!is_string($override) && is_callable($override)) { $override = $override(); // Late override may yet return null if (!isset($override)) { return []; } } return ['value' => $override]; }
Evaluate a template override. Returns an array where the presence of a 'value' key indiciates whether an override was successfully found, as null is a valid override value @param string $property Name of override requested @param array $overrides List of overrides available @return array An array with a 'value' key if a value has been found, or empty if not
processTemplateOverride
php
silverstripe/silverstripe-framework
src/View/SSViewer_DataPresenter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_DataPresenter.php
BSD-3-Clause
protected function getValueSource($property) { // Check for a presenter-specific override $result = $this->processTemplateOverride($property, $this->overlay); if (array_key_exists('value', $result)) { return ['source' => $result]; } // Check if the method to-be-called exists on the target object - if so, don't check any further // injection locations $on = $this->getItem(); if (is_object($on) && (isset($on->$property) || method_exists($on, $property ?? ''))) { return []; } // Check for a presenter-specific override $result = $this->processTemplateOverride($property, $this->underlay); if (array_key_exists('value', $result)) { return ['source' => $result]; } // Then for iterator-specific overrides if (array_key_exists($property, SSViewer_DataPresenter::$iteratorProperties)) { $source = SSViewer_DataPresenter::$iteratorProperties[$property]; /** @var TemplateIteratorProvider $implementor */ $implementor = $source['implementor']; if ($this->itemIterator) { // Set the current iterator position and total (the object instance is the first item in // the callable array) $implementor->iteratorProperties( $this->itemIterator->key(), $this->itemIteratorTotal ); } else { // If we don't actually have an iterator at the moment, act like a list of length 1 $implementor->iteratorProperties(0, 1); } return ($source) ? ['source' => $source] : []; } // And finally for global overrides if (array_key_exists($property, SSViewer_DataPresenter::$globalProperties)) { return [ 'source' => SSViewer_DataPresenter::$globalProperties[$property] // get the method call ]; } // No value return []; }
Determine source to use for getInjectedValue. Returns an array where the presence of a 'source' key indiciates whether a value source was successfully found, as a source may be a null value returned from an override @param string $property @return array An array with a 'source' key if a value source has been found, or empty if not
getValueSource
php
silverstripe/silverstripe-framework
src/View/SSViewer_DataPresenter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_DataPresenter.php
BSD-3-Clause
protected function castValue($value, $source) { // If the value has already been cast, is null, or is a non-string scalar if (is_object($value) || is_null($value) || (is_scalar($value) && !is_string($value))) { return $value; } // Get provided or default cast $casting = empty($source['casting']) ? ViewableData::config()->uninherited('default_cast') : $source['casting']; return DBField::create_field($casting, $value); }
Ensure the value is cast safely @param mixed $value @param array $source @return DBField
castValue
php
silverstripe/silverstripe-framework
src/View/SSViewer_DataPresenter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_DataPresenter.php
BSD-3-Clause
public function __construct(ViewableData $originalObject, ViewableData $customisedObject) { Deprecation::withSuppressedNotice(function () { Deprecation::notice('5.4.0', 'Will be renamed to SilverStripe\Model\ModelDataCustomised', Deprecation::SCOPE_CLASS); }); $this->original = $originalObject; $this->customised = $customisedObject; $this->original->setCustomisedObj($this); parent::__construct(); }
Instantiate a new customised ViewableData object @param ViewableData $originalObject @param ViewableData $customisedObject
__construct
php
silverstripe/silverstripe-framework
src/View/ViewableData_Customised.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/ViewableData_Customised.php
BSD-3-Clause
public function __construct($message, $parser) { Deprecation::noticeWithNoReplacment( '5.4.0', 'Will be renamed to SilverStripe\TemplateEngine\Exception\SSTemplateParseException', Deprecation::SCOPE_CLASS ); $prior = substr($parser->string ?? '', 0, $parser->pos); preg_match_all('/\r\n|\r|\n/', $prior ?? '', $matches); $line = count($matches[0] ?? []) + 1; parent::__construct("Parse error in template on line $line. Error was: $message"); }
SSTemplateParseException constructor. @param string $message @param SSTemplateParser $parser
__construct
php
silverstripe/silverstripe-framework
src/View/SSTemplateParseException.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSTemplateParseException.php
BSD-3-Clause
public function setField($field, $value) { $this->array[$field] = $value; return $this; }
Add or set a field on this object. @param string $field @param mixed $value @return $this
setField
php
silverstripe/silverstripe-framework
src/View/ArrayData.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/ArrayData.php
BSD-3-Clause
public function hasField($field) { return isset($this->array[$field]); }
Check array to see if field isset @param string $field Field Key @return bool
hasField
php
silverstripe/silverstripe-framework
src/View/ArrayData.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/ArrayData.php
BSD-3-Clause
public static function array_to_object($arr = null) { $obj = new stdClass(); if ($arr) { foreach ($arr as $name => $value) { $obj->$name = $value; } } return $obj; }
Converts an associative array to a simple object @param array $arr @return stdClass $obj
array_to_object
php
silverstripe/silverstripe-framework
src/View/ArrayData.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/ArrayData.php
BSD-3-Clause
public static function flush() { $disabled = Config::inst()->get(static::class, 'disable_flush_combined'); if (!$disabled) { Requirements::delete_all_combined_files(); } }
Triggered early in the request when a flush is requested
flush
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_combined_files_enabled($enable) { Requirements::backend()->setCombinedFilesEnabled($enable); }
Enable combining of css/javascript files. @param bool $enable
set_combined_files_enabled
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_combined_files_enabled() { return Requirements::backend()->getCombinedFilesEnabled(); }
Checks whether combining of css/javascript files is enabled. @return bool
get_combined_files_enabled
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_combined_files_folder($folder) { Requirements::backend()->setCombinedFilesFolder($folder); }
Set the relative folder e.g. 'assets' for where to store combined files @param string $folder Path to folder
set_combined_files_folder
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_suffix_requirements($var) { Requirements::backend()->setSuffixRequirements($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
set_suffix_requirements
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_suffix_requirements() { return Requirements::backend()->getSuffixRequirements(); }
Check whether we want to suffix requirements @return bool
get_suffix_requirements
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_backend(Requirements_Backend $backend) { Requirements::$backend = $backend; }
Setter method for changing the Requirements backend @param Requirements_Backend $backend
set_backend
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 javascript($file, $options = []) { Requirements::backend()->javascript($file, $options); }
Register the given JavaScript file as required. @param string $file Relative to docroot @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
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 customScript($script, $uniquenessID = null) { Requirements::backend()->customScript($script, $uniquenessID); }
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|int $uniquenessID A unique ID that ensures a piece of code is only added once
customScript
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 customScriptWithAttributes(string $script, array $options = [], string|int|null $uniquenessID = null) { Requirements::backend()->customScriptWithAttributes($script, $options, $uniquenessID); }
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|null $uniquenessID A unique ID that ensures a piece of code is only added once
customScriptWithAttributes
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_custom_scripts() { return Requirements::backend()->getCustomScripts(); }
Return all registered custom scripts @return array
get_custom_scripts
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 customCSS($script, $uniquenessID = null) { Requirements::backend()->customCSS($script, $uniquenessID); }
Register the given CSS styles into the list of requirements @param string $script CSS selectors as a string (without enclosing `<style>` tag) @param string|int $uniquenessID A unique ID that ensures a piece of code is only added once
customCSS
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 insertHeadTags($html, $uniquenessID = null) { Requirements::backend()->insertHeadTags($html, $uniquenessID); }
Add the following custom HTML code to the `<head>` section of the page @param string $html Custom HTML code @param string|int $uniquenessID A unique ID that ensures a piece of code is only added once
insertHeadTags
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 javascriptTemplate($file, $vars, $uniquenessID = null) { Requirements::backend()->javascriptTemplate($file, $vars, $uniquenessID); }
Include the content of the given JavaScript file in the list of requirements. Dollar-sign variables will be interpolated with values from $vars similar to a .ss template. @param string $file The template file to load, relative to docroot @param string[]|int[] $vars The array of variables to interpolate. @param string|int $uniquenessID A unique ID that ensures a piece of code is only added once
javascriptTemplate
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 css($file, $media = null, $options = []) { Requirements::backend()->css($file, $media, $options); }
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.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php
BSD-3-Clause
public static function themedCSS($name, $media = null) { Requirements::backend()->themedCSS($name, $media); }
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.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php
BSD-3-Clause
public static function themedJavascript($name, $type = null) { Requirements::backend()->themedJavascript($name, $type); }
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 '/javascript/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.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php
BSD-3-Clause
public static function clear($fileOrID = null) { Requirements::backend()->clear($fileOrID); }
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.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/Requirements.php
BSD-3-Clause
public static function restore() { Requirements::backend()->restore(); }
Restore requirements cleared by call to Requirements::clear
restore
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 unblock($fileOrID) { Requirements::backend()->unblock($fileOrID); }
Remove an item from the block list @param string|int $fileOrID
unblock
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 unblock_all() { Requirements::backend()->unblockAll(); }
Removes all items from the block list
unblock_all
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 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 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 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 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
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
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