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
public function getSortedList() { $this->addVariables(); // Find all items that don't have their order specified by the config system $unspecified = array_diff($this->names ?? [], $this->priorities); if (!empty($unspecified)) { $this->includeRest($unspecified); } $sortedList = []; foreach ($this->priorities as $itemName) { if (isset($this->items[$itemName])) { $sortedList[$itemName] = $this->items[$itemName]; } } return $sortedList; }
Sorts the items and returns a new version of $this->items @return array
getSortedList
php
silverstripe/silverstripe-framework
src/Core/Manifest/PrioritySorter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/PrioritySorter.php
BSD-3-Clause
public function setPriorities(array $priorities) { $this->priorities = $priorities; return $this; }
Set the priorities for the items @param array $priorities An array of keys used in $this->items @return $this
setPriorities
php
silverstripe/silverstripe-framework
src/Core/Manifest/PrioritySorter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/PrioritySorter.php
BSD-3-Clause
public function setVariable($name, $value) { $this->variables[$name] = $value; return $this; }
Add a variable for replacination, e.g. addVariable->('$project', 'myproject') @param string $name @param $value @return $this
setVariable
php
silverstripe/silverstripe-framework
src/Core/Manifest/PrioritySorter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/PrioritySorter.php
BSD-3-Clause
public function setRestKey($key) { $this->restKey = $key; return $this; }
The key used for "all other items" @param $key @return $this
setRestKey
php
silverstripe/silverstripe-framework
src/Core/Manifest/PrioritySorter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/PrioritySorter.php
BSD-3-Clause
protected function includeRest(array $list) { $otherItemsIndex = false; if ($this->restKey) { $otherItemsIndex = array_search($this->restKey, $this->priorities ?? []); } if ($otherItemsIndex !== false) { array_splice($this->priorities, $otherItemsIndex ?? 0, 1, $list); } else { // Otherwise just jam them on the end $this->priorities = array_merge($this->priorities, $list); } }
If the "rest" key exists in the order array, replace it by the unspecified items
includeRest
php
silverstripe/silverstripe-framework
src/Core/Manifest/PrioritySorter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/PrioritySorter.php
BSD-3-Clause
protected function resolveValue($name) { return isset($this->variables[$name]) ? $this->variables[$name] : $name; }
Ensure variables get converted to their values @param $name @return mixed
resolveValue
php
silverstripe/silverstripe-framework
src/Core/Manifest/PrioritySorter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/PrioritySorter.php
BSD-3-Clause
public function getPath() { return Path::join($this->module->getPath(), $this->relativePath); }
Return the full filesystem path to this resource. Note: In the case that this resource is mapped to the `_resources` folder, this will return the original rather than the copy / symlink. @return string Path with no trailing slash E.g. /var/www/module
getPath
php
silverstripe/silverstripe-framework
src/Core/Manifest/ModuleResource.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleResource.php
BSD-3-Clause
public function getRelativePath() { // Root module $parent = $this->module->getRelativePath(); if (!$parent) { return $this->relativePath; } return Path::join($parent, $this->relativePath); }
Get the path of this resource relative to the base path. Note: In the case that this resource is mapped to the `_resources` folder, this will return the original rather than the copy / symlink. @return string Relative path (no leading /)
getRelativePath
php
silverstripe/silverstripe-framework
src/Core/Manifest/ModuleResource.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleResource.php
BSD-3-Clause
public function getURL() { $generator = Injector::inst()->get(ResourceURLGenerator::class); return $generator->urlForResource($this); }
Public URL to this resource. Note: May be either absolute url, or root-relative url In the case that this resource is mapped to the `_resources` folder this will be the mapped url rather than the original path. @return string
getURL
php
silverstripe/silverstripe-framework
src/Core/Manifest/ModuleResource.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleResource.php
BSD-3-Clause
public function Link() { return $this->getURL(); }
Synonym for getURL() for APIs that expect a Link method @return mixed
Link
php
silverstripe/silverstripe-framework
src/Core/Manifest/ModuleResource.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleResource.php
BSD-3-Clause
public function exists() { return file_exists($this->getPath() ?? ''); }
Determine if this resource exists @return bool
exists
php
silverstripe/silverstripe-framework
src/Core/Manifest/ModuleResource.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleResource.php
BSD-3-Clause
public function getRelativeResource($path) { // Defer to parent module $relativeToModule = Path::join($this->relativePath, $path); return $this->getModule()->getResource($relativeToModule); }
Get nested resource relative to this. Note: Doesn't support `..` or `.` relative syntax @param string $path @return ModuleResource
getRelativeResource
php
silverstripe/silverstripe-framework
src/Core/Manifest/ModuleResource.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleResource.php
BSD-3-Clause
public function getName() { return $this->getComposerName() ?: $this->getShortName(); }
Gets name of this module. Used as unique key and identifier for this module. If installed by composer, this will be the full composer name (vendor/name). If not installed by composer this will default to the `basedir()` @return string
getName
php
silverstripe/silverstripe-framework
src/Core/Manifest/Module.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/Module.php
BSD-3-Clause
public function getComposerName() { if (isset($this->composerData['name'])) { return $this->composerData['name']; } return null; }
Get full composer name. Will be `null` if no composer.json is available @return string|null
getComposerName
php
silverstripe/silverstripe-framework
src/Core/Manifest/Module.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/Module.php
BSD-3-Clause
public function getExposedFolders() { if (isset($this->composerData['extra']['expose'])) { return $this->composerData['extra']['expose']; } return []; }
Get list of folders that need to be made available @return array
getExposedFolders
php
silverstripe/silverstripe-framework
src/Core/Manifest/Module.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/Module.php
BSD-3-Clause
public function getShortName() { // If installed in the root directory we need to infer from composer if ($this->path === $this->basePath && $this->composerData) { // Sometimes we customise installer name if (isset($this->composerData['extra']['installer-name'])) { return $this->composerData['extra']['installer-name']; } // Strip from full composer name $composerName = $this->getComposerName(); if ($composerName) { list(, $name) = explode('/', $composerName ?? ''); return $name; } } // Base name of directory return basename($this->path ?? ''); }
Gets "short" name of this module. This is the base directory this module is installed in. If installed in root, this will be generated from the composer name instead @return string
getShortName
php
silverstripe/silverstripe-framework
src/Core/Manifest/Module.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/Module.php
BSD-3-Clause
public function getResourcesDir() { return isset($this->composerData['extra']['resources-dir']) ? $this->composerData['extra']['resources-dir'] : ''; }
Name of the resource directory where vendor resources should be exposed as defined by the `extra.resources-dir` key in the composer file. A blank string will be returned if the key is undefined. Only applicable when reading the composer file for the main project. @return string
getResourcesDir
php
silverstripe/silverstripe-framework
src/Core/Manifest/Module.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/Module.php
BSD-3-Clause
public function getRelativePath() { if ($this->path === $this->basePath) { return ''; } return substr($this->path ?? '', strlen($this->basePath ?? '') + 1); }
Get path relative to base dir. If module path is base this will be empty string @return string Path with trimmed slashes. E.g. vendor/silverstripe/module.
getRelativePath
php
silverstripe/silverstripe-framework
src/Core/Manifest/Module.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/Module.php
BSD-3-Clause
public function activate() { $config = "{$this->path}/_config.php"; if (file_exists($config ?? '')) { requireFile($config); } }
Activate _config.php for this module, if one exists
activate
php
silverstripe/silverstripe-framework
src/Core/Manifest/Module.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/Module.php
BSD-3-Clause
function requireFile() { require_once func_get_arg(0); }
Scope isolated require - prevents access to $this, and prevents module _config.php files potentially leaking variables. Required argument $file is commented out to avoid leaking that into _config.php @param string $file
requireFile
php
silverstripe/silverstripe-framework
src/Core/Manifest/Module.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/Module.php
BSD-3-Clause
public function __construct($base, CacheFactory $cacheFactory = null) { $this->base = $base; $this->cacheFactory = $cacheFactory; $this->cacheKey = 'manifest'; $this->filesCacheKey = 'manifestFiles'; }
Constructs and initialises a new class manifest, either loading the data from the cache or re-scanning for classes. @param string $base The manifest base path. @param CacheFactory $cacheFactory Optional cache to use. Set to null to not cache.
__construct
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getTraverser() { if (!$this->traverser) { $this->traverser = new NodeTraverser; $this->traverser->addVisitor(new NameResolver); $this->traverser->addVisitor($this->getVisitor()); } return $this->traverser; }
Get node traverser for parsing class files @return NodeTraverser
getTraverser
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getVisitor() { if (!$this->visitor) { $this->visitor = new ClassManifestVisitor; } return $this->visitor; }
Get visitor for parsing class files @return ClassManifestVisitor
getVisitor
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getItemPath($name) { $lowerName = strtolower($name ?? ''); foreach ([ $this->classes, $this->interfaces, $this->traits, $this->enums, ] as $source) { if (isset($source[$lowerName]) && file_exists($source[$lowerName] ?? '')) { return $source[$lowerName]; } } return null; }
Returns the file path to a class or interface if it exists in the manifest. @param string $name @return string|null
getItemPath
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getClasses() { return $this->classes; }
Returns a map of lowercased class names to file paths. @return array
getClasses
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getClassNames() { return $this->classNames; }
Returns a map of lowercase class names to proper class names in the manifest @return array
getClassNames
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getTraits() { return $this->traits; }
Returns a map of lowercased trait names to file paths. @return array
getTraits
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getTraitNames() { return $this->traitNames; }
Returns a map of lowercase trait names to proper trait names in the manifest @return array
getTraitNames
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getEnums() { return $this->enums; }
Returns a map of lowercased enum names to file paths. @return array
getEnums
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getEnumNames() { return $this->enumNames; }
Returns a map of lowercase enum names to proper enum names in the manifest @return array
getEnumNames
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getDescendants() { return $this->descendants; }
Returns an array of all the descendant data. @return array
getDescendants
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getDescendantsOf($class) { if (is_object($class)) { $class = get_class($class); } $lClass = strtolower($class ?? ''); if (array_key_exists($lClass, $this->descendants ?? [])) { return $this->descendants[$lClass]; } return []; }
Returns an array containing all the descendants (direct and indirect) of a class. @param string|object $class @return array
getDescendantsOf
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getInterfaceNames() { return $this->interfaceNames; }
Return map of lowercase interface names to proper case names in the manifest @return array
getInterfaceNames
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getImplementors() { return $this->implementors; }
Returns a map of lowercased interface names to the classes the implement them. @return array
getImplementors
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getImplementorsOf($interface) { $lowerInterface = strtolower($interface ?? ''); if (array_key_exists($lowerInterface, $this->implementors ?? [])) { return $this->implementors[$lowerInterface]; } else { return []; } }
Returns an array containing the class names that implement a certain interface. @param string $interface @return array
getImplementorsOf
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function getOwnerModule($class) { $path = $this->getItemPath($class); return ModuleLoader::inst()->getManifest()->getModuleByPath($path); }
Get module that owns this class @param string $class Class name @return Module
getOwnerModule
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
protected function loadState($data) { $success = true; foreach ($this->serialisedProperties as $property) { if (!isset($data[$property]) || !is_array($data[$property])) { $success = false; $value = []; } else { $value = $data[$property]; } $this->$property = $value; } return $success; }
Reload state from given cache data @param array $data @return bool True if cache was valid and successfully loaded
loadState
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
protected function getState() { $data = []; foreach ($this->serialisedProperties as $property) { $data[$property] = $this->$property; } return $data; }
Load current state into an array of data @return array
getState
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
protected function validateItemCache($data) { if (!$data || !is_array($data)) { return false; } foreach (['classes', 'interfaces', 'traits', 'enums'] as $key) { // Must be set if (!isset($data[$key])) { return false; } // and an array if (!is_array($data[$key])) { return false; } // Detect legacy cache keys (non-associative) $array = $data[$key]; if (!empty($array) && is_numeric(key($array ?? []))) { return false; } } return true; }
Verify that cached data is valid for a single item @param array $data @return bool
validateItemCache
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassManifest.php
BSD-3-Clause
public function isInsideVendor($basename, $pathname, $depth) { $base = basename($this->upLevels($pathname, $depth - 1) ?? ''); return $base === ManifestFileFinder::VENDOR_DIR; }
Check if the given dir is, or is inside the vendor folder @param string $basename @param string $pathname @param int $depth @return bool
isInsideVendor
php
silverstripe/silverstripe-framework
src/Core/Manifest/ManifestFileFinder.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ManifestFileFinder.php
BSD-3-Clause
public function isInsideThemes($basename, $pathname, $depth) { $base = basename($this->upLevels($pathname, $depth - 1) ?? ''); return $base === THEMES_DIR; }
Check if the given dir is, or is inside the themes folder @param string $basename @param string $pathname @param int $depth @return bool
isInsideThemes
php
silverstripe/silverstripe-framework
src/Core/Manifest/ManifestFileFinder.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ManifestFileFinder.php
BSD-3-Clause
public function isInsideIgnored($basename, $pathname, $depth) { return $this->anyParents($basename, $pathname, $depth, function ($basename, $pathname, $depth) { return $this->isDirectoryIgnored($basename, $pathname, $depth); }); }
Check if this folder or any parent is ignored @param string $basename @param string $pathname @param int $depth @return bool
isInsideIgnored
php
silverstripe/silverstripe-framework
src/Core/Manifest/ManifestFileFinder.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ManifestFileFinder.php
BSD-3-Clause
public function isInsideModule($basename, $pathname, $depth) { return $this->anyParents($basename, $pathname, $depth, function ($basename, $pathname, $depth) { return $this->isDirectoryModule($basename, $pathname, $depth); }); }
Check if this folder is inside any module @param string $basename @param string $pathname @param int $depth @return bool
isInsideModule
php
silverstripe/silverstripe-framework
src/Core/Manifest/ManifestFileFinder.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ManifestFileFinder.php
BSD-3-Clause
protected function anyParents($basename, $pathname, $depth, $callback) { // Check all ignored dir up the path while ($depth >= 0) { $ignored = $callback($basename, $pathname, $depth); if ($ignored) { return true; } $pathname = dirname($pathname ?? ''); $basename = basename($pathname ?? ''); $depth--; } return false; }
Check if any parents match the given callback @param string $basename @param string $pathname @param int $depth @param callable $callback @return bool
anyParents
php
silverstripe/silverstripe-framework
src/Core/Manifest/ManifestFileFinder.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ManifestFileFinder.php
BSD-3-Clause
public function isDirectoryModule($basename, $pathname, $depth) { // Depth can either be 0, 1, or 3 (if and only if inside vendor) $inVendor = $this->isInsideVendor($basename, $pathname, $depth); if ($depth > 0 && $depth !== ($inVendor ? 3 : 1)) { return false; } // True if config file exists if (file_exists($pathname . '/' . ManifestFileFinder::CONFIG_FILE)) { return true; } // True if config dir exists if (file_exists($pathname . '/' . ManifestFileFinder::CONFIG_DIR)) { return true; } return false; }
Check if the given dir is a module root (not a subdir) @param string $basename @param string $pathname @param string $depth @return bool
isDirectoryModule
php
silverstripe/silverstripe-framework
src/Core/Manifest/ManifestFileFinder.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ManifestFileFinder.php
BSD-3-Clause
protected function upLevels($pathname, $depth) { if ($depth < 0) { return null; } while ($depth--) { $pathname = dirname($pathname ?? ''); } return $pathname; }
Get a parent path the given levels above @param string $pathname @param int $depth Number of parents to rise @return string
upLevels
php
silverstripe/silverstripe-framework
src/Core/Manifest/ManifestFileFinder.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ManifestFileFinder.php
BSD-3-Clause
public function isDirectoryIgnored($basename, $pathname, $depth) { // Don't ignore root if ($depth === 0) { return false; } // Check if manifest-ignored is present if (file_exists($pathname . '/' . ManifestFileFinder::EXCLUDE_FILE)) { return true; } // Check if directory name is ignored $ignored = $this->getIgnoredDirs(); if (in_array($basename, $ignored ?? [])) { return true; } // Ignore these dirs in the root only if ($depth === 1 && in_array($basename, [ASSETS_DIR, RESOURCES_DIR])) { return true; } return false; }
Check if the given directory is ignored @param string $basename @param string $pathname @param string $depth @return bool
isDirectoryIgnored
php
silverstripe/silverstripe-framework
src/Core/Manifest/ManifestFileFinder.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ManifestFileFinder.php
BSD-3-Clause
public function __construct($base, CacheFactory $cacheFactory = null) { $this->base = $base; $this->cacheKey = sha1($base ?? '') . '_modules'; $this->cacheFactory = $cacheFactory; }
Constructs and initialises a new configuration object, either loading from the cache or re-scanning for classes. @param string $base The project base path. @param CacheFactory $cacheFactory Cache factory to use
__construct
php
silverstripe/silverstripe-framework
src/Core/Manifest/ModuleManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleManifest.php
BSD-3-Clause
public function moduleExists($name) { $module = $this->getModule($name); return !empty($module); }
Returns true if the passed module exists @param string $name Either full composer name or short name @return bool
moduleExists
php
silverstripe/silverstripe-framework
src/Core/Manifest/ModuleManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleManifest.php
BSD-3-Clause
public function sort() { $order = static::config()->uninherited('module_priority'); $project = static::config()->get('project'); /** @var PrioritySorter $sorter */ $sorter = Injector::inst()->createWithArgs( PrioritySorter::class . '.modulesorter', [ $this->modules, $order ?: [], ] ); if ($project) { $sorter->setVariable(ModuleManifest::PROJECT_KEY, $project); } $this->modules = $sorter->getSortedList(); }
Sort modules sorted by priority
sort
php
silverstripe/silverstripe-framework
src/Core/Manifest/ModuleManifest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleManifest.php
BSD-3-Clause
public function getManifest() { return $this->manifests[count($this->manifests) - 1]['instance']; }
Returns the currently active class manifest instance that is used for loading classes. @return ClassManifest
getManifest
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassLoader.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassLoader.php
BSD-3-Clause
public function loadClass($class) { if ($path = $this->getItemPath($class)) { require_once $path; } return $path; }
Loads a class or interface if it is present in the currently active manifest. @param string $class @return String
loadClass
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassLoader.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassLoader.php
BSD-3-Clause
public function getItemPath($class) { foreach (array_reverse($this->manifests ?? []) as $manifest) { /** @var ClassManifest $manifestInst */ $manifestInst = $manifest['instance']; if ($path = $manifestInst->getItemPath($class)) { return $path; } if ($manifest['exclusive']) { break; } } return false; }
Returns the path for a class or interface in the currently active manifest, or any previous ones if later manifests aren't set to "exclusive". @param string $class @return string|false
getItemPath
php
silverstripe/silverstripe-framework
src/Core/Manifest/ClassLoader.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ClassLoader.php
BSD-3-Clause
public function getModules() { $modules = Config::inst()->get(VersionProvider::class, 'modules'); return !empty($modules) ? $modules : ['silverstripe/framework' => 'Framework']; }
Gets the configured core modules to use for the SilverStripe application version @return array<string,string>
getModules
php
silverstripe/silverstripe-framework
src/Core/Manifest/VersionProvider.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/VersionProvider.php
BSD-3-Clause
protected function getComposerLock($cache = true) { Deprecation::notice("5.1", "Has been replaced by composer-runtime-api", Deprecation::SCOPE_METHOD); $composerLockPath = $this->getComposerLockPath(); if (!file_exists($composerLockPath)) { return []; } $lockData = []; $jsonData = file_get_contents($composerLockPath); $jsonData = $jsonData ? $jsonData : ''; $cacheKey = md5($jsonData); if ($cache) { $cache = Injector::inst()->get(CacheInterface::class . '.VersionProvider_composerlock'); if ($versions = $cache->get($cacheKey)) { $lockData = json_decode($versions, true); } } if (empty($lockData) && $jsonData) { $lockData = json_decode($jsonData, true); if ($cache) { $cache->set($cacheKey, $jsonData); } } $lockData = $lockData ? $lockData : []; return $lockData; }
Load composer.lock's contents and return it @deprecated 5.1.0 Has been replaced by composer-runtime-api @param bool $cache @return array
getComposerLock
php
silverstripe/silverstripe-framework
src/Core/Manifest/VersionProvider.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/VersionProvider.php
BSD-3-Clause
protected function configFor($name) { // Return cached result if (array_key_exists($name, $this->configs ?? [])) { return $this->configs[$name]; } $config = Config::inst()->get(Injector::class, $name); $this->configs[$name] = $config; return $config; }
Retrieves the config for a named service without performing a hierarchy walk @param string $name Name of service @return mixed Get config for this service
configFor
php
silverstripe/silverstripe-framework
src/Core/Injector/SilverStripeServiceConfigurationLocator.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/SilverStripeServiceConfigurationLocator.php
BSD-3-Clause
public static function unnest() { // Unnest unless we would be left at 0 manifests $loader = InjectorLoader::inst(); if ($loader->countManifests() <= 1) { user_error( "Unable to unnest root Injector, please make sure you don't have mis-matched nest/unnest", E_USER_WARNING ); } else { $loader->popManifest(); } return static::inst(); }
Change the active Injector back to the Injector instance the current active Injector object was copied from. @return Injector Reference to restored active Injector instance
unnest
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public function setAutoScanProperties($val) { $this->autoScanProperties = $val; }
Indicate whether we auto scan injected objects for properties to set. @param boolean $val
setAutoScanProperties
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public function setObjectCreator(Factory $obj) { $this->objectCreator = $obj; }
Sets the default factory to use for creating new objects. @param \SilverStripe\Core\Injector\Factory $obj
setObjectCreator
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public function getConfigLocator() { return $this->configLocator; }
Retrieve the configuration locator @return ServiceConfigurationLocator
getConfigLocator
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public function updateSpec($id, $property, $value, $append = true) { if (isset($this->specs[$id]['properties'][$property])) { // by ref so we're updating the actual value $current = &$this->specs[$id]['properties'][$property]; if (is_array($current) && $append) { $current[] = $value; } else { $this->specs[$id]['properties'][$property] = $value; } // and reload the object; existing bindings don't get // updated though! (for now...) if (isset($this->serviceCache[$id])) { $this->instantiate(['class'=>$id], $id); } } }
Update the configuration of an already defined service Use this if you don't want to register a complete new config, just append to an existing configuration. Helpful to avoid overwriting someone else's changes updateSpec('RequestProcessor', 'filters', '%$MyFilter') @param string $id The name of the service to update the definition for @param string $property The name of the property to update. @param mixed $value The value to set @param boolean $append Whether to append (the default) when the property is an array
updateSpec
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
protected function updateSpecConstructor(&$spec) { if (isset($spec['constructor'])) { $spec['constructor'] = $this->convertServiceProperty($spec['constructor']); } }
Update a class specification to convert constructor configuration information if needed We do this as a separate process to avoid unneeded calls to convertServiceProperty @param array $spec The class specification to update
updateSpecConstructor
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
protected function setObjectProperty($object, $name, $value) { if (ClassInfo::hasMethod($object, 'set' . $name)) { $object->{'set' . $name}($value); } else { $object->$name = $value; } }
Helper to set a property's value @param object $object Set an object's property to a specific value @param string $name The name of the property to set @param mixed $value The value to set
setObjectProperty
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public function getServiceName($name) { // Lazy load in spec (disable inheritance to check exact service name) if ($this->getServiceSpec($name, false)) { return $name; } // okay, check whether we've got a compound name - don't worry about 0 index, cause that's an // invalid name if (!strpos($name ?? '', '.')) { return null; } return $this->getServiceName(substr($name ?? '', 0, strrpos($name ?? '', '.'))); }
Does the given service exist, and if so, what's the stored name for it? We do a special check here for services that are using compound names. For example, we might want to say that a property should be injected with Log.File or Log.Memory, but have only registered a 'Log' service, we'll instead return that. Will recursively call itself for each depth of dotting. @param string $name @return string|null The name of the service (as it might be different from the one passed in)
getServiceName
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public function unregisterNamedObject($name) { unset($this->serviceCache[$name]); unset($this->specs[$name]); return $this; }
Removes a named object from the cached list of objects managed by the inject @param string $name The name to unregister @return $this
unregisterNamedObject
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public function unregisterObjects($types) { if (!is_array($types)) { $types = [ $types ]; } // Filter all objects foreach ($this->serviceCache as $key => $object) { foreach ($types as $filterClass) { // Prevent destructive flushing if (strcasecmp($filterClass ?? '', 'object') === 0) { throw new InvalidArgumentException("Global unregistration is not allowed"); } if ($object instanceof $filterClass) { $this->unregisterNamedObject($key); break; } } } return $this; }
Clear out objects of one or more types that are managed by the injetor. @param array|string $types Base class of object (not service name) to remove @return $this
unregisterObjects
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public function get($name, $asSingleton = true, $constructorArgs = []) { $object = $this->getNamedService($name, $asSingleton, $constructorArgs); if (!$object) { throw new InjectorNotFoundException("The '{$name}' service could not be found"); } return $object; }
Get a named managed object Will first check to see if the item has been registered as a configured service/bean and return that if so. Next, will check to see if there's any registered configuration for the given type and will then try and load that Failing all of that, will just return a new instance of the specified object. @throws NotFoundExceptionInterface No entry was found for **this** identifier. @template T of object @param class-string<T>|string $name The name of the service to retrieve. If not a registered service, then a class of the given name is instantiated @param bool $asSingleton If set to false a new instance will be returned. If true a singleton will be returned unless the spec is type=prototype' @param array $constructorArgs Args to pass in to the constructor. Note: Ignored for singletons @return T|mixed Instance of the specified object
get
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
protected function getNamedService($name, $asSingleton = true, $constructorArgs = []) { // Normalise service / args list($name, $constructorArgs) = $this->normaliseArguments($name, $constructorArgs); // Resolve name with the appropriate spec, or a suitable mock for new services list($name, $spec) = $this->getServiceNamedSpec($name, $constructorArgs); // Check if we are getting a prototype or singleton $type = $asSingleton ? (isset($spec['type']) ? $spec['type'] : Injector::SINGLETON) : Injector::PROTOTYPE; // Return existing instance for singletons if ($type === Injector::SINGLETON && isset($this->serviceCache[$name])) { return $this->serviceCache[$name]; } // Update constructor args if ($type === Injector::PROTOTYPE && $constructorArgs) { // Passed in args are expected to already be normalised (no service references) $spec['constructor'] = $constructorArgs; } else { // Resolve references in constructor args $this->updateSpecConstructor($spec); } // Build instance return $this->instantiate($spec, $name, $type); }
Returns the service, or `null` if it doesnt' exist. See {@link get()} for main usage. @template T of object @param class-string<T>|string $name The name of the service to retrieve. If not a registered service, then a class of the given name is instantiated @param bool $asSingleton If set to false a new instance will be returned. If true a singleton will be returned unless the spec is type=prototype' @param array $constructorArgs Args to pass in to the constructor. Note: Ignored for singletons @return T|mixed Instance of the specified object
getNamedService
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
protected function normaliseArguments($name, $args = []) { // Allow service names of the form "%$ServiceName" if (substr($name ?? '', 0, 2) == '%$') { $name = substr($name ?? '', 2); } if (strstr($name ?? '', '(')) { list($name, $extraArgs) = ClassInfo::parse_class_spec($name); if ($args) { $args = array_merge($args, $extraArgs); } else { $args = $extraArgs; } } $name = trim($name ?? ''); return [$name, $args]; }
Detect service references with constructor arguments included. These will be split out of the service name reference and appended to the $args @param string $name @param array $args @return array Two items with name and new args
normaliseArguments
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
protected function getServiceNamedSpec($name, $constructorArgs = []) { $spec = $this->getServiceSpec($name); if ($spec) { // Resolve to exact service name (in case inherited) $name = $this->getServiceName($name); } else { // Late-generate config spec for non-configured spec $spec = [ 'class' => $name, 'constructor' => $constructorArgs, ]; } return [$name, $spec]; }
Get or build a named service and specification @param string $name Service name @param array $constructorArgs Optional constructor args @return array
getServiceNamedSpec
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public function getServiceSpec($name, $inherit = true) { if (isset($this->specs[$name])) { return $this->specs[$name]; } // Lazy load $config = $this->configLocator->locateConfigFor($name); if ($config) { $this->load([$name => $config]); if (isset($this->specs[$name])) { return $this->specs[$name]; } } // Fail over to parent service if allowed if (!$inherit || !strpos($name ?? '', '.')) { return null; } return $this->getServiceSpec(substr($name ?? '', 0, strrpos($name ?? '', '.'))); }
Search for spec, lazy-loading in from config locator. Falls back to parent service name if unloaded @param string $name @param bool $inherit Set to true to inherit from parent service if `.` suffixed E.g. 'Psr/Log/LoggerInterface.custom' would fail over to 'Psr/Log/LoggerInterface' @return mixed|object
getServiceSpec
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public function create($name, $argument = null) { $constructorArgs = func_get_args(); array_shift($constructorArgs); return $this->createWithArgs($name, $constructorArgs); }
Similar to get() but always returns a new object of the given type Additional parameters are passed through as @template T of object @param class-string<T>|string $name @param mixed ...$argument arguments to pass to the constructor @return T|mixed A new instance of the specified object
create
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public function createWithArgs($name, $constructorArgs) { return $this->get($name, false, $constructorArgs); }
Creates an object with the supplied argument array @template T of object @param class-string<T>|string $name Name of the class to create an object of @param array $constructorArgs Arguments to pass to the constructor @return T|mixed
createWithArgs
php
silverstripe/silverstripe-framework
src/Core/Injector/Injector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injector.php
BSD-3-Clause
public static function singleton($class = null) { if (!$class) { $class = get_called_class(); } return Injector::inst()->get($class); }
Creates a class instance by the "singleton" design pattern. It will always return the same instance for this class, which can be used for performance reasons and as a simple way to access instance methods which don't rely on instance data (e.g. the custom SilverStripe static handling). @param string $class Optional classname to create, if the called class should not be used @return static The singleton instance
singleton
php
silverstripe/silverstripe-framework
src/Core/Injector/Injectable.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/Injectable.php
BSD-3-Clause
public function getManifest() { if ($this !== InjectorLoader::$instance) { throw new BadMethodCallException( "Non-current injector manifest cannot be accessed. Please call ->activate() first" ); } if (empty($this->manifests)) { throw new BadMethodCallException(InjectorLoader::NO_MANIFESTS_AVAILABLE); } return $this->manifests[count($this->manifests) - 1]; }
Returns the currently active class manifest instance that is used for loading classes. @return Injector
getManifest
php
silverstripe/silverstripe-framework
src/Core/Injector/InjectorLoader.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/InjectorLoader.php
BSD-3-Clause
public function pushManifest(Injector $manifest) { $this->manifests[] = $manifest; }
Pushes a class manifest instance onto the top of the stack. @param Injector $manifest
pushManifest
php
silverstripe/silverstripe-framework
src/Core/Injector/InjectorLoader.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Injector/InjectorLoader.php
BSD-3-Clause
public function getItem() { Deprecation::notice('5.4.0', 'use getCurrentItem() instead.'); $item = $this->itemIterator ? $this->itemIterator->current() : $this->item; if (is_scalar($item)) { $item = $this->convertScalarToDBField($item); } return $item; }
Returns the current "active" item @return object @deprecated 5.4.0 use getCurrentItem() instead.
getItem
php
silverstripe/silverstripe-framework
src/View/SSViewer_Scope.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_Scope.php
BSD-3-Clause
public function locally() { list( $this->item, $this->itemIterator, $this->itemIteratorTotal, $this->popIndex, $this->upIndex, $this->currentIndex ) = $this->itemStack[$this->localIndex]; // Remember any un-completed (resetLocalScope hasn't been called) lookup chain. Even if there isn't an // un-completed chain we need to store an empty item, as resetLocalScope doesn't know the difference later $this->localStack[] = array_splice($this->itemStack, $this->localIndex + 1); return $this; }
Called at the start of every lookup chain by SSTemplateParser to indicate a new lookup from local scope @return SSViewer_Scope
locally
php
silverstripe/silverstripe-framework
src/View/SSViewer_Scope.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_Scope.php
BSD-3-Clause
public function resetLocalScope() { // Restore previous un-completed lookup chain if set $previousLocalState = $this->localStack ? array_pop($this->localStack) : null; array_splice($this->itemStack, $this->localIndex + 1, count($this->itemStack ?? []), $previousLocalState); list( $this->item, $this->itemIterator, $this->itemIteratorTotal, $this->popIndex, $this->upIndex, $this->currentIndex ) = end($this->itemStack); }
Reset the local scope - restores saved state to the "global" item stack. Typically called after a lookup chain has been completed
resetLocalScope
php
silverstripe/silverstripe-framework
src/View/SSViewer_Scope.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_Scope.php
BSD-3-Clause
public function self() { $result = $this->getCurrentItem(); $this->resetLocalScope(); return $result; }
Gets the current object and resets the scope. @return object
self
php
silverstripe/silverstripe-framework
src/View/SSViewer_Scope.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_Scope.php
BSD-3-Clause
public function pushScope() { $newLocalIndex = count($this->itemStack ?? []) - 1; $this->popIndex = $this->itemStack[$newLocalIndex][SSViewer_Scope::POP_INDEX] = $this->localIndex; $this->localIndex = $newLocalIndex; // $Up now becomes the parent scope - the parent of the current <% loop %> or <% with %> $this->upIndex = $this->itemStack[$newLocalIndex][SSViewer_Scope::UP_INDEX] = $this->popIndex; // We normally keep any previous itemIterator around, so local $Up calls reference the right element. But // once we enter a new global scope, we need to make sure we use a new one $this->itemIterator = $this->itemStack[$newLocalIndex][SSViewer_Scope::ITEM_ITERATOR] = null; return $this; }
Jump to the last item in the stack, called when a new item is added before a loop/with @return SSViewer_Scope
pushScope
php
silverstripe/silverstripe-framework
src/View/SSViewer_Scope.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_Scope.php
BSD-3-Clause
public function popScope() { $this->localIndex = $this->popIndex; $this->resetLocalScope(); return $this; }
Jump back to "previous" item in the stack, called after a loop/with block @return SSViewer_Scope
popScope
php
silverstripe/silverstripe-framework
src/View/SSViewer_Scope.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_Scope.php
BSD-3-Clause
public function iteratorProperties($pos, $totalItems) { $this->iteratorPos = $pos; $this->iteratorTotalItems = $totalItems; }
Set the current iterator properties - where we are on the iterator. @param int $pos position in iterator @param int $totalItems total number of items
iteratorProperties
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function IsFirst() { return $this->iteratorPos == 0; }
Returns true if this object is the first in a set. @return bool
IsFirst
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function IsLast() { return $this->iteratorPos == $this->iteratorTotalItems - 1; }
Returns true if this object is the last in a set. @return bool
IsLast
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function FirstLast() { if ($this->IsFirst() && $this->IsLast()) { return 'first last'; } if ($this->IsFirst()) { return 'first'; } if ($this->IsLast()) { return 'last'; } return null; }
Returns 'first' or 'last' if this is the first or last object in the set. @return string|null
FirstLast
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function Middle() { return !$this->IsFirst() && !$this->IsLast(); }
Return true if this object is between the first & last objects. @return bool
Middle
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function MiddleString() { if ($this->Middle()) { return 'middle'; } return null; }
Return 'middle' if this object is between the first & last objects. @return string
MiddleString
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function Even($startIndex = 1) { return !$this->Odd($startIndex); }
Return true if this object is an even item in the set. The count starts from $startIndex, which defaults to 1. @param int $startIndex Number to start count from. @return bool
Even
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function Odd($startIndex = 1) { return (bool)(($this->iteratorPos + $startIndex) % 2); }
Return true if this is an odd item in the set. @param int $startIndex Number to start count from. @return bool
Odd
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function EvenOdd($startIndex = 1) { return ($this->Even($startIndex)) ? 'even' : 'odd'; }
Return 'even' or 'odd' if this object is in an even or odd position in the set respectively. @param int $startIndex Number to start count from. @return string
EvenOdd
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function Pos($startIndex = 1) { return $this->iteratorPos + $startIndex; }
Return the numerical position of this object in the container set. The count starts at $startIndex. The default is the give the position using a 1-based index. @param int $startIndex Number to start count from. @return int
Pos
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function FromEnd($endIndex = 1) { return $this->iteratorTotalItems - $this->iteratorPos + $endIndex - 1; }
Return the position of this item from the last item in the list. The position of the final item is $endIndex, which defaults to 1. @param int $endIndex Value of the last item @return int
FromEnd
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function TotalItems() { return $this->iteratorTotalItems; }
Return the total number of "sibling" items in the dataset. @return int
TotalItems
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function Modulus($mod, $startIndex = 1) { return ($this->iteratorPos + $startIndex) % $mod; }
Returns the modulus of the numerical position of the item in the data set. The count starts from $startIndex, which defaults to 1. @param int $mod The number to perform Mod operation to. @param int $startIndex Number to start count from. @return int
Modulus
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function MultipleOf($factor, $offset = 1) { return (bool)($this->Modulus($factor, $offset) == 0); }
Returns true or false depending on if the pos of the iterator is a multiple of a specific number. So, <% if MultipleOf(3) %> would return true on indexes: 3,6,9,12,15, etc. The count starts from $offset, which defaults to 1. @param int $factor The multiple of which to return @param int $offset Number to start count from. @return bool
MultipleOf
php
silverstripe/silverstripe-framework
src/View/SSViewer_BasicIteratorSupport.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/SSViewer_BasicIteratorSupport.php
BSD-3-Clause
public function addSet($set, ThemeList $manifest) { $this->sets[$set] = $manifest; }
Add a new theme manifest for a given identifier. E.g. '$default' @param string $set @param ThemeList $manifest
addSet
php
silverstripe/silverstripe-framework
src/View/ThemeResourceLoader.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/ThemeResourceLoader.php
BSD-3-Clause
public static function ModulePath($name) { // BC for a couple of the key modules in the old syntax. Reduces merge brittleness but can // be removed before 4.0 stable $legacyMapping = [ 'framework' => 'silverstripe/framework', 'frameworkadmin' => 'silverstripe/admin', ]; if (isset($legacyMapping[$name])) { $name = $legacyMapping[$name]; } return ModuleLoader::getModule($name)->getRelativePath(); }
Given some pre-defined modules, return the filesystem path of the module. @param string $name Name of module to find path of @return string
ModulePath
php
silverstripe/silverstripe-framework
src/View/GenericTemplateGlobalProvider.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/GenericTemplateGlobalProvider.php
BSD-3-Clause
public static function getDataList($className) { return DataList::create($className); }
This allows templates to create a new `DataList` from a known DataObject class name, and call methods such as aggregates. The common use case is for partial caching: <code> <% cached List(Member).max(LastEdited) %> loop members here <% end_cached %> </code> @template T of DataObject @param class-string<T> $className @return DataList<T>
getDataList
php
silverstripe/silverstripe-framework
src/View/GenericTemplateGlobalProvider.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/View/GenericTemplateGlobalProvider.php
BSD-3-Clause
protected function cacheGlobalProperties() { if (SSViewer_DataPresenter::$globalProperties !== null) { return; } SSViewer_DataPresenter::$globalProperties = $this->getPropertiesFromProvider( TemplateGlobalProvider::class, 'get_template_global_variables' ); }
Build cache of global properties
cacheGlobalProperties
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