code
stringlengths 17
296k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
protected function addCallbackMethod($method, $callback)
{
self::class::$extra_methods[strtolower(static::class)][strtolower($method)] = [
'callback' => $callback,
];
} | Add callback as a method.
@param string $method Name of method
@param callable $callback Callback to invoke.
Note: $this is passed as first parameter to this callback and then $args as array | addCallbackMethod | php | silverstripe/silverstripe-framework | src/Core/CustomMethods.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/CustomMethods.php | BSD-3-Clause |
public static function getTempFolder($base)
{
$parent = static::getTempParentFolder($base);
// The actual temp folder is a subfolder of getTempParentFolder(), named by username
$subfolder = Path::join($parent, static::getTempFolderUsername());
if (!@file_exists($subfolder ?? '')) {
mkdir($subfolder ?? '');
}
return $subfolder;
} | Returns the temporary folder path that silverstripe should use for its cache files.
@param string $base The base path to use for determining the temporary path
@return string Path to temp | getTempFolder | php | silverstripe/silverstripe-framework | src/Core/TempFolder.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/TempFolder.php | BSD-3-Clause |
public static function getTempFolderUsername()
{
$user = '';
if (function_exists('posix_getpwuid') && function_exists('posix_getuid')) {
$userDetails = posix_getpwuid(posix_getuid());
$user = $userDetails['name'] ?? false;
}
if (!$user) {
$user = Environment::getEnv('APACHE_RUN_USER');
}
if (!$user) {
$user = Environment::getEnv('USER');
}
if (!$user) {
$user = Environment::getEnv('USERNAME');
}
if (!$user) {
$user = 'unknown';
}
$user = preg_replace('/[^A-Za-z0-9_\-]/', '', $user ?? '');
return $user;
} | Returns as best a representation of the current username as we can glean.
@return string | getTempFolderUsername | php | silverstripe/silverstripe-framework | src/Core/TempFolder.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/TempFolder.php | BSD-3-Clause |
protected static function getTempParentFolder($base)
{
// first, try finding a silverstripe-cache dir built off the base path
$localPath = Path::join($base, 'silverstripe-cache');
if (@file_exists($localPath ?? '')) {
if ((fileperms($localPath ?? '') & 0777) != 0777) {
@chmod($localPath ?? '', 0777);
}
return $localPath;
}
// failing the above, try finding a namespaced silverstripe-cache dir in the system temp
$tempPath = Path::join(
sys_get_temp_dir(),
'silverstripe-cache-php' . preg_replace('/[^\w\-\.+]+/', '-', PHP_VERSION) .
str_replace([' ', '/', ':', '\\'], '-', $base ?? '')
);
if (!@file_exists($tempPath ?? '')) {
$oldUMask = umask(0);
@mkdir($tempPath ?? '', 0777);
umask($oldUMask);
// if the folder already exists, correct perms
} else {
if ((fileperms($tempPath ?? '') & 0777) != 0777) {
@chmod($tempPath ?? '', 0777);
}
}
$worked = @file_exists($tempPath ?? '') && @is_writable($tempPath ?? '');
// failing to use the system path, attempt to create a local silverstripe-cache dir
if (!$worked) {
$tempPath = $localPath;
if (!@file_exists($tempPath ?? '')) {
$oldUMask = umask(0);
@mkdir($tempPath ?? '', 0777);
umask($oldUMask);
}
$worked = @file_exists($tempPath ?? '') && @is_writable($tempPath ?? '');
}
if (!$worked) {
throw new Exception(
'Permission problem gaining access to a temp folder. ' . 'Please create a folder named silverstripe-cache in the base folder ' . 'of the installation and ensure it has the correct permissions'
);
}
return $tempPath;
} | Return the parent folder of the temp folder.
The temp folder will be a subfolder of this, named by username.
This structure prevents permission problems.
@param string $base
@return string
@throws Exception | getTempParentFolder | php | silverstripe/silverstripe-framework | src/Core/TempFolder.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/TempFolder.php | BSD-3-Clause |
public static function exists($class)
{
return class_exists($class ?? '', false)
|| interface_exists($class ?? '', false)
|| ClassLoader::inst()->getItemPath($class);
} | Returns true if a class or interface name exists.
@param string $class
@return bool | exists | php | silverstripe/silverstripe-framework | src/Core/ClassInfo.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/ClassInfo.php | BSD-3-Clause |
public static function hasTable($tableName)
{
$cache = ClassInfo::getCache();
$configData = serialize(DB::getConfig());
$cacheKey = 'tableList_' . md5($configData);
$tableList = $cache->get($cacheKey) ?? [];
if (empty($tableList) && DB::is_active()) {
$tableList = DB::get_schema()->tableList();
// Cache the list of all table names to reduce on DB traffic
$cache->set($cacheKey, $tableList);
}
return !empty($tableList[strtolower($tableName)]);
} | Cached call to see if the table exists in the DB.
For live queries, use DBSchemaManager::hasTable.
@param string $tableName
@return bool | hasTable | php | silverstripe/silverstripe-framework | src/Core/ClassInfo.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/ClassInfo.php | BSD-3-Clause |
public static function getValidSubClasses($class = SiteTree::class, $includeUnbacked = false)
{
if (is_string($class) && !class_exists($class ?? '')) {
return [];
}
$class = ClassInfo::class_name($class);
if ($includeUnbacked) {
$table = DataObject::getSchema()->tableName($class);
$classes = DB::get_schema()->enumValuesForField($table, 'ClassName');
} else {
$classes = static::subclassesFor($class);
}
return $classes;
} | Returns the manifest of all classes which are present in the database.
@param string $class Class name to check enum values for ClassName field
@param boolean $includeUnbacked Flag indicating whether or not to include
types that don't exist as implemented classes. By default these are excluded.
@return array List of subclasses | getValidSubClasses | php | silverstripe/silverstripe-framework | src/Core/ClassInfo.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/ClassInfo.php | BSD-3-Clause |
public static function dataClassesFor($nameOrObject)
{
if (is_string($nameOrObject) && !class_exists($nameOrObject ?? '')) {
return [];
}
// Get all classes
$class = ClassInfo::class_name($nameOrObject);
$classes = array_merge(
ClassInfo::ancestry($class),
ClassInfo::subclassesFor($class)
);
// Filter by table
return array_filter($classes ?? [], function ($next) {
return DataObject::getSchema()->classHasTable($next);
});
} | Returns an array of the current class and all its ancestors and children
which require a DB table.
@param string|object $nameOrObject Class or object instance
@return array | dataClassesFor | php | silverstripe/silverstripe-framework | src/Core/ClassInfo.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/ClassInfo.php | BSD-3-Clause |
public static function class_name($nameOrObject)
{
if (is_object($nameOrObject)) {
return get_class($nameOrObject);
}
$key = strtolower($nameOrObject ?? '');
if (!isset(static::$_cache_class_names[$key])) {
// Get manifest name
$name = ClassLoader::inst()->getManifest()->getItemName($nameOrObject);
// Use reflection for non-manifest classes
if (!$name) {
$reflection = new ReflectionClass($nameOrObject);
$name = $reflection->getName();
}
static::$_cache_class_names[$key] = $name;
}
return static::$_cache_class_names[$key];
} | Convert a class name in any case and return it as it was defined in PHP
eg: ClassInfo::class_name('dataobJEct'); //returns 'DataObject'
@param string|object $nameOrObject The classname or object you want to normalise
@throws \ReflectionException
@return string The normalised class name | class_name | php | silverstripe/silverstripe-framework | src/Core/ClassInfo.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/ClassInfo.php | BSD-3-Clause |
public static function classImplements($className, $interfaceName)
{
$lowerClassName = strtolower($className ?? '');
$implementors = ClassInfo::implementorsOf($interfaceName);
return isset($implementors[$lowerClassName]);
} | Returns true if the given class implements the given interface
@param string $className
@param string $interfaceName
@return bool | classImplements | php | silverstripe/silverstripe-framework | src/Core/ClassInfo.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/ClassInfo.php | BSD-3-Clause |
public static function classes_for_file($filePath)
{
$absFilePath = Convert::slashes(Director::getAbsFile($filePath));
$classManifest = ClassLoader::inst()->getManifest();
$classes = $classManifest->getClasses();
$classNames = $classManifest->getClassNames();
$matchedClasses = [];
foreach ($classes as $lowerClass => $compareFilePath) {
if (strcasecmp($absFilePath, Convert::slashes($compareFilePath ?? '')) === 0) {
$matchedClasses[$lowerClass] = $classNames[$lowerClass];
}
}
return $matchedClasses;
} | Get all classes contained in a file.
@param string $filePath Path to a PHP file (absolute or relative to webroot)
@return array Map of lowercase class names to correct class name | classes_for_file | php | silverstripe/silverstripe-framework | src/Core/ClassInfo.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/ClassInfo.php | BSD-3-Clause |
public static function classes_for_folder($folderPath)
{
$absFolderPath = Convert::slashes(Director::getAbsFile($folderPath));
$classManifest = ClassLoader::inst()->getManifest();
$classes = $classManifest->getClasses();
$classNames = $classManifest->getClassNames();
$matchedClasses = [];
foreach ($classes as $lowerClass => $compareFilePath) {
if (stripos(Convert::slashes($compareFilePath ?? ''), $absFolderPath) === 0) {
$matchedClasses[$lowerClass] = $classNames[$lowerClass];
}
}
return $matchedClasses;
} | Returns all classes contained in a certain folder.
@param string $folderPath Relative or absolute folder path
@return array Map of lowercase class names to correct class name | classes_for_folder | php | silverstripe/silverstripe-framework | src/Core/ClassInfo.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/ClassInfo.php | BSD-3-Clause |
public static function has_method_from($class, $method, $compclass)
{
$lClass = strtolower($class ?? '');
$lMethod = strtolower($method ?? '');
$lCompclass = strtolower($compclass ?? '');
if (!isset(ClassInfo::$_cache_methods[$lClass])) {
ClassInfo::$_cache_methods[$lClass] = [];
}
if (!array_key_exists($lMethod, ClassInfo::$_cache_methods[$lClass] ?? [])) {
ClassInfo::$_cache_methods[$lClass][$lMethod] = false;
$classRef = new ReflectionClass($class);
if ($classRef->hasMethod($method)) {
$methodRef = $classRef->getMethod($method);
ClassInfo::$_cache_methods[$lClass][$lMethod] = $methodRef->getDeclaringClass()->getName();
}
}
return strtolower(ClassInfo::$_cache_methods[$lClass][$lMethod] ?? '') === $lCompclass;
} | Determine if the given class method is implemented at the given comparison class
@param string $class Class to get methods from
@param string $method Method name to lookup
@param string $compclass Parent class to test if this is the implementor
@return bool True if $class::$method is declared in $compclass | has_method_from | php | silverstripe/silverstripe-framework | src/Core/ClassInfo.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/ClassInfo.php | BSD-3-Clause |
public static function hasMethod($object, $method)
{
if (empty($object) || (!is_object($object) && !is_string($object))) {
return false;
}
if (method_exists($object, $method ?? '')) {
return true;
}
return method_exists($object, 'hasMethod') && $object->hasMethod($method);
} | Helper to determine if the given object has a method
@param object $object
@param string $method
@return bool | hasMethod | php | silverstripe/silverstripe-framework | src/Core/ClassInfo.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/ClassInfo.php | BSD-3-Clause |
public static function join(...$parts)
{
// In case $parts passed as an array in first parameter
if (count($parts ?? []) === 1 && is_array($parts[0])) {
$parts = $parts[0];
}
// Cleanup and join all parts
$parts = array_filter(array_map('trim', array_filter($parts ?? [])));
$fullPath = static::normalise(implode(DIRECTORY_SEPARATOR, $parts));
// Protect against directory traversal vulnerability (OTG-AUTHZ-001)
if ($fullPath === '..' || str_ends_with($fullPath, '/..') || str_contains($fullPath, '../')) {
throw new InvalidArgumentException('Can not collapse relative folders');
}
return $fullPath ?: DIRECTORY_SEPARATOR;
} | Joins one or more paths, normalising all separators to DIRECTORY_SEPARATOR
Note: Errors on collapsed `/../` for security reasons. Use realpath() if you need to
join a trusted relative path.
@link https://www.owasp.org/index.php/Testing_Directory_traversal/file_include_(OTG-AUTHZ-001)
@see File::join_paths() for joining file identifiers
@param array $parts
@return string Combined path, not including trailing slash (unless it's a single slash) | join | php | silverstripe/silverstripe-framework | src/Core/Path.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Path.php | BSD-3-Clause |
public static function normalise($path, $relative = false)
{
$path = trim(Convert::slashes($path) ?? '');
if ($relative) {
return trim($path ?? '', Path::TRIM_CHARS ?? '');
} else {
return rtrim($path ?? '', Path::TRIM_CHARS ?? '');
}
} | Normalise absolute or relative filesystem path.
Important: Single slashes are converted to empty strings (empty relative paths)
@param string $path Input path
@param bool $relative
@return string Path with no trailing slash. If $relative is true, also trim leading slashes | normalise | php | silverstripe/silverstripe-framework | src/Core/Path.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Path.php | BSD-3-Clause |
public static function add_to_class($class, $extensionClass, $args = null)
{
// NOP
} | Called when this extension is added to a particular class
@param string $class
@param string $extensionClass
@param mixed $args | add_to_class | php | silverstripe/silverstripe-framework | src/Core/Extension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Extension.php | BSD-3-Clause |
public function setOwner($owner)
{
$this->ownerStack[] = $this->owner;
$this->owner = $owner;
} | Set the owner of this extension.
@param object $owner The owner object | setOwner | php | silverstripe/silverstripe-framework | src/Core/Extension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Extension.php | BSD-3-Clause |
public function clearOwner()
{
if (empty($this->ownerStack)) {
throw new BadMethodCallException("clearOwner() called more than setOwner()");
}
$this->owner = array_pop($this->ownerStack);
} | Clear the current owner, and restore extension to the state prior to the last setOwner() | clearOwner | php | silverstripe/silverstripe-framework | src/Core/Extension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Extension.php | BSD-3-Clause |
public function getOwner()
{
return $this->owner;
} | Returns the owner of this extension.
@return T | getOwner | php | silverstripe/silverstripe-framework | src/Core/Extension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Extension.php | BSD-3-Clause |
public static function get_classname_without_arguments($extensionStr)
{
// Split out both args and service name
return strtok(strtok($extensionStr ?? '', '(') ?? '', '.');
} | Helper method to strip eval'ed arguments from a string
that's passed to {@link DataObject::$extensions} or
{@link Object::add_extension()}.
@param string $extensionStr E.g. "Versioned('Stage','Live')"
@return string Extension classname, e.g. "Versioned" | get_classname_without_arguments | php | silverstripe/silverstripe-framework | src/Core/Extension.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Extension.php | BSD-3-Clause |
protected function validateDatabase()
{
if (!$this->bootDatabase) {
return;
}
$databaseConfig = DB::getConfig();
// Gracefully fail if no DB is configured
if (empty($databaseConfig['database'])) {
$msg = 'Silverstripe Framework requires a "database" key in DB::getConfig(). ' .
'Did you forget to set SS_DATABASE_NAME or SS_DATABASE_CHOOSE_NAME in your environment?';
$this->detectLegacyEnvironment();
Deprecation::withSuppressedNotice(fn() => $this->redirectToInstaller($msg));
}
} | Check that the database configuration is valid, throwing an HTTPResponse_Exception if it's not
@throws HTTPResponse_Exception | validateDatabase | php | silverstripe/silverstripe-framework | src/Core/CoreKernel.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/CoreKernel.php | BSD-3-Clause |
protected function bootDatabaseGlobals()
{
if (!$this->bootDatabase) {
return;
}
// Now that configs have been loaded, we can check global for database config
global $databaseConfig;
global $database;
// Case 1: $databaseConfig global exists. Merge $database in as needed
if (!empty($databaseConfig)) {
if (!empty($database)) {
$databaseConfig['database'] = $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
}
// Only set it if its valid, otherwise ignore $databaseConfig entirely
if (!empty($databaseConfig['database'])) {
DB::setConfig($databaseConfig);
return;
}
}
// Case 2: $database merged into existing config
if (!empty($database)) {
$existing = DB::getConfig();
$existing['database'] = $this->getDatabasePrefix() . $database . $this->getDatabaseSuffix();
DB::setConfig($existing);
}
} | Load default database configuration from the $database and $databaseConfig globals | bootDatabaseGlobals | php | silverstripe/silverstripe-framework | src/Core/CoreKernel.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/CoreKernel.php | BSD-3-Clause |
protected function bootDatabaseEnvVars()
{
if (!$this->bootDatabase) {
return;
}
// Set default database config
$databaseConfig = $this->getDatabaseConfig();
$databaseConfig['database'] = $this->getDatabaseName();
DB::setConfig($databaseConfig);
} | Load default database configuration from environment variable | bootDatabaseEnvVars | php | silverstripe/silverstripe-framework | src/Core/CoreKernel.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/CoreKernel.php | BSD-3-Clause |
public function createRoot()
{
$instance = new CachedConfigCollection();
// Override nested config to use delta collection
$instance->setNestFactory(function ($collection) {
return DeltaConfigCollection::createFromCollection($collection, Config::NO_DELTAS);
});
// Create config cache
if ($this->cacheFactory) {
$cache = $this->cacheFactory->create(CacheInterface::class . '.configcache', [
'namespace' => 'configcache'
]);
$instance->setCache($cache);
}
// Set collection creator
$instance->setCollectionCreator(function () {
return $this->createCore();
});
return $instance;
} | Create root application config.
This will be an immutable cached config,
which conditionally generates a nested "core" config.
@return CachedConfigCollection | createRoot | php | silverstripe/silverstripe-framework | src/Core/Config/CoreConfigFactory.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/CoreConfigFactory.php | BSD-3-Clause |
public function createCore()
{
$config = new MemoryConfigCollection();
// Set default middleware
$config->setMiddlewares([
new InheritanceMiddleware(Config::UNINHERITED),
new ExtensionMiddleware(Config::EXCLUDE_EXTRA_SOURCES),
]);
// Transform
$config->transform([
$this->buildStaticTransformer(),
$this->buildYamlTransformer()
]);
return $config;
} | Rebuild new uncached config, which is mutable
@return MemoryConfigCollection | createCore | php | silverstripe/silverstripe-framework | src/Core/Config/CoreConfigFactory.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/CoreConfigFactory.php | BSD-3-Clause |
public function getManifest()
{
if ($this !== ConfigLoader::$instance) {
throw new BadMethodCallException(
"Non-current config manifest cannot be accessed. Please call ->activate() first"
);
}
if (empty($this->manifests)) {
throw new BadMethodCallException("No config manifests available");
}
return $this->manifests[count($this->manifests) - 1];
} | Returns the currently active class manifest instance that is used for
loading classes.
@return ConfigCollectionInterface | getManifest | php | silverstripe/silverstripe-framework | src/Core/Config/ConfigLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/ConfigLoader.php | BSD-3-Clause |
public function hasManifest()
{
return (bool)$this->manifests;
} | Returns true if this class loader has a manifest.
@return bool | hasManifest | php | silverstripe/silverstripe-framework | src/Core/Config/ConfigLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/ConfigLoader.php | BSD-3-Clause |
public function pushManifest(ConfigCollectionInterface $manifest)
{
$this->manifests[] = $manifest;
} | Pushes a class manifest instance onto the top of the stack.
@param ConfigCollectionInterface $manifest | pushManifest | php | silverstripe/silverstripe-framework | src/Core/Config/ConfigLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/ConfigLoader.php | BSD-3-Clause |
public function nest()
{
// Nest config
$manifest = clone $this->getManifest();
// Create new blank loader with new stack (top level nesting)
$newLoader = new static;
$newLoader->pushManifest($manifest);
// Activate new loader
return $newLoader->activate();
} | Nest the config loader and activates it
@return static | nest | php | silverstripe/silverstripe-framework | src/Core/Config/ConfigLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/ConfigLoader.php | BSD-3-Clause |
public function activate()
{
static::$instance = $this;
return $this;
} | Mark this instance as the current instance
@return $this | activate | php | silverstripe/silverstripe-framework | src/Core/Config/ConfigLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/ConfigLoader.php | BSD-3-Clause |
public static function inst()
{
return ConfigLoader::inst()->getManifest();
} | Get the current active Config instance.
In general use you will use this method to obtain the current Config
instance. It assumes the config instance has already been set.
@return ConfigCollectionInterface | inst | php | silverstripe/silverstripe-framework | src/Core/Config/Config.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/Config.php | BSD-3-Clause |
public static function modify()
{
$instance = static::inst();
if ($instance instanceof MutableConfigCollectionInterface) {
return $instance;
}
// By default nested configs should become mutable
$instance = static::nest();
if ($instance instanceof MutableConfigCollectionInterface) {
return $instance;
}
throw new InvalidArgumentException("Nested config could not be made mutable");
} | Make this config available to be modified
@return MutableConfigCollectionInterface | modify | php | silverstripe/silverstripe-framework | src/Core/Config/Config.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/Config.php | BSD-3-Clause |
public static function nest()
{
// Clone current config and nest
$new = Config::inst()->nest();
ConfigLoader::inst()->pushManifest($new);
return $new;
} | Make the newly active {@link Config} be a copy of the current active
{@link Config} instance.
You can then make changes to the configuration by calling update and
remove on the new value returned by {@link Config::inst()}, and then discard
those changes later by calling unnest.
@return ConfigCollectionInterface Active config | nest | php | silverstripe/silverstripe-framework | src/Core/Config/Config.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/Config.php | BSD-3-Clause |
public static function unnest()
{
// Unnest unless we would be left at 0 manifests
$loader = ConfigLoader::inst();
if ($loader->countManifests() <= 1) {
user_error(
"Unable to unnest root Config, please make sure you don't have mis-matched nest/unnest",
E_USER_WARNING
);
} else {
$loader->popManifest();
}
return static::inst();
} | Change the active Config back to the Config instance the current active
Config object was copied from.
@return ConfigCollectionInterface | unnest | php | silverstripe/silverstripe-framework | src/Core/Config/Config.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/Config.php | BSD-3-Clause |
public static function forClass($class)
{
return new Config_ForClass($class);
} | Get an accessor that returns results by class by default.
Shouldn't be overridden, since there might be many Config_ForClass instances already held in the wild. Each
Config_ForClass instance asks the current_instance of Config for the actual result, so override that instead
@param string $class
@return Config_ForClass | forClass | php | silverstripe/silverstripe-framework | src/Core/Config/Config.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/Config.php | BSD-3-Clause |
public static function config()
{
return Config::forClass(get_called_class());
} | Get a configuration accessor for this class. Short hand for Config::inst()->get($this->class, .....).
@return Config_ForClass | config | php | silverstripe/silverstripe-framework | src/Core/Config/Configurable.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/Configurable.php | BSD-3-Clause |
public function uninherited($name)
{
return $this->config()->uninherited($name);
} | Gets the uninherited value for the given config option
@param string $name
@return mixed | uninherited | php | silverstripe/silverstripe-framework | src/Core/Config/Configurable.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Config/Configurable.php | BSD-3-Clause |
public function hit()
{
if (!$this->getCache()->has($this->getIdentifier())) {
$ttl = $this->getDecay() * 60;
$expiry = DBDatetime::now()->getTimestamp() + $ttl;
$this->getCache()->set($this->getIdentifier() . '-timer', $expiry, $ttl);
} else {
$expiry = $this->getCache()->get($this->getIdentifier() . '-timer');
$ttl = $expiry - DBDatetime::now()->getTimestamp();
}
$this->getCache()->set($this->getIdentifier(), $this->getNumAttempts() + 1, $ttl);
return $this;
} | Store a hit in the rate limit cache
@return $this | hit | php | silverstripe/silverstripe-framework | src/Core/Cache/RateLimiter.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Cache/RateLimiter.php | BSD-3-Clause |
public function create($service, array $params = [])
{
// Override default cache generation with SS_MANIFESTCACHE
$cacheClass = Environment::getEnv('SS_MANIFESTCACHE');
$params['useInjector'] = false;
if (!$cacheClass) {
return parent::create($service, $params);
}
// Check if SS_MANIFESTCACHE is a factory
if (is_a($cacheClass, CacheFactory::class, true)) {
/** @var CacheFactory $factory */
$factory = new $cacheClass;
return $factory->create($service, $params);
}
// Check if SS_MANIFESTCACHE is a PSR-6 or PSR-16 class
if (is_a($cacheClass, CacheItemPoolInterface::class, true) ||
is_a($cacheClass, CacheInterface::class, true)
) {
$args = array_merge($this->args, $params);
$namespace = isset($args['namespace']) ? $args['namespace'] : '';
return $this->createCache($cacheClass, [$namespace], false);
}
// Validate type
throw new BadMethodCallException(
'SS_MANIFESTCACHE is not a valid CacheInterface, CacheItemPoolInterface or CacheFactory class name'
);
} | Note: While the returned object is used as a singleton (by the originating Injector->get() call),
this cache object shouldn't be a singleton itself - it has varying constructor args for the same service name.
@param string $service The class name of the service.
@param array $params The constructor parameters.
@return CacheInterface | create | php | silverstripe/silverstripe-framework | src/Core/Cache/ManifestCacheFactory.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Cache/ManifestCacheFactory.php | BSD-3-Clause |
protected function isAPCUSupported()
{
Deprecation::noticeWithNoReplacment('5.4.0');
static $apcuSupported = null;
if (null === $apcuSupported) {
// Need to check for CLI because Symfony won't: https://github.com/symfony/symfony/pull/25080
$apcuSupported = Director::is_cli()
? filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOL) && ApcuAdapter::isSupported()
: ApcuAdapter::isSupported();
}
return $apcuSupported;
} | Determine if apcu is supported
@return bool
@deprecated 5.4.0 Will be removed without equivalent functionality to replace it. | isAPCUSupported | php | silverstripe/silverstripe-framework | src/Core/Cache/DefaultCacheFactory.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Cache/DefaultCacheFactory.php | BSD-3-Clause |
protected function isPHPFilesSupported()
{
static $phpFilesSupported = null;
if (null === $phpFilesSupported) {
$phpFilesSupported = PhpFilesAdapter::isSupported();
}
return $phpFilesSupported;
} | Determine if PHP files is supported
@return bool | isPHPFilesSupported | php | silverstripe/silverstripe-framework | src/Core/Cache/DefaultCacheFactory.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Cache/DefaultCacheFactory.php | BSD-3-Clause |
protected function getCacheTimestamp()
{
$classLoader = $this->kernel->getClassLoader();
$classManifest = $classLoader->getManifest();
$cacheTimestamp = $classManifest->getManifestTimestamp();
return $cacheTimestamp;
} | Returns the timestamp of the manifest generation or null
if no cache has been found (or couldn't read the cache)
@return int|null unix timestamp | getCacheTimestamp | php | silverstripe/silverstripe-framework | src/Core/Startup/DeployFlushDiscoverer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Startup/DeployFlushDiscoverer.php | BSD-3-Clause |
protected function getDeployResource()
{
$resource = Environment::getEnv('SS_FLUSH_ON_DEPLOY');
if ($resource === false) {
return null;
}
if ($resource === true) {
$path = __FILE__;
} else {
$path = sprintf("%s/%s", BASE_PATH, $resource);
}
return $path;
} | Returns the resource to be checked for deployment
- if the environment variable SS_FLUSH_ON_DEPLOY undefined or false, then returns null
- if SS_FLUSH_ON_DEPLOY is true, then takes __FILE__ as the resource to check
- otherwise takes {BASE_PATH/SS_FLUSH_ON_DEPLOY} as the resource to check
@return string|null returns the resource path or null if not set | getDeployResource | php | silverstripe/silverstripe-framework | src/Core/Startup/DeployFlushDiscoverer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Startup/DeployFlushDiscoverer.php | BSD-3-Clause |
protected function getDeployTimestamp($resource)
{
if (!file_exists($resource ?? '')) {
return 0;
}
return max(filemtime($resource ?? ''), filectime($resource ?? ''));
} | Returns the resource modification timestamp
@param string $resource Path to the filesystem
@return int | getDeployTimestamp | php | silverstripe/silverstripe-framework | src/Core/Startup/DeployFlushDiscoverer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Startup/DeployFlushDiscoverer.php | BSD-3-Clause |
public function __construct(HTTPRequest $request, $env)
{
$this->env = $env;
$this->request = $request;
} | Initialize it with active Request and Kernel
@param HTTPRequest $request instance of the request (session is not initialized yet!)
@param string $env Environment type (dev, test or live) | __construct | php | silverstripe/silverstripe-framework | src/Core/Startup/RequestFlushDiscoverer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Startup/RequestFlushDiscoverer.php | BSD-3-Clause |
protected function lookupRequest()
{
$request = $this->request;
$getVar = array_key_exists('flush', $request->getVars() ?? []);
$devBuild = $request->getURL() === 'dev/build';
// WARNING!
// We specifically return `null` and not `false` here so that
// it does not override other FlushDiscoverers
return ($getVar || $devBuild) ? true : null;
} | Checks whether the request contains any flush indicators
@return null|bool flush or don't care | lookupRequest | php | silverstripe/silverstripe-framework | src/Core/Startup/RequestFlushDiscoverer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Startup/RequestFlushDiscoverer.php | BSD-3-Clause |
protected function isAllowed()
{
// WARNING!
// We specifically return `null` and not `false` here so that
// it does not override other FlushDiscoverers
return (Environment::isCli() || $this->env === Kernel::DEV) ? true : null;
} | Checks for permission to flush
Startup flush through a request is only allowed
to CLI or DEV modes for security reasons
@return bool|null true for allow, false for denying, or null if don't care | isAllowed | php | silverstripe/silverstripe-framework | src/Core/Startup/RequestFlushDiscoverer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Startup/RequestFlushDiscoverer.php | BSD-3-Clause |
protected function getFlush()
{
$classLoader = $this->kernel->getClassLoader();
$classManifest = $classLoader->getManifest();
return (bool) $classManifest->isFlushScheduled();
} | Returns the flag whether the manifest flush
has been scheduled in previous requests
@return bool unix timestamp | getFlush | php | silverstripe/silverstripe-framework | src/Core/Startup/ScheduledFlushDiscoverer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Startup/ScheduledFlushDiscoverer.php | BSD-3-Clause |
public static function scheduleFlush(Kernel $kernel)
{
$classLoader = $kernel->getClassLoader();
$classManifest = $classLoader->getManifest();
if (!$classManifest->isFlushScheduled()) {
$classManifest->scheduleFlush();
return true;
}
return false;
} | @internal This method is not a part of public API and will be deleted without a deprecation warning
This method is here so that scheduleFlush functionality implementation is kept close to the check
implementation. | scheduleFlush | php | silverstripe/silverstripe-framework | src/Core/Startup/ScheduledFlushDiscoverer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Startup/ScheduledFlushDiscoverer.php | BSD-3-Clause |
public function __construct(callable $callback)
{
$this->callback = $callback;
} | Construct the discoverer from a callback
@param Callable $callback returning FlushDiscoverer response or a timestamp | __construct | php | silverstripe/silverstripe-framework | src/Core/Startup/CallbackFlushDiscoverer.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Startup/CallbackFlushDiscoverer.php | BSD-3-Clause |
public static function getModule($module)
{
return static::inst()->getManifest()->getModule($module);
} | Get module by name from the current manifest.
Alias for ::inst()->getManifest()->getModule()
@param string $module
@return Module | getModule | php | silverstripe/silverstripe-framework | src/Core/Manifest/ModuleLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleLoader.php | BSD-3-Clause |
public function getManifest()
{
return $this->manifests[count($this->manifests) - 1];
} | Returns the currently active class manifest instance that is used for
loading classes.
@return ModuleManifest | getManifest | php | silverstripe/silverstripe-framework | src/Core/Manifest/ModuleLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleLoader.php | BSD-3-Clause |
public function hasManifest()
{
return (bool)$this->manifests;
} | Returns true if this class loader has a manifest.
@return bool | hasManifest | php | silverstripe/silverstripe-framework | src/Core/Manifest/ModuleLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleLoader.php | BSD-3-Clause |
public function pushManifest(ModuleManifest $manifest)
{
$this->manifests[] = $manifest;
} | Pushes a module manifest instance onto the top of the stack.
@param ModuleManifest $manifest | pushManifest | php | silverstripe/silverstripe-framework | src/Core/Manifest/ModuleLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleLoader.php | BSD-3-Clause |
public function resolvePath($resource)
{
// Skip blank resources
if (empty($resource)) {
return null;
}
$resourceObj = $this->resolveResource($resource);
if ($resourceObj instanceof ModuleResource) {
return $resourceObj->getRelativePath();
}
return $resource;
} | Convert a file of the form "vendor/package:resource" into a BASE_PATH-relative file or folder
For other files, return original value
@param string $resource
@return string|null | resolvePath | php | silverstripe/silverstripe-framework | src/Core/Manifest/ModuleResourceLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleResourceLoader.php | BSD-3-Clause |
public function resolveURL($resource)
{
// Skip blank resources
if (empty($resource)) {
return null;
}
// Resolve resource to reference
$resource = $this->resolveResource($resource);
// Resolve resource to url
$generator = Injector::inst()->get(ResourceURLGenerator::class);
return $generator->urlForResource($resource);
} | Resolves resource specifier to the given url.
@param string $resource
@return string|null | resolveURL | php | silverstripe/silverstripe-framework | src/Core/Manifest/ModuleResourceLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleResourceLoader.php | BSD-3-Clause |
public static function resourcePath($resource)
{
return static::singleton()->resolvePath($resource);
} | Template wrapper for resolvePath
@param string $resource
@return string|null | resourcePath | php | silverstripe/silverstripe-framework | src/Core/Manifest/ModuleResourceLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleResourceLoader.php | BSD-3-Clause |
public static function resourceURL($resource)
{
return static::singleton()->resolveURL($resource);
} | Template wrapper for resolveURL
@param string $resource
@return string|null | resourceURL | php | silverstripe/silverstripe-framework | src/Core/Manifest/ModuleResourceLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleResourceLoader.php | BSD-3-Clause |
public function resolveResource($resource)
{
// String of the form vendor/package:resource. Excludes "http://bla" as that's an absolute URL
if (!preg_match('#^ *(?<module>[^/: ]+/[^/: ]+) *: *(?<resource>[^ ]*)$#', $resource ?? '', $matches)) {
return $resource;
}
$module = $matches['module'];
$resource = $matches['resource'];
$moduleObj = ModuleLoader::getModule($module);
if (!$moduleObj) {
throw new InvalidArgumentException("Can't find module '$module', the composer.json file may be missing from the modules installation directory");
}
$resourceObj = $moduleObj->getResource($resource);
return $resourceObj;
} | Return module resource for the given path, if specified as one.
Returns the original resource otherwise.
@param string $resource
@return ModuleResource|string The resource (or directory), or input string if not a module resource | resolveResource | php | silverstripe/silverstripe-framework | src/Core/Manifest/ModuleResourceLoader.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/Core/Manifest/ModuleResourceLoader.php | BSD-3-Clause |
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 getInterfaces()
{
return $this->interfaces;
} | Returns a map of lowercased interface names to file locations.
@return array | getInterfaces | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.