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 setTable($tableName) { $this->tableName = $tableName; return $this; }
Assign this DBField to a table @param string $tableName @return $this
setTable
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function getTable() { return $this->tableName; }
Get the table this field belongs to, if assigned @return string|null
getTable
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function forTemplate() { // Default to XML encoding return $this->XML(); }
Determine 'default' casting for this field. @return string
forTemplate
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function HTMLATT() { return Convert::raw2htmlatt($this->RAW()); }
Gets the value appropriate for a HTML attribute string @return string
HTMLATT
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function RAW() { return $this->getValue(); }
Gets the raw value for this field. Note: Skips processors implemented via forTemplate() @return mixed
RAW
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function JS() { return Convert::raw2js($this->RAW()); }
Gets javascript string literal value @return string
JS
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function nullValue() { return null; }
Returns the value to be set in the database to blank this field. Usually it's a choice between null, 0, and '' @return mixed
nullValue
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function saveInto($dataObject) { $fieldName = $this->name; if (empty($fieldName)) { throw new \BadMethodCallException( "DBField::saveInto() Called on a nameless '" . static::class . "' object" ); } if ($this->value instanceof DBField) { $this->value->saveInto($dataObject); } else { $dataObject->__set($fieldName, $this->value); } }
Saves this field to the given data object. @param DataObject $dataObject
saveInto
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function scaffoldSearchField($title = null) { return $this->scaffoldFormField($title); }
Returns a FormField instance used as a default for searchform scaffolding. Used by {@link SearchContext}, {@link ModelAdmin}, {@link DataObject::scaffoldFormFields()}. @param string $title Optional. Localized title of the generated instance @return FormField
scaffoldSearchField
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function scalarValueOnly() { return true; }
Whether or not this DBField only accepts scalar values. Composite DBFields can override this method and return `false` so they can accept arrays of values. @return boolean
scalarValueOnly
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBField.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBField.php
BSD-3-Clause
public function Nice() { if (!$this->exists()) { return null; } $amount = $this->getAmount(); $currency = $this->getCurrency(); // Without currency, format as basic localised number $formatter = $this->getFormatter(); if (!$currency) { return $formatter->format($amount); } // Localise currency return $formatter->formatCurrency($amount, $currency); }
Get nicely formatted currency (based on current locale) @return string
Nice
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBMoney.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBMoney.php
BSD-3-Clause
public function getValue() { if (!$this->exists()) { return null; } $amount = $this->getAmount(); $currency = $this->getCurrency(); if (empty($currency)) { return $amount; } return $amount . ' ' . $currency; }
Standard '0.00 CUR' format (non-localised) @return string
getValue
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBMoney.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBMoney.php
BSD-3-Clause
public function hasAmount() { $a = $this->getAmount(); return (!empty($a) && is_numeric($a)); }
Determine if this has a non-zero amount @return bool
hasAmount
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBMoney.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBMoney.php
BSD-3-Clause
public function bindTo($dataObject) { $this->record = $dataObject; }
Bind this field to the dataobject, and set the underlying table to that of the owner @param DataObject $dataObject
bindTo
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBComposite.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBComposite.php
BSD-3-Clause
public function getField($field) { // Skip invalid fields $fields = $this->compositeDatabaseFields(); if (!isset($fields[$field])) { return null; } // Check bound object if ($this->record instanceof DataObject) { $key = $this->getName() . $field; return $this->record->getField($key); } // Check local record if (isset($this->record[$field])) { return $this->record[$field]; } return null; }
get value of a single composite field @param string $field @return mixed
getField
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBComposite.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBComposite.php
BSD-3-Clause
public function setField($field, $value, $markChanged = true) { $this->objCacheClear(); if (!$this->hasField($field)) { throw new InvalidArgumentException(implode(' ', [ "Field $field does not exist.", 'If this was accessed via a dynamic property then call setDynamicData() instead.' ])); } // Set changed if ($markChanged) { $this->isChanged = true; } // Set bound object if ($this->record instanceof DataObject) { $key = $this->getName() . $field; $this->record->setField($key, $value); return $this; } // Set local record $this->record[$field] = $value; return $this; }
Set value of a single composite field @param string $field @param mixed $value @param bool $markChanged @return $this
setField
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBComposite.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBComposite.php
BSD-3-Clause
public function dbObject($field) { $fields = $this->compositeDatabaseFields(); if (!isset($fields[$field])) { return null; } // Build nested field $key = $this->getName() . $field; $spec = $fields[$field]; /** @var DBField $fieldObject */ $fieldObject = Injector::inst()->create($spec, $key); $fieldObject->setValue($this->getField($field), null, false); return $fieldObject; }
Get a db object for the named field @param string $field Field name @return DBField|null
dbObject
php
silverstripe/silverstripe-framework
src/ORM/FieldType/DBComposite.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBComposite.php
BSD-3-Clause
public function __construct($modelClass, $fields = null, $filters = null) { $this->modelClass = $modelClass; $this->fields = ($fields) ? $fields : new FieldList(); $this->filters = ($filters) ? $filters : []; }
A key value pair of values that should be searched for. The keys should match the field names specified in {@link SearchContext::$fields}. Usually these values come from a submitted searchform in the form of a $_REQUEST object. CAUTION: All values should be treated as insecure client input. @param class-string<T> $modelClass The base {@link DataObject} class that search properties related to. Also used to generate a set of result objects based on this class. @param FieldList $fields Optional. FormFields mapping to {@link DataObject::$db} properties which are to be searched. Derived from modelclass using {@link DataObject::scaffoldSearchFields()} if left blank. @param array $filters Optional. Derived from modelclass if left blank
__construct
php
silverstripe/silverstripe-framework
src/ORM/Search/SearchContext.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Search/SearchContext.php
BSD-3-Clause
public function getSearchFields() { if ($this->fields?->exists()) { return $this->fields; } $singleton = singleton($this->modelClass); if (!$singleton->hasMethod('scaffoldSearchFields')) { throw new LogicException( 'Cannot dynamically determine search fields. Pass the fields to setFields()' . " or implement a scaffoldSearchFields() method on {$this->modelClass}" ); } return $singleton->scaffoldSearchFields(); }
Returns scaffolded search fields for UI. @return FieldList
getSearchFields
php
silverstripe/silverstripe-framework
src/ORM/Search/SearchContext.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Search/SearchContext.php
BSD-3-Clause
public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = null) { if ((count(func_get_args()) >= 3) && (!in_array(gettype($limit), ['integer', 'array', 'NULL']))) { Deprecation::notice( '5.1.0', '$limit should be type of int|array|null' ); $limit = null; } $this->setSearchParams($searchParams); $query = $this->prepareQuery($sort, $limit, $existingQuery); return $this->search($query); }
Returns a SQL object representing the search context for the given list of query parameters. @param array $searchParams Map of search criteria, mostly taken from $_REQUEST. If a filter is applied to a relationship in dot notation, the parameter name should have the dots replaced with double underscores, for example "Comments__Name" instead of the filter name "Comments.Name". @param array|bool|string $sort Database column to sort on. Falls back to {@link DataObject::$default_sort} if not provided. @param int|array|null $limit @param DataList $existingQuery @return DataList<T> @throws Exception
getQuery
php
silverstripe/silverstripe-framework
src/ORM/Search/SearchContext.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Search/SearchContext.php
BSD-3-Clause
public function getResults($searchParams, $sort = false, $limit = null) { $searchParams = array_filter((array)$searchParams, [$this, 'clearEmptySearchFields']); // getQuery actually returns a DataList return $this->getQuery($searchParams, $sort, $limit); }
Returns a result set from the given search parameters. @param array $searchParams @param array|bool|string $sort @param array|null|string $limit @return DataList<T> @throws Exception
getResults
php
silverstripe/silverstripe-framework
src/ORM/Search/SearchContext.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Search/SearchContext.php
BSD-3-Clause
public function clearEmptySearchFields($value) { return ($value != ''); }
Callback map function to filter fields with empty values from being included in the search expression. @param mixed $value @return boolean
clearEmptySearchFields
php
silverstripe/silverstripe-framework
src/ORM/Search/SearchContext.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Search/SearchContext.php
BSD-3-Clause
public function getFilter($name) { if (isset($this->filters[$name])) { return $this->filters[$name]; } else { return null; } }
Accessor for the filter attached to a named field. @param string $name @return SearchFilter|null
getFilter
php
silverstripe/silverstripe-framework
src/ORM/Search/SearchContext.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Search/SearchContext.php
BSD-3-Clause
public function removeFieldByName($fieldName) { $this->fields?->removeByName($fieldName); }
Removes an existing formfield instance by its name. @param string $fieldName
removeFieldByName
php
silverstripe/silverstripe-framework
src/ORM/Search/SearchContext.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/Search/SearchContext.php
BSD-3-Clause
public static function parse_plurals($string) { if (strstr($string ?? '', '|') && strstr($string ?? '', '{count}')) { $keys = i18n::config()->uninherited('default_plurals'); $values = explode('|', $string ?? ''); if (count($keys ?? []) == count($values ?? [])) { return array_combine($keys ?? [], $values ?? []); } } return []; }
Split plural string into standard CLDR array form. A string is considered a pluralised form if it has a {count} argument, and a single `|` pipe-delimiting character. Note: Only splits in the default (en) locale as the string form contains limited metadata. @param string $string Input string @return array List of plural forms, or empty array if not plural
parse_plurals
php
silverstripe/silverstripe-framework
src/i18n/i18n.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/i18n.php
BSD-3-Clause
public static function encode_plurals($plurals) { // Validate against global plural list $forms = i18n::config()->uninherited('plurals'); $forms = array_combine($forms ?? [], $forms ?? []); $intersect = array_intersect_key($plurals ?? [], $forms); if ($intersect) { return implode('|', $intersect); } return null; }
Convert CLDR array plural form to `|` pipe-delimited string. Unlike parse_plurals, this supports all locale forms (not just en) @param array $plurals @return string Delimited string, or null if not plurals
encode_plurals
php
silverstripe/silverstripe-framework
src/i18n/i18n.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/i18n.php
BSD-3-Clause
public static function get_closest_translation($locale) { // Check if exact match $pool = i18n::getSources()->getKnownLocales(); if (isset($pool[$locale])) { return $locale; } // Fallback to best locale for common language $localesData = static::getData(); $lang = $localesData->langFromLocale($locale); $candidate = $localesData->localeFromLang($lang); if (isset($pool[$candidate])) { return $candidate; } return null; }
Matches a given locale with the closest translation available in the system @param string $locale locale code @return string Locale of closest available translation, if available
get_closest_translation
php
silverstripe/silverstripe-framework
src/i18n/i18n.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/i18n.php
BSD-3-Clause
public static function convert_rfc1766($locale) { return str_replace('_', '-', $locale ?? ''); }
Gets a RFC 1766 compatible language code, e.g. "en-US". @see http://www.ietf.org/rfc/rfc1766.txt @see http://tools.ietf.org/html/rfc2616#section-3.10 @param string $locale @return string
convert_rfc1766
php
silverstripe/silverstripe-framework
src/i18n/i18n.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/i18n.php
BSD-3-Clause
public static function get_script_direction($locale = null) { return static::getData()->scriptDirection($locale); }
Returns the script direction in format compatible with the HTML "dir" attribute. @see http://www.w3.org/International/tutorials/bidi-xhtml/ @param string $locale Optional locale incl. region (underscored) @return string "rtl" or "ltr"
get_script_direction
php
silverstripe/silverstripe-framework
src/i18n/i18n.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/i18n.php
BSD-3-Clause
public static function getSources() { return Injector::inst()->get(Sources::class); }
Get data sources for localisation strings @return Sources
getSources
php
silverstripe/silverstripe-framework
src/i18n/i18n.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/i18n.php
BSD-3-Clause
public static function getTranslatables($template, $warnIfEmpty = true) { // Run the parser and throw away the result $parser = new Parser($template, $warnIfEmpty); if (substr($template ?? '', 0, 3) == pack("CCC", 0xef, 0xbb, 0xbf)) { $parser->pos = 3; } $parser->match_TopTemplate(); return $parser->getEntities(); }
Parses a template and returns any translatable entities @param string $template String to parse for translations @param bool $warnIfEmpty Show warnings if default omitted @return array Map of keys -> values
getTranslatables
php
silverstripe/silverstripe-framework
src/i18n/TextCollection/Parser.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/TextCollection/Parser.php
BSD-3-Clause
protected function getConflicts($entitiesByModule) { $modules = array_keys($entitiesByModule ?? []); $allConflicts = []; // bubble-compare each group of modules for ($i = 0; $i < count($modules ?? []) - 1; $i++) { $left = array_keys($entitiesByModule[$modules[$i]] ?? []); for ($j = $i + 1; $j < count($modules ?? []); $j++) { $right = array_keys($entitiesByModule[$modules[$j]] ?? []); $conflicts = array_intersect($left ?? [], $right); $allConflicts = array_merge($allConflicts, $conflicts); } } return array_unique($allConflicts ?? []); }
Find all keys in the entity list that are duplicated across modules @param array $entitiesByModule @return array List of keys
getConflicts
php
silverstripe/silverstripe-framework
src/i18n/TextCollection/i18nTextCollector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/TextCollection/i18nTextCollector.php
BSD-3-Clause
protected function getBestModuleForKey($entitiesByModule, $key) { // Check classes $class = current(explode('.', $key ?? '')); if (array_key_exists($class, $this->classModuleCache ?? [])) { return $this->classModuleCache[$class]; } $owner = $this->findModuleForClass($class); if ($owner) { $this->classModuleCache[$class] = $owner; return $owner; } // Display notice if not found Debug::message( "Duplicate key {$key} detected in no / multiple modules with no obvious owner", false ); // Fall back to framework then cms modules foreach (['framework', 'cms'] as $module) { if (isset($entitiesByModule[$module][$key])) { $this->classModuleCache[$class] = $module; return $module; } } // Do nothing $this->classModuleCache[$class] = null; return null; }
Determine the best module to be given ownership over this key @param array $entitiesByModule @param string $key @return string Best module, if found
getBestModuleForKey
php
silverstripe/silverstripe-framework
src/i18n/TextCollection/i18nTextCollector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/TextCollection/i18nTextCollector.php
BSD-3-Clause
protected function findModuleForClass($class) { if (ClassInfo::exists($class)) { $module = ClassLoader::inst() ->getManifest() ->getOwnerModule($class); if ($module) { return $module->getName(); } } // If we can't find a class, see if it needs to be fully qualified if (strpos($class ?? '', '\\') !== false) { return null; } // Find FQN that ends with $class $classes = preg_grep( '/' . preg_quote("\\{$class}", '\/') . '$/i', ClassLoader::inst()->getManifest()->getClassNames() ?? [] ); // Find all modules for candidate classes $modules = array_unique(array_map(function ($class) { $module = ClassLoader::inst()->getManifest()->getOwnerModule($class); return $module ? $module->getName() : null; }, $classes ?? [])); if (count($modules ?? []) === 1) { return reset($modules); } // Couldn't find it! Exists in none, or multiple modules. return null; }
Given a partial class name, attempt to determine the best module to assign strings to. @param string $class Either a FQN class name, or a non-qualified class name. @return string Name of module
findModuleForClass
php
silverstripe/silverstripe-framework
src/i18n/TextCollection/i18nTextCollector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/TextCollection/i18nTextCollector.php
BSD-3-Clause
protected function getFileListForModule(Module $module) { $modulePath = $module->getPath(); // Search all .ss files in themes if (stripos($module->getRelativePath() ?? '', i18nTextCollector::THEME_PREFIX) === 0) { return $this->getFilesRecursive($modulePath, null, 'ss'); } // If non-standard module structure, search all root files if (!is_dir(Path::join($modulePath, 'code')) && !is_dir(Path::join($modulePath, 'src'))) { return $this->getFilesRecursive($modulePath); } // Get code files if (is_dir(Path::join($modulePath, 'src'))) { $files = $this->getFilesRecursive(Path::join($modulePath, 'src'), null, 'php'); } else { $files = $this->getFilesRecursive(Path::join($modulePath, 'code'), null, 'php'); } // Search for templates in this module if (is_dir(Path::join($modulePath, 'templates'))) { $templateFiles = $this->getFilesRecursive(Path::join($modulePath, 'templates'), null, 'ss'); } else { $templateFiles = $this->getFilesRecursive($modulePath, null, 'ss'); } return array_merge($files, $templateFiles); }
Retrieves the list of files for this module @param Module $module Module instance @return array List of files to parse
getFileListForModule
php
silverstripe/silverstripe-framework
src/i18n/TextCollection/i18nTextCollector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/TextCollection/i18nTextCollector.php
BSD-3-Clause
protected function normalizeEntity($fullName, $_namespace = null) { // split fullname into entity parts $entityParts = explode('.', $fullName ?? ''); if (count($entityParts ?? []) > 1) { // templates don't have a custom namespace $entity = array_pop($entityParts); // namespace might contain dots, so we explode $namespace = implode('.', $entityParts); } else { $entity = array_pop($entityParts); $namespace = $_namespace; } // If a dollar sign is used in the entity name, // we can't resolve without running the method, // and skip the processing. This is mostly used for // dynamically translating static properties, e.g. looping // through $db, which are detected by {@link collectFromEntityProviders}. if ($entity && strpos('$', $entity ?? '') !== false) { return false; } return "{$namespace}.{$entity}"; }
Normalizes entities with namespaces. @param string $fullName @param string $_namespace @return string|boolean FALSE
normalizeEntity
php
silverstripe/silverstripe-framework
src/i18n/TextCollection/i18nTextCollector.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/TextCollection/i18nTextCollector.php
BSD-3-Clause
protected function normaliseMessages($entities) { $messages = []; // Squash second and third levels together (class.key) foreach ($entities as $class => $keys) { // Check if namespace omits class if (!is_array($keys)) { $messages[$class] = $keys; } else { foreach ($keys as $key => $value) { $fullKey = "{$class}.{$key}"; $messages[$fullKey] = $value; } } } ksort($messages); return $messages; }
Flatten [class => [ key1 => value1, key2 => value2]] into [class.key1 => value1, class.key2 => value2] Inverse of YamlWriter::denormaliseMessages() @param array $entities @return mixed
normaliseMessages
php
silverstripe/silverstripe-framework
src/i18n/Messages/YamlReader.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/Messages/YamlReader.php
BSD-3-Clause
protected function denormaliseValue($value) { // Check plural form $plurals = $this->getPluralForm($value); if ($plurals) { return $plurals; } // Non-plural non-array is already denormalised if (!is_array($value)) { return $value; } // Denormalise from default key if (!empty($value['default'])) { return $this->denormaliseValue($value['default']); } // No value return null; }
Convert entities array format into yml-ready string / array @param array|string $value Input value @return array|string denormalised value
denormaliseValue
php
silverstripe/silverstripe-framework
src/i18n/Messages/YamlWriter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/Messages/YamlWriter.php
BSD-3-Clause
protected function getPluralForm($value) { // Strip non-plural keys away if (is_array($value)) { $forms = i18n::config()->uninherited('plurals'); $forms = array_combine($forms ?? [], $forms ?? []); return array_intersect_key($value ?? [], $forms); } // Parse from string // Note: Risky outside of 'en' locale. return i18n::parse_plurals($value); }
Get array-plural form for any value @param array|string $value @return array List of plural forms, or empty array if not plural
getPluralForm
php
silverstripe/silverstripe-framework
src/i18n/Messages/YamlWriter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/Messages/YamlWriter.php
BSD-3-Clause
public function getYaml($messages, $locale) { $entities = $this->denormaliseMessages($messages); $content = $this->getDumper()->dump([ $locale => $entities ], 99); return $content; }
Convert messages to yml ready to write @param array $messages @param string $locale @return string
getYaml
php
silverstripe/silverstripe-framework
src/i18n/Messages/YamlWriter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/Messages/YamlWriter.php
BSD-3-Clause
protected function getClassKey($entity) { $parts = explode('.', $entity ?? ''); $class = array_shift($parts); // Ensure the `.ss` suffix gets added to the top level class rather than the key if (count($parts ?? []) > 1 && reset($parts) === 'ss') { $class .= '.ss'; array_shift($parts); } $key = implode('.', $parts); return [$class, $key]; }
Determine class and key for a localisation entity @param string $entity @return array Two-length array with class and key as elements
getClassKey
php
silverstripe/silverstripe-framework
src/i18n/Messages/YamlWriter.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/Messages/YamlWriter.php
BSD-3-Clause
protected function load($locale) { if (isset($this->loadedLocales[$locale])) { return; } // Add full locale file. E.g. 'en_NZ' $this ->getTranslator() ->addResource('ss', $this->getSourceDirs(), $locale); // Add lang-only file. E.g. 'en' $lang = i18n::getData()->langFromLocale($locale); if ($lang !== $locale) { $this ->getTranslator() ->addResource('ss', $this->getSourceDirs(), $lang); } $this->loadedLocales[$locale] = true; }
Load resources for the given locale @param string $locale
load
php
silverstripe/silverstripe-framework
src/i18n/Messages/Symfony/SymfonyMessageProvider.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/Messages/Symfony/SymfonyMessageProvider.php
BSD-3-Clause
public function getSourceDirs() { if (!$this->sourceDirs) { $this->setSourceDirs(i18n::getSources()->getLangDirs()); } return $this->sourceDirs; }
Get the list of /lang dirs to load localisations from @return array
getSourceDirs
php
silverstripe/silverstripe-framework
src/i18n/Messages/Symfony/SymfonyMessageProvider.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/Messages/Symfony/SymfonyMessageProvider.php
BSD-3-Clause
public function setSourceDirs($sourceDirs) { $this->sourceDirs = $sourceDirs; return $this; }
Set the list of /lang dirs to load localisations from @param array $sourceDirs @return $this
setSourceDirs
php
silverstripe/silverstripe-framework
src/i18n/Messages/Symfony/SymfonyMessageProvider.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/Messages/Symfony/SymfonyMessageProvider.php
BSD-3-Clause
protected function templateInjection($injection) { $injection = $injection ?: []; // Rewrite injection to {} surrounded placeholders $arguments = array_combine( array_map(function ($val) { return '{' . $val . '}'; }, array_keys($injection ?? [])), $injection ?? [] ); return $arguments; }
Generate template safe injection parameters @param array $injection @return array Injection array with all keys surrounded with {} placeholders
templateInjection
php
silverstripe/silverstripe-framework
src/i18n/Messages/Symfony/SymfonyMessageProvider.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/Messages/Symfony/SymfonyMessageProvider.php
BSD-3-Clause
protected function normalisePlurals($parts) { return implode('|', $parts); }
Convert ruby i18n plural form to symfony pipe-delimited form. @param array $parts @return array|string
normalisePlurals
php
silverstripe/silverstripe-framework
src/i18n/Messages/Symfony/SymfonyMessageProvider.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/Messages/Symfony/SymfonyMessageProvider.php
BSD-3-Clause
protected function normaliseMessage($key, $value, $locale) { if (!is_array($value)) { return $value; } if (isset($value['default'])) { return $value['default']; } // Plurals $pluralised = i18n::encode_plurals($value); if ($pluralised) { return $pluralised; } // Warn if mismatched plural forms trigger_error("Localisation entity {$locale}.{$key} is invalid", E_USER_WARNING); return null; }
Normalise rails-yaml plurals into pipe-separated rules @link http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html @link http://guides.rubyonrails.org/i18n.html#pluralization @link http://symfony.com/doc/current/components/translation/usage.html#component-translation-pluralization @param string $key @param mixed $value Input value @param string $locale @return string
normaliseMessage
php
silverstripe/silverstripe-framework
src/i18n/Messages/Symfony/ModuleYamlLoader.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/i18n/Messages/Symfony/ModuleYamlLoader.php
BSD-3-Clause
public function createObject($name, $identifier, $data = null) { if (!isset($this->blueprints[$name])) { $this->blueprints[$name] = new FixtureBlueprint($name); } $blueprint = $this->blueprints[$name]; $obj = $blueprint->createObject($identifier, $data, $this->fixtures); $class = $blueprint->getClass(); if (!isset($this->fixtures[$class])) { $this->fixtures[$class] = []; } $this->fixtures[$class][$identifier] = $obj->ID; return $obj; }
Writes the fixture into the database using DataObjects @param string $name Name of the {@link FixtureBlueprint} to use, usually a DataObject subclass. @param string $identifier Unique identifier for this fixture type @param array $data Map of properties. Overrides default data. @return DataObject
createObject
php
silverstripe/silverstripe-framework
src/Dev/FixtureFactory.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/FixtureFactory.php
BSD-3-Clause
public function getId($class, $identifier) { if (isset($this->fixtures[$class][$identifier])) { return $this->fixtures[$class][$identifier]; } else { return false; } }
Get the ID of an object from the fixture. @param string $class The data class, as specified in your fixture file. Parent classes won't work @param string $identifier The identifier string, as provided in your fixture file @return int|false
getId
php
silverstripe/silverstripe-framework
src/Dev/FixtureFactory.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/FixtureFactory.php
BSD-3-Clause
public function getIds($class) { if (isset($this->fixtures[$class])) { return $this->fixtures[$class]; } else { return false; } }
Return all of the IDs in the fixture of a particular class name. @param string $class The data class or table name @return array|false A map of fixture-identifier => object-id
getIds
php
silverstripe/silverstripe-framework
src/Dev/FixtureFactory.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/FixtureFactory.php
BSD-3-Clause
public function get($class, $identifier) { $id = $this->getId($class, $identifier); if (!$id) { return null; } // If the class doesn't exist, look for a table instead if (!class_exists($class ?? '')) { $tableNames = DataObject::getSchema()->getTableNames(); $potential = array_search($class, $tableNames ?? []); if (!$potential) { throw new \LogicException("'$class' is neither a class nor a table name"); } $class = $potential; } return DataObject::get_by_id($class, $id); }
Get an object from the fixture. @template T of DataObject @param class-string<T> $class The data class or table name, as specified in your fixture file. Parent classes won't work @param string $identifier The identifier string, as provided in your fixture file @return T|null
get
php
silverstripe/silverstripe-framework
src/Dev/FixtureFactory.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/FixtureFactory.php
BSD-3-Clause
public function getFixtures() { return $this->fixtures; }
@return array Map of class names, containing a map of in-memory identifiers mapped to database identifiers.
getFixtures
php
silverstripe/silverstripe-framework
src/Dev/FixtureFactory.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/FixtureFactory.php
BSD-3-Clause
protected function parseValue($value) { if (substr($value ?? '', 0, 2) == '=>') { // Parse a dictionary reference - used to set foreign keys if (strpos($value ?? '', '.') !== false) { list($class, $identifier) = explode('.', substr($value ?? '', 2), 2); } else { throw new \LogicException("Bad fixture lookup identifier: " . $value); } if ($this->fixtures && !isset($this->fixtures[$class][$identifier])) { throw new InvalidArgumentException(sprintf( 'No fixture definitions found for "%s"', $value )); } return $this->fixtures[$class][$identifier]; } else { // Regular field value setting return $value; } }
Parse a value from a fixture file. If it starts with => it will get an ID from the fixture dictionary @param string $value @return string Fixture database ID, or the original value
parseValue
php
silverstripe/silverstripe-framework
src/Dev/FixtureFactory.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/FixtureFactory.php
BSD-3-Clause
public function reset() { $this->setEnvironment(TestKernel::DEV); $this->bootPHP(); return $this; }
Reset kernel between tests. Note: this avoids resetting services (See TestState for service specific reset) @return $this
reset
php
silverstripe/silverstripe-framework
src/Dev/TestKernel.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/TestKernel.php
BSD-3-Clause
public function buildDefaults() { Deprecation::withSuppressedNotice(function () { Deprecation::notice( '5.4.0', 'Will be replaced with SilverStripe\Dev\Command\DbDefaults' ); }); $da = DatabaseAdmin::create(); $renderer = null; if (!Director::is_cli()) { $renderer = DebugView::create(); echo $renderer->renderHeader(); echo $renderer->renderInfo("Defaults Builder", Director::absoluteBaseURL()); echo "<div class=\"build\">"; } $da->buildDefaults(); if (!Director::is_cli()) { echo "</div>"; echo $renderer->renderFooter(); } }
Build the default data, calling requireDefaultRecords on all DataObject classes Should match the $url_handlers rule: 'build/defaults' => 'buildDefaults', @deprecated 5.4.0 Will be replaced with SilverStripe\Dev\Commands\DbDefaults
buildDefaults
php
silverstripe/silverstripe-framework
src/Dev/DevelopmentAdmin.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/DevelopmentAdmin.php
BSD-3-Clause
public function generatesecuretoken() { Deprecation::withSuppressedNotice(function () { Deprecation::notice( '5.4.0', 'Will be replaced with SilverStripe\Dev\Command\GenerateSecureToken' ); }); $generator = Injector::inst()->create('SilverStripe\\Security\\RandomGenerator'); $token = $generator->randomToken('sha1'); $body = <<<TXT Generated new token. Please add the following code to your YAML configuration: Security: token: $token TXT; $response = new HTTPResponse($body); return $response->addHeader('Content-Type', 'text/plain'); }
Generate a secure token which can be used as a crypto key. Returns the token and suggests PHP configuration to set it. @deprecated 5.4.0 Will be replaced with SilverStripe\Dev\Commands\GenerateSecureToken
generatesecuretoken
php
silverstripe/silverstripe-framework
src/Dev/DevelopmentAdmin.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/DevelopmentAdmin.php
BSD-3-Clause
public static function supports_colour() { // Special case for buildbot if (isset($_ENV['_']) && strpos($_ENV['_'] ?? '', 'buildbot') !== false) { return false; } if (!defined('STDOUT')) { define('STDOUT', fopen("php://stdout", "w")); } return function_exists('posix_isatty') ? @posix_isatty(STDOUT) : false; }
Returns true if the current STDOUT supports the use of colour control codes.
supports_colour
php
silverstripe/silverstripe-framework
src/Dev/CLI.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/CLI.php
BSD-3-Clause
public static function text($text, $fgColour = null, $bgColour = null, $bold = false) { if (!CLI::supports_colour()) { return $text; } if ($fgColour || $bgColour || $bold) { $prefix = CLI::start_colour($fgColour, $bgColour, $bold); $suffix = CLI::end_colour(); } else { $prefix = $suffix = ""; } return $prefix . $text . $suffix; }
Return text encoded for CLI output, optionally coloured @param string $text @param string $fgColour The foreground colour - black, red, green, yellow, blue, magenta, cyan, white. Null is default. @param string $bgColour The foreground colour - black, red, green, yellow, blue, magenta, cyan, white. Null is default. @param bool $bold A boolean variable - bold or not. @return string
text
php
silverstripe/silverstripe-framework
src/Dev/CLI.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/CLI.php
BSD-3-Clause
public static function start_colour($fgColour = null, $bgColour = null, $bold = false) { if (!CLI::supports_colour()) { return ""; } $colours = [ 'black' => 0, 'red' => 1, 'green' => 2, 'yellow' => 3, 'blue' => 4, 'magenta' => 5, 'cyan' => 6, 'white' => 7, ]; $prefix = ""; if ($fgColour || $bold) { if (!$fgColour) { $fgColour = "white"; } $prefix .= "\033[" . ($bold ? "1;" :"") . "3" . $colours[$fgColour] . "m"; }
Send control codes for changing text to the given colour @param string $fgColour The foreground colour - black, red, green, yellow, blue, magenta, cyan, white. Null is default. @param string $bgColour The foreground colour - black, red, green, yellow, blue, magenta, cyan, white. Null is default. @param bool $bold A boolean variable - bold or not. @return string
start_colour
php
silverstripe/silverstripe-framework
src/Dev/CLI.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/CLI.php
BSD-3-Clause
public static function end_colour() { return CLI::supports_colour() ? "\033[0m" : ""; }
Send control codes for returning to normal colour
end_colour
php
silverstripe/silverstripe-framework
src/Dev/CLI.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/CLI.php
BSD-3-Clause
public function renderHeader($httpRequest = null) { return null; }
Render HTML header for development views @param HTTPRequest $httpRequest @return string
renderHeader
php
silverstripe/silverstripe-framework
src/Dev/CliDebugView.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/CliDebugView.php
BSD-3-Clause
public function renderFooter() { }
Render HTML footer for development views
renderFooter
php
silverstripe/silverstripe-framework
src/Dev/CliDebugView.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/CliDebugView.php
BSD-3-Clause
public function renderError($httpRequest, $errno, $errstr, $errfile, $errline) { if (!isset(CliDebugView::$error_types[$errno])) { $errorTypeTitle = "UNKNOWN TYPE, ERRNO $errno"; } else { $errorTypeTitle = CliDebugView::$error_types[$errno]['title']; } $output = CLI::text("ERROR [" . $errorTypeTitle . "]: $errstr\nIN $httpRequest\n", "red", null, true); $output .= CLI::text("Line $errline in $errfile\n\n", "red"); return $output; }
Write information about the error to the screen @param string $httpRequest @param int $errno @param string $errstr @param string $errfile @param int $errline @return string
renderError
php
silverstripe/silverstripe-framework
src/Dev/CliDebugView.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/CliDebugView.php
BSD-3-Clause
public function renderInfo($title, $subtitle, $description = null) { $output = wordwrap(strtoupper($title ?? ''), static::config()->columns ?? 0) . "\n"; $output .= wordwrap($subtitle ?? '', static::config()->columns ?? 0) . "\n"; $output .= str_repeat('-', min(static::config()->columns, max(strlen($title ?? ''), strlen($subtitle ?? ''))) ?? 0) . "\n"; $output .= wordwrap($description ?? '', static::config()->columns ?? 0) . "\n\n"; return $output; }
Render the information header for the view @param string $title @param string $subtitle @param string $description @return string
renderInfo
php
silverstripe/silverstripe-framework
src/Dev/CliDebugView.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/CliDebugView.php
BSD-3-Clause
public function debugVariable($val, $caller, $showHeader = true) { $text = $this->debugVariableText($val); if ($showHeader) { $callerFormatted = $this->formatCaller($caller); return "Debug ($callerFormatted)\n{$text}\n\n"; } else { return $text; } }
Similar to renderVariable() but respects debug() method on object if available @param mixed $val @param array $caller @param bool $showHeader @return string
debugVariable
php
silverstripe/silverstripe-framework
src/Dev/CliDebugView.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/CliDebugView.php
BSD-3-Clause
public static function show($val, $showHeader = true, HTTPRequest $request = null) { // Don't show on live if (Director::isLive()) { return; } echo static::create_debug_view($request) ->debugVariable($val, static::caller(), $showHeader); }
Show the contents of val in a debug-friendly way. Debug::show() is intended to be equivalent to dprintr() Does not work on live mode. @param mixed $val @param bool $showHeader @param HTTPRequest|null $request
show
php
silverstripe/silverstripe-framework
src/Dev/Debug.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/Debug.php
BSD-3-Clause
public static function caller() { $bt = debug_backtrace(); $caller = isset($bt[2]) ? $bt[2] : []; $caller['line'] = $bt[1]['line']; $caller['file'] = $bt[1]['file']; if (!isset($caller['class'])) { $caller['class'] = ''; } if (!isset($caller['type'])) { $caller['type'] = ''; } if (!isset($caller['function'])) { $caller['function'] = ''; } return $caller; }
Returns the caller for a specific method @return array
caller
php
silverstripe/silverstripe-framework
src/Dev/Debug.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/Debug.php
BSD-3-Clause
public static function endshow($val, $showHeader = true, HTTPRequest $request = null) { // Don't show on live if (Director::isLive()) { return; } echo static::create_debug_view($request) ->debugVariable($val, static::caller(), $showHeader); die(); }
Close out the show dumper. Does not work on live mode @param mixed $val @param bool $showHeader @param HTTPRequest $request
endshow
php
silverstripe/silverstripe-framework
src/Dev/Debug.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/Debug.php
BSD-3-Clause
public static function dump($val, HTTPRequest $request = null) { echo Debug::create_debug_view($request) ->renderVariable($val, Debug::caller()); }
Quick dump of a variable. Note: This method will output in live! @param mixed $val @param HTTPRequest $request Current request to influence output format
dump
php
silverstripe/silverstripe-framework
src/Dev/Debug.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/Debug.php
BSD-3-Clause
public static function text($val, HTTPRequest $request = null) { return static::create_debug_view($request) ->debugVariableText($val); }
Get debug text for this object @param mixed $val @param HTTPRequest $request @return string
text
php
silverstripe/silverstripe-framework
src/Dev/Debug.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/Debug.php
BSD-3-Clause
public static function message($message, $showHeader = true, HTTPRequest $request = null) { // Don't show on live if (Director::isLive()) { return; } echo static::create_debug_view($request) ->renderMessage($message, static::caller(), $showHeader); }
Show a debugging message. Does not work on live mode @param string $message @param bool $showHeader @param HTTPRequest|null $request
message
php
silverstripe/silverstripe-framework
src/Dev/Debug.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/Debug.php
BSD-3-Clause
public static function create_debug_view(HTTPRequest $request = null) { $service = static::supportsHTML($request) ? DebugView::class : CliDebugView::class; return Injector::inst()->get($service); }
Create an instance of an appropriate DebugView object. @param HTTPRequest $request Optional request to target this view for @return DebugView
create_debug_view
php
silverstripe/silverstripe-framework
src/Dev/Debug.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/Debug.php
BSD-3-Clause
public static function require_developer_login() { Deprecation::noticeWithNoReplacment('5.4.0'); // Don't require login for dev mode if (Director::isDev()) { return; } if (isset($_SESSION['loggedInAs'])) { // We have to do some raw SQL here, because this method is called in Object::defineMethods(). // This means we have to be careful about what objects we create, as we don't want Object::defineMethods() // being called again. // This basically calls Permission::checkMember($_SESSION['loggedInAs'], 'ADMIN'); $memberID = $_SESSION['loggedInAs']; $permission = DB::prepared_query( ' SELECT "ID" FROM "Permission" INNER JOIN "Group_Members" ON "Permission"."GroupID" = "Group_Members"."GroupID" WHERE "Permission"."Code" = ? AND "Permission"."Type" = ? AND "Group_Members"."MemberID" = ?', [ 'ADMIN', // Code Permission::GRANT_PERMISSION, // Type $memberID // MemberID ] )->value(); if ($permission) { return; } } // This basically does the same as // Security::permissionFailure(null, "You need to login with developer access to make use of debugging tools.") // We have to do this because of how early this method is called in execution. $_SESSION['SilverStripe\\Security\\Security']['Message']['message'] = "You need to login with developer access to make use of debugging tools."; $_SESSION['SilverStripe\\Security\\Security']['Message']['type'] = 'warning'; $_SESSION['BackURL'] = $_SERVER['REQUEST_URI']; header($_SERVER['SERVER_PROTOCOL'] . " 302 Found"); header("Location: " . Director::baseURL() . Security::login_url()); die(); }
Check if the user has permissions to run URL debug tools, else redirect them to log in. @deprecated 5.4.0 Will be removed without equivalent functionality.
require_developer_login
php
silverstripe/silverstripe-framework
src/Dev/Debug.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/Debug.php
BSD-3-Clause
public function Breadcrumbs() { $basePath = str_replace(Director::protocolAndHost() ?? '', '', Director::absoluteBaseURL() ?? ''); $relPath = parse_url( substr($_SERVER['REQUEST_URI'] ?? '', strlen($basePath ?? ''), strlen($_SERVER['REQUEST_URI'] ?? '')), PHP_URL_PATH ); $parts = explode('/', $relPath ?? ''); $base = Director::absoluteBaseURL(); $pathPart = ""; $pathLinks = []; foreach ($parts as $part) { if ($part != '') { $pathPart = Controller::join_links($pathPart, $part); $href = Controller::join_links($base, $pathPart); $pathLinks[] = "<a href=\"$href\">$part</a>"; } } return implode('&nbsp;&rarr;&nbsp;', $pathLinks); }
Generate breadcrumb links to the URL path being displayed @return string
Breadcrumbs
php
silverstripe/silverstripe-framework
src/Dev/DebugView.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/DebugView.php
BSD-3-Clause
public function renderInfo($title, $subtitle, $description = false) { $output = '<div class="info header">'; $output .= "<h1>" . Convert::raw2xml($title) . "</h1>"; if ($subtitle) { $output .= "<h3>" . Convert::raw2xml($subtitle) . "</h3>"; } if ($description) { $output .= "<p>$description</p>"; } else { $output .= $this->Breadcrumbs(); } $output .= '</div>'; return $output; }
Render the information header for the view @param string $title The main title @param string $subtitle The subtitle @param string|bool $description The description to show @return string
renderInfo
php
silverstripe/silverstripe-framework
src/Dev/DebugView.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/DebugView.php
BSD-3-Clause
public function renderFooter() { return "</body></html>"; }
Render HTML footer for development views @return string
renderFooter
php
silverstripe/silverstripe-framework
src/Dev/DebugView.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/DebugView.php
BSD-3-Clause
public function renderParagraph($text) { return '<div class="info"><p>' . $text . '</p></div>'; }
Render an arbitrary paragraph. @param string $text The HTML-escaped text to render @return string
renderParagraph
php
silverstripe/silverstripe-framework
src/Dev/DebugView.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/DebugView.php
BSD-3-Clause
protected function formatCaller($caller) { $return = basename($caller['file'] ?? '') . ":" . $caller['line']; if (!empty($caller['class']) && !empty($caller['function'])) { $return .= " - {$caller['class']}::{$caller['function']}()"; } return $return; }
Formats the caller of a method @param array $caller @return string
formatCaller
php
silverstripe/silverstripe-framework
src/Dev/DebugView.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/DebugView.php
BSD-3-Clause
public function renderVariable($val, $caller) { $output = '<pre style="background-color:#ccc;padding:5px;font-size:14px;line-height:18px;">'; $output .= "<span style=\"font-size: 12px;color:#666;\">" . $this->formatCaller($caller) . " - </span>\n"; if (is_string($val)) { $output .= wordwrap($val ?? '', static::config()->columns ?? 0); } else { $output .= var_export($val, true); } $output .= '</pre>'; return $output; }
Outputs a variable in a user presentable way @param object $val @param array $caller Caller information @return string
renderVariable
php
silverstripe/silverstripe-framework
src/Dev/DebugView.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/DebugView.php
BSD-3-Clause
public function writeInto(FixtureFactory $factory) { $parser = new Parser(); if (isset($this->fixtureString)) { $fixtureContent = $parser->parse($this->fixtureString); } else { if (!file_exists($this->fixtureFile ?? '') || is_dir($this->fixtureFile ?? '')) { return; } $contents = file_get_contents($this->fixtureFile ?? ''); $fixtureContent = $parser->parse($contents); if (!$fixtureContent) { return; } } foreach ($fixtureContent as $class => $items) { foreach ($items as $identifier => $data) { if (ClassInfo::exists($class)) { $factory->createObject($class, $identifier, $data); } else { $factory->createRaw($class, $identifier, $data); } } } }
Persists the YAML data in a FixtureFactory, which in turn saves them into the database. Please use the passed in factory to access the fixtures afterwards. @param FixtureFactory $factory
writeInto
php
silverstripe/silverstripe-framework
src/Dev/YamlFixture.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/YamlFixture.php
BSD-3-Clause
public function followRedirection() { if ($this->lastResponse->getHeader('Location')) { $url = Director::makeRelative($this->lastResponse->getHeader('Location')); $url = strtok($url ?? '', '#'); return $this->get($url); } }
If the last request was a 3xx response, then follow the redirection @return HTTPResponse The response given, or null if no redirect occurred
followRedirection
php
silverstripe/silverstripe-framework
src/Dev/TestSession.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/TestSession.php
BSD-3-Clause
public function wasRedirected() { $code = $this->lastResponse->getStatusCode(); return $code >= 300 && $code < 400; }
Returns true if the last response was a 3xx redirection @return bool
wasRedirected
php
silverstripe/silverstripe-framework
src/Dev/TestSession.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/TestSession.php
BSD-3-Clause
public function lastUrl() { return $this->lastUrl; }
Return the fake HTTP_REFERER; set each time get() or post() is called. @return string
lastUrl
php
silverstripe/silverstripe-framework
src/Dev/TestSession.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/TestSession.php
BSD-3-Clause
public function lastContent() { if (is_string($this->lastResponse)) { return $this->lastResponse; } else { return $this->lastResponse->getBody(); } }
Get the most recent response's content @return string
lastContent
php
silverstripe/silverstripe-framework
src/Dev/TestSession.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/TestSession.php
BSD-3-Clause
public function cssParser() { return new CSSContentParser($this->lastContent()); }
Return a CSSContentParser containing the most recent response @return CSSContentParser
cssParser
php
silverstripe/silverstripe-framework
src/Dev/TestSession.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/TestSession.php
BSD-3-Clause
public function session() { return $this->session; }
Get the current session, as a Session object @return Session
session
php
silverstripe/silverstripe-framework
src/Dev/TestSession.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/TestSession.php
BSD-3-Clause
public function Created() { return $this->mapToArrayList($this->created); }
Returns all created objects. Each object might contain specific importer feedback in the "_BulkLoaderMessage" property. @return ArrayList
Created
php
silverstripe/silverstripe-framework
src/Dev/BulkLoader_Result.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/BulkLoader_Result.php
BSD-3-Clause
public function LastChange() { return $this->lastChange; }
Returns the last change. It is in the same format as {@link $created} but with an additional key, "ChangeType", which will be set to one of 3 strings: "created", "updated", or "deleted"
LastChange
php
silverstripe/silverstripe-framework
src/Dev/BulkLoader_Result.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/BulkLoader_Result.php
BSD-3-Clause
public function merge(BulkLoader_Result $other) { $this->created = array_merge($this->created, $other->created); $this->updated = array_merge($this->updated, $other->updated); $this->deleted = array_merge($this->deleted, $other->deleted); }
Merges another BulkLoader_Result into this one. @param BulkLoader_Result $other
merge
php
silverstripe/silverstripe-framework
src/Dev/BulkLoader_Result.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/BulkLoader_Result.php
BSD-3-Clause
public static function withNoReplacement(callable $func) { Deprecation::notice('5.4.0', 'Use withSuppressedNotice() instead'); return Deprecation::withSuppressedNotice($func); }
Used to wrap deprecated methods and deprecated config get()/set() called from the vendor dir that projects have no ability to change. @return mixed @deprecated 5.4.0 Use withSuppressedNotice() instead
withNoReplacement
php
silverstripe/silverstripe-framework
src/Dev/Deprecation.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/Deprecation.php
BSD-3-Clause
protected function withBaseURL($url, $callback) { $oldBase = Config::inst()->get(Director::class, 'alternate_base_url'); Config::modify()->set(Director::class, 'alternate_base_url', $url); $callback($this); Config::modify()->set(Director::class, 'alternate_base_url', $oldBase); }
Run a test while mocking the base url with the provided value @param string $url The base URL to use for this test @param callable $callback The test to run
withBaseURL
php
silverstripe/silverstripe-framework
src/Dev/FunctionalTest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/FunctionalTest.php
BSD-3-Clause
protected function withBaseFolder($folder, $callback) { $oldFolder = Config::inst()->get(Director::class, 'alternate_base_folder'); Config::modify()->set(Director::class, 'alternate_base_folder', $folder); $callback($this); Config::modify()->set(Director::class, 'alternate_base_folder', $oldFolder); }
Run a test while mocking the base folder with the provided value @param string $folder The base folder to use for this test @param callable $callback The test to run
withBaseFolder
php
silverstripe/silverstripe-framework
src/Dev/FunctionalTest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/FunctionalTest.php
BSD-3-Clause
public function content() { return $this->mainSession->lastContent(); }
Return the most recent content @return string
content
php
silverstripe/silverstripe-framework
src/Dev/FunctionalTest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/FunctionalTest.php
BSD-3-Clause
public function findAttribute($object, $attribute) { $found = false; foreach ($object->attributes() as $a => $b) { if ($a == $attribute) { $found = $b; } } return $found; }
Find an attribute in a SimpleXMLElement object by name. @param SimpleXMLElement $object @param string $attribute Name of attribute to find @return SimpleXMLElement object of the attribute
findAttribute
php
silverstripe/silverstripe-framework
src/Dev/FunctionalTest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/FunctionalTest.php
BSD-3-Clause
public function cssParser() { if (!$this->cssParser) { $this->cssParser = new CSSContentParser($this->mainSession->lastContent()); } return $this->cssParser; }
Return a CSSContentParser for the most recent content. @return CSSContentParser
cssParser
php
silverstripe/silverstripe-framework
src/Dev/FunctionalTest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/FunctionalTest.php
BSD-3-Clause
public function hasHeaderRow() { return ($this->hasHeaderRow || isset($this->columnMap)); }
Determine whether any loaded files should be parsed with a header-row (otherwise we rely on {@link CsvBulkLoader::$columnMap}. @return boolean
hasHeaderRow
php
silverstripe/silverstripe-framework
src/Dev/CsvBulkLoader.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/CsvBulkLoader.php
BSD-3-Clause
public static function getIllegalExtensions() { return static::$illegal_extensions; }
Gets illegal extensions for this class @return array
getIllegalExtensions
php
silverstripe/silverstripe-framework
src/Dev/SapphireTest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/SapphireTest.php
BSD-3-Clause
public static function getRequiredExtensions() { return static::$required_extensions; }
Gets required extensions for this class @return array
getRequiredExtensions
php
silverstripe/silverstripe-framework
src/Dev/SapphireTest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/SapphireTest.php
BSD-3-Clause
protected static function is_running_test() { return SapphireTest::$is_running_test; }
Check if test bootstrapping has been performed. Must not be relied on outside of unit tests. @return bool
is_running_test
php
silverstripe/silverstripe-framework
src/Dev/SapphireTest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/SapphireTest.php
BSD-3-Clause
protected function shouldSetupDatabaseForCurrentTest($fixtureFiles) { $databaseEnabledByDefault = $fixtureFiles || $this->usesDatabase; return ($databaseEnabledByDefault && !$this->currentTestDisablesDatabase()) || $this->currentTestEnablesDatabase(); }
Helper method to determine if the current test should enable a test database @param $fixtureFiles @return bool
shouldSetupDatabaseForCurrentTest
php
silverstripe/silverstripe-framework
src/Dev/SapphireTest.php
https://github.com/silverstripe/silverstripe-framework/blob/master/src/Dev/SapphireTest.php
BSD-3-Clause