code
stringlengths 17
296k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function getEnum()
{
$classNames = ClassInfo::subclassesFor($this->getBaseClass());
$dataobject = strtolower(DataObject::class);
unset($classNames[$dataobject]);
return array_values($classNames ?? []);
} | Get list of classnames that should be selectable
@return array | getEnum | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBClassNameTrait.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBClassNameTrait.php | BSD-3-Clause |
protected function parseTime($value)
{
// Skip empty values
if (empty($value) && !is_numeric($value)) {
return null;
}
// Determine value to parse
if (is_array($value)) {
$source = $value; // parse array
} elseif (is_numeric($value)) {
$source = $value; // parse timestamp
} else {
// Convert using strtotime
$source = strtotime($value ?? '');
}
if ($value === false) {
return false;
}
// Format as iso8601
$formatter = $this->getFormatter();
$formatter->setPattern($this->getISOFormat());
return $formatter->format($source);
} | Parse timestamp or iso8601-ish date into standard iso8601 format
@param mixed $value
@return string|null|false Formatted time, null if empty but valid, or false if invalid | parseTime | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBTime.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php | BSD-3-Clause |
public function getFormatter($timeLength = IntlDateFormatter::MEDIUM)
{
return IntlDateFormatter::create(i18n::get_locale(), IntlDateFormatter::NONE, $timeLength);
} | Get date / time formatter for the current locale
@param int $timeLength
@return IntlDateFormatter | getFormatter | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBTime.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php | BSD-3-Clause |
public function Short()
{
if (!$this->value) {
return null;
}
$formatter = $this->getFormatter(IntlDateFormatter::SHORT);
return $formatter->format($this->getTimestamp());
} | Returns the date in the localised short format
@return string | Short | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBTime.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php | BSD-3-Clause |
public function Nice()
{
if (!$this->value) {
return null;
}
$formatter = $this->getFormatter();
return $formatter->format($this->getTimestamp());
} | Returns the standard localised medium time
e.g. "3:15pm"
@return string | Nice | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBTime.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php | BSD-3-Clause |
public function Format($format)
{
if (!$this->value) {
return null;
}
$formatter = $this->getFormatter();
$formatter->setPattern($format);
return $formatter->format($this->getTimestamp());
} | Return the time using a particular formatting string.
@param string $format Format code string. See https://unicode-org.github.io/icu/userguide/format_parse/datetime
@return string The time in the requested format | Format | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBTime.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php | BSD-3-Clause |
public function FormatFromSettings($member = null)
{
if (!$member) {
$member = Security::getCurrentUser();
}
// Fall back to nice
if (!$member) {
return $this->Nice();
}
// Get user format
$format = $member->getTimeFormat();
return $this->Format($format);
} | Return a time formatted as per a CMS user's settings.
@param Member $member
@return string A time formatted as per user-defined settings. | FormatFromSettings | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBTime.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php | BSD-3-Clause |
public function getISOFormat()
{
return DBTime::ISO_TIME;
} | Get standard ISO time format string
@return string | getISOFormat | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBTime.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php | BSD-3-Clause |
public function getTimestamp()
{
if ($this->value) {
return strtotime($this->value ?? '');
}
return 0;
} | Get unix timestamp for this time
@return int | getTimestamp | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBTime.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBTime.php | BSD-3-Clause |
public function getClassValue()
{
return $this->getField('Class');
} | Get the value of the "Class" this key points to
@return string Name of a subclass of DataObject | getClassValue | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBPolymorphicForeignKey.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBPolymorphicForeignKey.php | BSD-3-Clause |
public function setClassValue($value, $markChanged = true)
{
$this->setField('Class', $value, $markChanged);
} | Set the value of the "Class" this key points to
@param string $value Name of a subclass of DataObject
@param boolean $markChanged Mark this field as changed? | setClassValue | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBPolymorphicForeignKey.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBPolymorphicForeignKey.php | BSD-3-Clause |
public function getIDValue()
{
return $this->getField('ID');
} | Gets the value of the "ID" this key points to
@return integer | getIDValue | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBPolymorphicForeignKey.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBPolymorphicForeignKey.php | BSD-3-Clause |
public function setIDValue($value, $markChanged = true)
{
$this->setField('ID', $value, $markChanged);
} | Sets the value of the "ID" this key points to
@param integer $value
@param boolean $markChanged Mark this field as changed? | setIDValue | php | silverstripe/silverstripe-framework | src/ORM/FieldType/DBPolymorphicForeignKey.php | https://github.com/silverstripe/silverstripe-framework/blob/master/src/ORM/FieldType/DBPolymorphicForeignKey.php | BSD-3-Clause |
public function __construct($name = null, $options = [])
{
$this->name = $name;
if ($options) {
if (!is_array($options)) {
throw new InvalidArgumentException("Invalid options $options");
}
$this->setOptions($options);
}
parent::__construct();
} | Provide the DBField name and an array of options, e.g. ['index' => true], or ['nullifyEmpty' => false]
@param string $name
@param array $options
@throws InvalidArgumentException If $options was passed by not an array | __construct | 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 static function create_field($spec, $value, $name = null, ...$args)
{
// Raise warning if inconsistent with DataObject::dbObject() behaviour
// This will cause spec args to be shifted down by the number of provided $args
if ($args && strpos($spec ?? '', '(') !== false) {
trigger_error('Additional args provided in both $spec and $args', E_USER_WARNING);
}
// Ensure name is always first argument
array_unshift($args, $name);
/** @var DBField $dbField */
$dbField = Injector::inst()->createWithArgs($spec, $args);
$dbField->setValue($value, null, false);
return $dbField;
} | Create a DBField object that's not bound to any particular field.
Useful for accessing the classes behaviour for other parts of your code.
@param string $spec Class specification to construct. May include both service name and additional
constructor arguments in the same format as DataObject.db config.
@param mixed $value value of field
@param string $name Name of field
@param mixed $args Additional arguments to pass to constructor if not using args in service $spec
Note: Will raise a warning if using both
@return static | create_field | 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 setName($name)
{
if ($this->name && $this->name !== $name) {
user_error("DBField::setName() shouldn't be called once a DBField already has a name."
. "It's partially immutable - it shouldn't be altered after it's given a value.", E_USER_WARNING);
}
$this->name = $name;
return $this;
} | Set the name of this field.
The name should never be altered, but it if was never given a name in
the first place you can set a name.
If you try an alter the name a warning will be thrown.
@param string $name
@return $this | setName | 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 getName()
{
return $this->name;
} | Returns the name of this field.
@return string | getName | 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 getValue()
{
return $this->value;
} | Returns the value of this field.
@return mixed | getValue | 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 getDefaultValue()
{
return $this->defaultVal;
} | Get default value assigned at the DB level
@return mixed | getDefaultValue | 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 setDefaultValue($defaultValue)
{
$this->defaultVal = $defaultValue;
return $this;
} | Set default value to use at the DB level
@param mixed $defaultValue
@return $this | setDefaultValue | 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 setOptions(array $options = [])
{
$this->options = $options;
return $this;
} | Update the optional parameters for this field
@param array $options Array of options
@return $this | setOptions | 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 getOptions()
{
return $this->options;
} | Get optional parameters for this field
@return array | getOptions | 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 exists()
{
return (bool)$this->value;
} | Determines if the field has a value which is not considered to be 'null'
in a database context.
@return boolean | exists | 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 prepValueForDB($value)
{
if ($value === null ||
$value === "" ||
$value === false ||
($this->scalarValueOnly() && !is_scalar($value))
) {
return null;
} else {
return $value;
}
} | Return the transformed value ready to be sent to the database. This value
will be escaped automatically by the prepared query processor, so it
should not be escaped or quoted at all.
@param mixed $value The value to check
@return mixed The raw value, or escaped parameterised details | prepValueForDB | 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 addToQuery(&$query)
{
} | Add custom query parameters for this field,
mostly SELECT statements for multi-value fields.
By default, the ORM layer does a
SELECT <tablename>.* which
gets you the default representations
of all columns.
@param SQLSelect $query | addToQuery | 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 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 ATT()
{
return Convert::raw2att($this->RAW());
} | Gets the value appropriate for a HTML attribute string
@return string | ATT | 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 getFilters()
{
return $this->filters;
} | Get the map of filters in the current search context.
@return SearchFilter[] | getFilters | 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 setFilters($filters)
{
$this->filters = $filters;
} | Overwrite the current search context filter map.
@param SearchFilter[] $filters | setFilters | 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 getFields()
{
return $this->fields;
} | Get the list of searchable fields in the current search context.
@return FieldList | getFields | 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 setFields($fields)
{
$this->fields = $fields;
} | Apply a list of searchable fields to the current search context.
@param FieldList $fields | setFields | 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 |
public function getWriter()
{
return $this->writer;
} | Gets the currently assigned writer, or the default if none is specified.
@return Writer | getWriter | 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 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.