mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Compare commits
5 Commits
41cbfe4e49
...
e0b2f721ea
Author | SHA1 | Date | |
---|---|---|---|
|
e0b2f721ea | ||
|
662ac9d1f9 | ||
|
983e90b25e | ||
|
8e08b1cf79 | ||
|
165f72fd22 |
@ -511,7 +511,7 @@ trait Extensible
|
||||
// Setup all extension instances for this instance
|
||||
$this->extension_instances = [];
|
||||
foreach (ClassInfo::ancestry(static::class) as $class) {
|
||||
if (in_array($class, self::$unextendable_classes)) {
|
||||
if (in_array($class, self::class::$unextendable_classes)) {
|
||||
continue;
|
||||
}
|
||||
$extensions = Config::inst()->get($class, 'extensions', Config::UNINHERITED | Config::EXCLUDE_EXTRA_SOURCES);
|
||||
|
@ -391,7 +391,7 @@ class Deprecation
|
||||
}
|
||||
|
||||
// Getting a backtrace is slow, so we only do it if we need it
|
||||
$backtrace = null;
|
||||
$backtrace = [];
|
||||
|
||||
// Get the calling scope
|
||||
if ($scope == Deprecation::SCOPE_METHOD) {
|
||||
|
@ -22,9 +22,6 @@ use SilverStripe\Model\List\ArrayList;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\ORM\DataObjectInterface;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\Model\List\Filterable;
|
||||
use SilverStripe\Model\List\Limitable;
|
||||
use SilverStripe\Model\List\Sortable;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
use SilverStripe\View\HTML;
|
||||
use SilverStripe\Model\ModelData;
|
||||
@ -86,7 +83,7 @@ class GridField extends FormField
|
||||
/**
|
||||
* Data source.
|
||||
*
|
||||
* @var SS_List&Filterable&Sortable&Limitable
|
||||
* @var SS_List
|
||||
*/
|
||||
protected $list = null;
|
||||
|
||||
@ -397,7 +394,7 @@ class GridField extends FormField
|
||||
/**
|
||||
* Set the data source.
|
||||
*
|
||||
* @param SS_List&Filterable&Sortable&Limitable $list
|
||||
* @param SS_List $list
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
@ -411,7 +408,7 @@ class GridField extends FormField
|
||||
/**
|
||||
* Get the data source.
|
||||
*
|
||||
* @return SS_List&Filterable&Sortable&Limitable
|
||||
* @return SS_List
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
@ -421,7 +418,7 @@ class GridField extends FormField
|
||||
/**
|
||||
* Get the data source after applying every {@link GridField_DataManipulator} to it.
|
||||
*
|
||||
* @return SS_List&Filterable&Sortable&Limitable
|
||||
* @return SS_List
|
||||
*/
|
||||
public function getManipulatedList()
|
||||
{
|
||||
|
@ -6,6 +6,7 @@ use SilverStripe\Core\Convert;
|
||||
use InvalidArgumentException;
|
||||
use LogicException;
|
||||
use SilverStripe\Model\ModelData;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
|
||||
/**
|
||||
* @see GridField
|
||||
@ -228,9 +229,11 @@ class GridFieldDataColumns extends AbstractGridFieldComponent implements GridFie
|
||||
* @param ModelData $record
|
||||
* @param string $columnName
|
||||
* @return string|null - returns null if it could not found a value
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
|
||||
*/
|
||||
protected function getValueFromRelation($record, $columnName)
|
||||
{
|
||||
Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it.');
|
||||
$fieldNameParts = explode('.', $columnName ?? '');
|
||||
$tmpItem = clone($record);
|
||||
for ($idx = 0; $idx < sizeof($fieldNameParts ?? []); $idx++) {
|
||||
|
@ -11,7 +11,6 @@ use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\Schema\FormSchema;
|
||||
use SilverStripe\Model\List\Filterable;
|
||||
use SilverStripe\ORM\Search\SearchContext;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
use SilverStripe\Model\ArrayData;
|
||||
@ -109,13 +108,13 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi
|
||||
*/
|
||||
protected function checkDataType($dataList)
|
||||
{
|
||||
if ($dataList instanceof Filterable) {
|
||||
if ($dataList instanceof SS_List) {
|
||||
return true;
|
||||
} else {
|
||||
// This will be changed to always throw an exception in a future major release.
|
||||
if ($this->throwExceptionOnBadDataType) {
|
||||
throw new LogicException(
|
||||
static::class . " expects an SS_Filterable list to be passed to the GridField."
|
||||
static::class . " expects an SS_List list to be passed to the GridField."
|
||||
);
|
||||
}
|
||||
return false;
|
||||
@ -209,7 +208,7 @@ class GridFieldFilterHeader extends AbstractGridFieldComponent implements GridFi
|
||||
public function canFilterAnyColumns($gridField)
|
||||
{
|
||||
$list = $gridField->getList();
|
||||
if (!($list instanceof Filterable) || !$this->checkDataType($list)) {
|
||||
if (!($list instanceof SS_List) || !$this->checkDataType($list)) {
|
||||
return false;
|
||||
}
|
||||
$modelClass = $gridField->getModelClass();
|
||||
|
@ -5,7 +5,6 @@ namespace SilverStripe\Forms\GridField;
|
||||
use SilverStripe\Forms\FormField;
|
||||
use SilverStripe\Forms\TabSet;
|
||||
use SilverStripe\Model\List\ArrayList;
|
||||
use SilverStripe\Model\List\Filterable;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
|
||||
/**
|
||||
@ -28,7 +27,7 @@ class GridFieldLazyLoader extends AbstractGridFieldComponent implements GridFiel
|
||||
{
|
||||
// If we are lazy loading an empty the list
|
||||
if ($this->isLazy($gridField)) {
|
||||
if ($dataList instanceof Filterable) {
|
||||
if ($dataList instanceof SS_List) {
|
||||
// If our original list can be filtered, filter out all results.
|
||||
$dataList = $dataList->byIDs([-1]);
|
||||
} else {
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace SilverStripe\Forms\GridField;
|
||||
|
||||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\Model\List\Limitable;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
use SilverStripe\ORM\UnsavedRelationList;
|
||||
use SilverStripe\Model\ArrayData;
|
||||
@ -89,13 +88,13 @@ class GridFieldPaginator extends AbstractGridFieldComponent implements GridField
|
||||
*/
|
||||
protected function checkDataType($dataList)
|
||||
{
|
||||
if ($dataList instanceof Limitable) {
|
||||
if ($dataList instanceof SS_List) {
|
||||
return true;
|
||||
} else {
|
||||
// This will be changed to always throw an exception in a future major release.
|
||||
if ($this->throwExceptionOnBadDataType) {
|
||||
throw new LogicException(
|
||||
static::class . " expects an SS_Limitable list to be passed to the GridField."
|
||||
static::class . " expects an SS_List list to be passed to the GridField."
|
||||
);
|
||||
}
|
||||
return false;
|
||||
@ -183,7 +182,7 @@ class GridFieldPaginator extends AbstractGridFieldComponent implements GridField
|
||||
$startRow = 0;
|
||||
}
|
||||
|
||||
if (!($dataList instanceof Limitable) || ($dataList instanceof UnsavedRelationList)) {
|
||||
if (!($dataList instanceof SS_List) || ($dataList instanceof UnsavedRelationList)) {
|
||||
return $dataList;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ namespace SilverStripe\Forms\GridField;
|
||||
|
||||
use SilverStripe\Forms\LiteralField;
|
||||
use SilverStripe\ORM\DataObjectSchema;
|
||||
use SilverStripe\Model\List\Sortable;
|
||||
use SilverStripe\Model\List\ArrayList;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
@ -78,13 +77,13 @@ class GridFieldSortableHeader extends AbstractGridFieldComponent implements Grid
|
||||
*/
|
||||
protected function checkDataType($dataList)
|
||||
{
|
||||
if ($dataList instanceof Sortable) {
|
||||
if ($dataList instanceof SS_List) {
|
||||
return true;
|
||||
} else {
|
||||
// This will be changed to always throw an exception in a future major release.
|
||||
if ($this->throwExceptionOnBadDataType) {
|
||||
throw new LogicException(
|
||||
static::class . " expects an SS_Sortable list to be passed to the GridField."
|
||||
static::class . " expects an SS_List list to be passed to the GridField."
|
||||
);
|
||||
}
|
||||
return false;
|
||||
@ -246,7 +245,7 @@ class GridFieldSortableHeader extends AbstractGridFieldComponent implements Grid
|
||||
* {@link DataQuery} first.
|
||||
*
|
||||
* @param GridField $gridField
|
||||
* @param SS_List&Sortable $dataList
|
||||
* @param SS_List $dataList
|
||||
* @return SS_List
|
||||
*/
|
||||
public function getManipulatedData(GridField $gridField, SS_List $dataList)
|
||||
|
@ -15,8 +15,8 @@ use Traversable;
|
||||
/**
|
||||
* A list object that wraps around an array of objects or arrays.
|
||||
*
|
||||
* Note that (like DataLists), the implementations of the methods from SS_Filterable, SS_Sortable and
|
||||
* SS_Limitable return a new instance of ArrayList, rather than modifying the existing instance.
|
||||
* Note that (like DataLists), the implementations of the methods from SS_List return a new instance of ArrayList,
|
||||
* rather than modifying the existing instance.
|
||||
*
|
||||
* For easy reference, methods that operate in this way are:
|
||||
*
|
||||
@ -28,11 +28,8 @@ use Traversable;
|
||||
*
|
||||
* @template T
|
||||
* @implements SS_List<T>
|
||||
* @implements Filterable<T>
|
||||
* @implements Sortable<T>
|
||||
* @implements Limitable<T>
|
||||
*/
|
||||
class ArrayList extends ModelData implements SS_List, Filterable, Sortable, Limitable
|
||||
class ArrayList extends ModelData implements SS_List
|
||||
{
|
||||
use SearchFilterable;
|
||||
|
||||
@ -597,7 +594,7 @@ class ArrayList extends ModelData implements SS_List, Filterable, Sortable, Limi
|
||||
/**
|
||||
* Filter the list to include items with these characteristics
|
||||
*
|
||||
* @see Filterable::filter()
|
||||
* @see SS_List::filter()
|
||||
* @example $list->filter('Name', 'bob'); // only bob in the list
|
||||
* @example $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
|
||||
* @example $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob with the Age 21 in list
|
||||
@ -854,7 +851,7 @@ class ArrayList extends ModelData implements SS_List, Filterable, Sortable, Limi
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Filterable::filterByCallback()
|
||||
* @see SS_List::filterByCallback()
|
||||
*
|
||||
* @example $list = $list->filterByCallback(function($item, $list) { return $item->Age == 9; })
|
||||
* @param callable $callback
|
||||
@ -864,7 +861,7 @@ class ArrayList extends ModelData implements SS_List, Filterable, Sortable, Limi
|
||||
{
|
||||
if (!is_callable($callback)) {
|
||||
throw new LogicException(sprintf(
|
||||
"SS_Filterable::filterByCallback() passed callback must be callable, '%s' given",
|
||||
"SS_List::filterByCallback() passed callback must be callable, '%s' given",
|
||||
gettype($callback)
|
||||
));
|
||||
}
|
||||
|
@ -1,107 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Model\List;
|
||||
|
||||
/**
|
||||
* Additional interface for {@link SS_List} classes that are filterable.
|
||||
*
|
||||
* All methods in this interface are immutable - they should return new instances with the filter
|
||||
* applied, rather than applying the filter in place
|
||||
*
|
||||
* @see SS_List
|
||||
* @see Sortable
|
||||
* @see Limitable
|
||||
*
|
||||
* @template T
|
||||
* @extends SS_List<T>
|
||||
*/
|
||||
interface Filterable extends SS_List
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns TRUE if the list can be filtered by a given field expression.
|
||||
*
|
||||
* @param string $by
|
||||
* @return bool
|
||||
*/
|
||||
public function canFilterBy($by);
|
||||
|
||||
/**
|
||||
* Return a new instance of this list that only includes items with these characteristics
|
||||
*
|
||||
* @example $list = $list->filter('Name', 'bob'); // only bob in the list
|
||||
* @example $list = $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
|
||||
* @example $list = $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob with the age 21
|
||||
* @example $list = $list->filter(array('Name'=>'bob, 'Age'=>array(21, 43))); // bob with the Age 21 or 43
|
||||
* @example $list = $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43)));
|
||||
* // aziz with the age 21 or 43 and bob with the Age 21 or 43
|
||||
*
|
||||
* @return static<T>
|
||||
*/
|
||||
public function filter();
|
||||
|
||||
/**
|
||||
* Return a copy of this list which contains items matching any of these characteristics.
|
||||
*
|
||||
* @example // only bob in the list
|
||||
* $list = $list->filterAny('Name', 'bob');
|
||||
* // SQL: WHERE "Name" = 'bob'
|
||||
* @example // azis or bob in the list
|
||||
* $list = $list->filterAny('Name', array('aziz', 'bob');
|
||||
* // SQL: WHERE ("Name" IN ('aziz','bob'))
|
||||
* @example // bob or anyone aged 21 in the list
|
||||
* $list = $list->filterAny(array('Name'=>'bob, 'Age'=>21));
|
||||
* // SQL: WHERE ("Name" = 'bob' OR "Age" = '21')
|
||||
* @example // bob or anyone aged 21 or 43 in the list
|
||||
* $list = $list->filterAny(array('Name'=>'bob, 'Age'=>array(21, 43)));
|
||||
* // SQL: WHERE ("Name" = 'bob' OR ("Age" IN ('21', '43'))
|
||||
* @example // all bobs, phils or anyone aged 21 or 43 in the list
|
||||
* $list = $list->filterAny(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
|
||||
* // SQL: WHERE (("Name" IN ('bob', 'phil')) OR ("Age" IN ('21', '43'))
|
||||
*
|
||||
* @param string|array See {@link filter()}
|
||||
* @return static<T>
|
||||
*/
|
||||
public function filterAny();
|
||||
|
||||
/**
|
||||
* Return a new instance of this list that excludes any items with these characteristics
|
||||
*
|
||||
* @example $list = $list->exclude('Name', 'bob'); // exclude bob from list
|
||||
* @example $list = $list->exclude('Name', array('aziz', 'bob'); // exclude aziz and bob from list
|
||||
* @example $list = $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob that has Age 21
|
||||
* @example $list = $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43
|
||||
* @example $list = $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
|
||||
* // bob age 21 or 43, phil age 21 or 43 would be excluded
|
||||
*
|
||||
* @return static<T>
|
||||
*/
|
||||
public function exclude();
|
||||
|
||||
/**
|
||||
* Return a new instance of this list that excludes any items with these characteristics
|
||||
* Filter this List by a callback function. The function will be passed each record of the List in turn,
|
||||
* and must return true for the record to be included. Returns the filtered list.
|
||||
*
|
||||
* @example $list = $list->filterByCallback(function($item, $list) { return $item->Age == 9; })
|
||||
* @param callable $callback
|
||||
* @return SS_List<T>
|
||||
*/
|
||||
public function filterByCallback($callback);
|
||||
|
||||
/**
|
||||
* Return the first item with the given ID
|
||||
*
|
||||
* @param int $id
|
||||
* @return T|null
|
||||
*/
|
||||
public function byID($id);
|
||||
|
||||
/**
|
||||
* Filter this list to only contain the given Primary IDs
|
||||
*
|
||||
* @param array $ids Array of integers
|
||||
* @return static<T>
|
||||
*/
|
||||
public function byIDs($ids);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Model\List;
|
||||
|
||||
/**
|
||||
* Additional interface for {@link SS_List} classes that are limitable - able to have a subset of the list extracted.
|
||||
*
|
||||
* All methods in this interface are immutable - they should return new instances with the limit
|
||||
* applied, rather than applying the limit in place
|
||||
*
|
||||
* @see SS_List
|
||||
* @see Sortable
|
||||
* @see Filterable
|
||||
*
|
||||
* @template T
|
||||
* @implements SS_List<T>
|
||||
*/
|
||||
interface Limitable extends SS_List
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns a new instance of this list where no more than $limit records are included.
|
||||
* If $offset is specified, then that many records at the beginning of the list will be skipped.
|
||||
* This matches the behaviour of the SQL LIMIT clause.
|
||||
*
|
||||
* If `$length` is null, then no limit is applied. If `$length` is 0, then an empty list is returned.
|
||||
*
|
||||
* @throws InvalidArgumentException if $length or offset are negative
|
||||
* @return static<T>
|
||||
*/
|
||||
public function limit(?int $length, int $offset = 0): Limitable;
|
||||
}
|
@ -5,39 +5,36 @@ namespace SilverStripe\Model\List;
|
||||
use SilverStripe\Model\ModelData;
|
||||
use LogicException;
|
||||
use Traversable;
|
||||
use BadMethodCallException;
|
||||
|
||||
/**
|
||||
* A base class for decorators that wrap around a list to provide additional
|
||||
* functionality. It passes through list methods to the underlying list
|
||||
* implementation.
|
||||
*
|
||||
* @template TList of SS_List&Sortable&Filterable&Limitable
|
||||
* @template T
|
||||
* @implements SS_List<T>
|
||||
* @implements Sortable<T>
|
||||
* @implements Filterable<T>
|
||||
* @implements Limitable<T>
|
||||
*/
|
||||
abstract class ListDecorator extends ModelData implements SS_List, Sortable, Filterable, Limitable
|
||||
abstract class ListDecorator extends ModelData implements SS_List
|
||||
{
|
||||
/**
|
||||
* @var TList<T>
|
||||
* @var SS_List<T>
|
||||
*/
|
||||
protected SS_List&Sortable&Filterable&Limitable $list;
|
||||
protected SS_List $list;
|
||||
|
||||
/**
|
||||
* @param TList<T> $list
|
||||
* @param SS_List<T> $list
|
||||
*/
|
||||
public function __construct(SS_List&Sortable&Filterable&Limitable $list)
|
||||
public function __construct(SS_List $list)
|
||||
{
|
||||
$this->setList($list);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TList<T>
|
||||
* @return SS_List<T>
|
||||
*/
|
||||
public function getList(): SS_List&Sortable&Filterable&Limitable
|
||||
public function getList(): SS_List
|
||||
{
|
||||
return $this->list;
|
||||
}
|
||||
@ -48,12 +45,12 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
* Useful for keeping a decorator/paginated list configuration intact while modifying
|
||||
* the underlying list.
|
||||
*
|
||||
* @template TListA
|
||||
* @template SS_ListA
|
||||
* @template TA
|
||||
* @param TListA<TA> $list
|
||||
* @return static<TListA, TA>
|
||||
* @param SS_ListA<TA> $list
|
||||
* @return static<SS_ListA, TA>
|
||||
*/
|
||||
public function setList(SS_List&Sortable&Filterable&Limitable $list): ListDecorator
|
||||
public function setList(SS_List $list): ListDecorator
|
||||
{
|
||||
$this->list = $list;
|
||||
$this->failover = $this->list;
|
||||
@ -113,7 +110,10 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
|
||||
public function exists(): bool
|
||||
{
|
||||
return $this->list->exists();
|
||||
if (method_exists($this->list, 'exists')) {
|
||||
return call_user_func([$this->list, 'exists']);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function first()
|
||||
@ -141,7 +141,13 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
|
||||
public function forTemplate(): string
|
||||
{
|
||||
return $this->list->forTemplate();
|
||||
if (method_exists($this->list, 'forTemplate')) {
|
||||
return call_user_func([$this->list, 'forTemplate']);
|
||||
}
|
||||
throw new BadMethodCallException(sprintf(
|
||||
"Method 'forTemplate' not found on class '%s'",
|
||||
get_class($this->list)
|
||||
));
|
||||
}
|
||||
|
||||
public function map($index = 'ID', $titleField = 'Title')
|
||||
@ -161,11 +167,17 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
|
||||
public function columnUnique($value = "ID")
|
||||
{
|
||||
return $this->list->columnUnique($value);
|
||||
if (method_exists($this->list, 'columnUnique')) {
|
||||
return call_user_func([$this->list, 'columnUnique'], $value);
|
||||
}
|
||||
throw new BadMethodCallException(sprintf(
|
||||
"Method 'columnUnique' not found on class '%s'",
|
||||
get_class($this->list)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TList<T>
|
||||
* @return SS_List<T>
|
||||
*/
|
||||
public function each($callback)
|
||||
{
|
||||
@ -191,7 +203,7 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
* @example $list->sort('Name', 'ASC');
|
||||
* @example $list->sort(array('Name'=>'ASC,'Age'=>'DESC'));
|
||||
*
|
||||
* @return TList<T>
|
||||
* @return SS_List<T>
|
||||
*/
|
||||
public function sort()
|
||||
{
|
||||
@ -211,7 +223,7 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
* @example $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob or someone with Age 21
|
||||
* @example $list->filter(array('Name'=>'bob, 'Age'=>array(21, 43))); // bob or anyone with Age 21 or 43
|
||||
*
|
||||
* @return TList<T>
|
||||
* @return SS_List<T>
|
||||
*/
|
||||
public function filter()
|
||||
{
|
||||
@ -239,7 +251,7 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
*
|
||||
* @param string|array See {@link filter()}
|
||||
*
|
||||
* @return TList<T>
|
||||
* @return SS_List<T>
|
||||
*/
|
||||
public function filterAny()
|
||||
{
|
||||
@ -249,7 +261,7 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
/**
|
||||
* Note that, in the current implementation, the filtered list will be an ArrayList, but this may change in a
|
||||
* future implementation.
|
||||
* @see Filterable::filterByCallback()
|
||||
* @see SS_List::filterByCallback()
|
||||
*
|
||||
* @example $list = $list->filterByCallback(function($item, $list) { return $item->Age == 9; })
|
||||
* @param callable $callback
|
||||
@ -259,7 +271,7 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
{
|
||||
if (!is_callable($callback)) {
|
||||
throw new LogicException(sprintf(
|
||||
"SS_Filterable::filterByCallback() passed callback must be callable, '%s' given",
|
||||
"SS_List::filterByCallback() passed callback must be callable, '%s' given",
|
||||
gettype($callback)
|
||||
));
|
||||
}
|
||||
@ -273,9 +285,9 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TList<T>
|
||||
* @return SS_List<T>
|
||||
*/
|
||||
public function limit(?int $length, int $offset = 0): SS_List&Sortable&Filterable&Limitable
|
||||
public function limit(?int $length, int $offset = 0): SS_List
|
||||
{
|
||||
return $this->list->limit($length, $offset);
|
||||
}
|
||||
@ -290,7 +302,7 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
*
|
||||
* @param array $ids Array of integers
|
||||
*
|
||||
* @return TList<T>
|
||||
* @return SS_List<T>
|
||||
*/
|
||||
public function byIDs($ids)
|
||||
{
|
||||
@ -305,7 +317,7 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
* @example $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob or someone with Age 21
|
||||
* @example $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob or anyone with Age 21 or 43
|
||||
*
|
||||
* @return TList<T>
|
||||
* @return SS_List<T>
|
||||
*/
|
||||
public function exclude()
|
||||
{
|
||||
@ -314,6 +326,12 @@ abstract class ListDecorator extends ModelData implements SS_List, Sortable, Fil
|
||||
|
||||
public function debug(): string
|
||||
{
|
||||
return $this->list->debug();
|
||||
if (method_exists($this->list, 'debug')) {
|
||||
return call_user_func([$this->list, 'debug']);
|
||||
}
|
||||
throw new BadMethodCallException(sprintf(
|
||||
"Method 'debug' not found on class '%s'",
|
||||
get_class($this->list)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ use IteratorAggregate;
|
||||
*/
|
||||
interface SS_List extends ArrayAccess, Countable, IteratorAggregate
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns all the items in the list in an array.
|
||||
*
|
||||
@ -94,4 +93,135 @@ interface SS_List extends ArrayAccess, Countable, IteratorAggregate
|
||||
* @return static<T>
|
||||
*/
|
||||
public function each($callback);
|
||||
|
||||
|
||||
/**
|
||||
* Returns TRUE if the list can be filtered by a given field expression.
|
||||
*
|
||||
* @param string $by
|
||||
* @return bool
|
||||
*/
|
||||
public function canFilterBy($by);
|
||||
|
||||
/**
|
||||
* Return a new instance of this list that only includes items with these characteristics
|
||||
*
|
||||
* @example $list = $list->filter('Name', 'bob'); // only bob in the list
|
||||
* @example $list = $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
|
||||
* @example $list = $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob with the age 21
|
||||
* @example $list = $list->filter(array('Name'=>'bob, 'Age'=>array(21, 43))); // bob with the Age 21 or 43
|
||||
* @example $list = $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43)));
|
||||
* // aziz with the age 21 or 43 and bob with the Age 21 or 43
|
||||
*
|
||||
* @return static<T>
|
||||
*/
|
||||
public function filter();
|
||||
|
||||
/**
|
||||
* Return a copy of this list which contains items matching any of these characteristics.
|
||||
*
|
||||
* @example // only bob in the list
|
||||
* $list = $list->filterAny('Name', 'bob');
|
||||
* // SQL: WHERE "Name" = 'bob'
|
||||
* @example // azis or bob in the list
|
||||
* $list = $list->filterAny('Name', array('aziz', 'bob');
|
||||
* // SQL: WHERE ("Name" IN ('aziz','bob'))
|
||||
* @example // bob or anyone aged 21 in the list
|
||||
* $list = $list->filterAny(array('Name'=>'bob, 'Age'=>21));
|
||||
* // SQL: WHERE ("Name" = 'bob' OR "Age" = '21')
|
||||
* @example // bob or anyone aged 21 or 43 in the list
|
||||
* $list = $list->filterAny(array('Name'=>'bob, 'Age'=>array(21, 43)));
|
||||
* // SQL: WHERE ("Name" = 'bob' OR ("Age" IN ('21', '43'))
|
||||
* @example // all bobs, phils or anyone aged 21 or 43 in the list
|
||||
* $list = $list->filterAny(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
|
||||
* // SQL: WHERE (("Name" IN ('bob', 'phil')) OR ("Age" IN ('21', '43'))
|
||||
*
|
||||
* @param string|array See {@link filter()}
|
||||
* @return static<T>
|
||||
*/
|
||||
public function filterAny();
|
||||
|
||||
/**
|
||||
* Return a new instance of this list that excludes any items with these characteristics
|
||||
*
|
||||
* @example $list = $list->exclude('Name', 'bob'); // exclude bob from list
|
||||
* @example $list = $list->exclude('Name', array('aziz', 'bob'); // exclude aziz and bob from list
|
||||
* @example $list = $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob that has Age 21
|
||||
* @example $list = $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43
|
||||
* @example $list = $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
|
||||
* // bob age 21 or 43, phil age 21 or 43 would be excluded
|
||||
*
|
||||
* @return static<T>
|
||||
*/
|
||||
public function exclude();
|
||||
|
||||
/**
|
||||
* Return a new instance of this list that excludes any items with these characteristics
|
||||
* Filter this List by a callback function. The function will be passed each record of the List in turn,
|
||||
* and must return true for the record to be included. Returns the filtered list.
|
||||
*
|
||||
* @example $list = $list->filterByCallback(function($item, $list) { return $item->Age == 9; })
|
||||
* @param callable $callback
|
||||
* @return SS_List<T>
|
||||
*/
|
||||
public function filterByCallback($callback);
|
||||
|
||||
/**
|
||||
* Return the first item with the given ID
|
||||
*
|
||||
* @param int $id
|
||||
* @return T|null
|
||||
*/
|
||||
public function byID($id);
|
||||
|
||||
/**
|
||||
* Filter this list to only contain the given Primary IDs
|
||||
*
|
||||
* @param array $ids Array of integers
|
||||
* @return static<T>
|
||||
*/
|
||||
public function byIDs($ids);
|
||||
|
||||
/**
|
||||
* Returns TRUE if the list can be sorted by a field.
|
||||
*
|
||||
* @param string $by
|
||||
* @return bool
|
||||
*/
|
||||
public function canSortBy($by);
|
||||
|
||||
/**
|
||||
* Return a new instance of this list that is sorted by one or more fields. You can either pass in a single
|
||||
* field name and direction, or a map of field names to sort directions.
|
||||
*
|
||||
* @example $list = $list->sort('Name'); // default ASC sorting
|
||||
* @example $list = $list->sort('Name DESC'); // DESC sorting
|
||||
* @example $list = $list->sort('Name', 'ASC');
|
||||
* @example $list = $list->sort(array('Name'=>'ASC,'Age'=>'DESC'));
|
||||
*
|
||||
* @return static<T>
|
||||
*/
|
||||
public function sort();
|
||||
|
||||
|
||||
/**
|
||||
* Return a new instance of this list based on reversing the current sort.
|
||||
*
|
||||
* @example $list = $list->reverse();
|
||||
*
|
||||
* @return static<T>
|
||||
*/
|
||||
public function reverse();
|
||||
|
||||
/**
|
||||
* Returns a new instance of this list where no more than $limit records are included.
|
||||
* If $offset is specified, then that many records at the beginning of the list will be skipped.
|
||||
* This matches the behaviour of the SQL LIMIT clause.
|
||||
*
|
||||
* If `$length` is null, then no limit is applied. If `$length` is 0, then an empty list is returned.
|
||||
*
|
||||
* @throws InvalidArgumentException if $length or offset are negative
|
||||
* @return static<T>
|
||||
*/
|
||||
public function limit(?int $length, int $offset = 0): SS_List;
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Model\List;
|
||||
|
||||
/**
|
||||
* Additional interface for {@link SS_List} classes that are sortable.
|
||||
*
|
||||
* All methods in this interface are immutable - they should return new instances with the sort
|
||||
* applied, rather than applying the sort in place
|
||||
*
|
||||
* @see SS_List
|
||||
* @see Filterable
|
||||
* @see Limitable
|
||||
*
|
||||
* @template T
|
||||
* @implements SS_List<T>
|
||||
*/
|
||||
interface Sortable extends SS_List
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns TRUE if the list can be sorted by a field.
|
||||
*
|
||||
* @param string $by
|
||||
* @return bool
|
||||
*/
|
||||
public function canSortBy($by);
|
||||
|
||||
/**
|
||||
* Return a new instance of this list that is sorted by one or more fields. You can either pass in a single
|
||||
* field name and direction, or a map of field names to sort directions.
|
||||
*
|
||||
* @example $list = $list->sort('Name'); // default ASC sorting
|
||||
* @example $list = $list->sort('Name DESC'); // DESC sorting
|
||||
* @example $list = $list->sort('Name', 'ASC');
|
||||
* @example $list = $list->sort(array('Name'=>'ASC,'Age'=>'DESC'));
|
||||
*
|
||||
* @return static<T>
|
||||
*/
|
||||
public function sort();
|
||||
|
||||
|
||||
/**
|
||||
* Return a new instance of this list based on reversing the current sort.
|
||||
*
|
||||
* @example $list = $list->reverse();
|
||||
*
|
||||
* @return static<T>
|
||||
*/
|
||||
public function reverse();
|
||||
}
|
@ -15,6 +15,7 @@ use SilverStripe\Core\Injector\Injectable;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\Debug;
|
||||
use SilverStripe\Core\ArrayLib;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\Model\List\ArrayList;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\ORM\FieldType\DBHTMLText;
|
||||
@ -385,9 +386,12 @@ class ModelData
|
||||
|
||||
/**
|
||||
* Get the class name a field on this object will be casted to.
|
||||
*
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
|
||||
*/
|
||||
public function castingClass(string $field): string
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.');
|
||||
// Strip arguments
|
||||
$spec = $this->castingHelper($field);
|
||||
return trim(strtok($spec ?? '', '(') ?? '');
|
||||
@ -397,9 +401,11 @@ class ModelData
|
||||
* Return the string-format type for the given field.
|
||||
*
|
||||
* @return string 'xml'|'raw'
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
|
||||
*/
|
||||
public function escapeTypeForField(string $field): string
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.');
|
||||
$class = $this->castingClass($field) ?: $this->config()->get('default_cast');
|
||||
|
||||
/** @var DBField $type */
|
||||
@ -445,9 +451,11 @@ class ModelData
|
||||
* @param string $fieldName Name of field
|
||||
* @param array $arguments List of optional arguments given
|
||||
* @return string
|
||||
* @deprecated 5.4.0 Will be made private
|
||||
*/
|
||||
protected function objCacheName($fieldName, $arguments)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be made private');
|
||||
return $arguments
|
||||
? $fieldName . ":" . var_export($arguments, true)
|
||||
: $fieldName;
|
||||
@ -506,6 +514,9 @@ class ModelData
|
||||
bool $cache = false,
|
||||
?string $cacheName = null
|
||||
): ?object {
|
||||
if ($cacheName !== null) {
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'The $cacheName parameter has been deprecated and will be removed');
|
||||
}
|
||||
$hasObj = false;
|
||||
if (!$cacheName && $cache) {
|
||||
$cacheName = $this->objCacheName($fieldName, $arguments);
|
||||
@ -569,9 +580,11 @@ class ModelData
|
||||
* without re-running the method.
|
||||
*
|
||||
* @return Object|DBField
|
||||
* @deprecated 5.4.0 use obj() instead
|
||||
*/
|
||||
public function cachedCall(string $fieldName, array $arguments = [], ?string $cacheName = null): object
|
||||
{
|
||||
Deprecation::notice('5.4.0', 'Use obj() instead');
|
||||
return $this->obj($fieldName, $arguments, true, $cacheName);
|
||||
}
|
||||
|
||||
@ -591,9 +604,12 @@ class ModelData
|
||||
/**
|
||||
* Get the string value of a field on this object that has been suitable escaped to be inserted directly into a
|
||||
* template.
|
||||
*
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
|
||||
*/
|
||||
public function XML_val(string $field, array $arguments = [], bool $cache = false): string
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0');
|
||||
$result = $this->obj($field, $arguments, $cache);
|
||||
if (!$result) {
|
||||
return '';
|
||||
@ -606,9 +622,11 @@ class ModelData
|
||||
* Get an array of XML-escaped values by field name
|
||||
*
|
||||
* @param array $fields an array of field names
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
|
||||
*/
|
||||
public function getXMLValues(array $fields): array
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0');
|
||||
$result = [];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
|
@ -14,10 +14,7 @@ use SilverStripe\ORM\Connect\Query;
|
||||
use Traversable;
|
||||
use SilverStripe\ORM\DataQuery;
|
||||
use SilverStripe\Model\List\ArrayList;
|
||||
use SilverStripe\Model\List\Filterable;
|
||||
use SilverStripe\Model\List\Limitable;
|
||||
use SilverStripe\Model\List\Map;
|
||||
use SilverStripe\Model\List\Sortable;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
use SilverStripe\ORM\Filters\SearchFilterable;
|
||||
|
||||
@ -43,11 +40,8 @@ use SilverStripe\ORM\Filters\SearchFilterable;
|
||||
*
|
||||
* @template T of DataObject
|
||||
* @implements SS_List<T>
|
||||
* @implements Filterable<T>
|
||||
* @implements Sortable<T>
|
||||
* @implements Limitable<T>
|
||||
*/
|
||||
class DataList extends ModelData implements SS_List, Filterable, Sortable, Limitable
|
||||
class DataList extends ModelData implements SS_List
|
||||
{
|
||||
use SearchFilterable;
|
||||
|
||||
@ -474,7 +468,7 @@ class DataList extends ModelData implements SS_List, Filterable, Sortable, Limit
|
||||
*
|
||||
* Raw SQL is not accepted, only actual field names can be passed
|
||||
*
|
||||
* @see Filterable::filter()
|
||||
* @see SS_List::filter()
|
||||
*
|
||||
* @example $list = $list->filter('Name', 'bob'); // only bob in the list
|
||||
* @example $list = $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
|
||||
@ -591,7 +585,7 @@ class DataList extends ModelData implements SS_List, Filterable, Sortable, Limit
|
||||
/**
|
||||
* Note that, in the current implementation, the filtered list will be an ArrayList, but this may change in a
|
||||
* future implementation.
|
||||
* @see Filterable::filterByCallback()
|
||||
* @see SS_List::filterByCallback()
|
||||
*
|
||||
* @example $list = $list->filterByCallback(function($item, $list) { return $item->Age == 9; })
|
||||
* @param callable $callback
|
||||
@ -601,7 +595,7 @@ class DataList extends ModelData implements SS_List, Filterable, Sortable, Limit
|
||||
{
|
||||
if (!is_callable($callback)) {
|
||||
throw new LogicException(sprintf(
|
||||
"SS_Filterable::filterByCallback() passed callback must be callable, '%s' given",
|
||||
"SS_List::filterByCallback() passed callback must be callable, '%s' given",
|
||||
gettype($callback)
|
||||
));
|
||||
}
|
||||
|
@ -11,10 +11,7 @@ use InvalidArgumentException;
|
||||
use LogicException;
|
||||
use SilverStripe\Core\ArrayLib;
|
||||
use SilverStripe\Model\List\ArrayList;
|
||||
use SilverStripe\Model\List\Filterable;
|
||||
use SilverStripe\Model\List\Limitable;
|
||||
use SilverStripe\Model\List\Map;
|
||||
use SilverStripe\Model\List\Sortable;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
use SilverStripe\ORM\Filters\SearchFilterable;
|
||||
use Traversable;
|
||||
@ -32,11 +29,8 @@ use Traversable;
|
||||
* @template T of DataObject
|
||||
* @implements Relation<T>
|
||||
* @implements SS_List<T>
|
||||
* @implements Filterable<T>
|
||||
* @implements Sortable<T>
|
||||
* @implements Limitable<T>
|
||||
*/
|
||||
class EagerLoadedList extends ModelData implements Relation, SS_List, Filterable, Sortable, Limitable
|
||||
class EagerLoadedList extends ModelData implements Relation, SS_List
|
||||
{
|
||||
use SearchFilterable;
|
||||
|
||||
|
@ -2,9 +2,6 @@
|
||||
|
||||
namespace SilverStripe\ORM;
|
||||
|
||||
use SilverStripe\Model\List\Filterable;
|
||||
use SilverStripe\Model\List\Limitable;
|
||||
use SilverStripe\Model\List\Sortable;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
|
||||
@ -19,11 +16,8 @@ use SilverStripe\ORM\FieldType\DBField;
|
||||
*
|
||||
* @template T
|
||||
* @extends SS_List<T>
|
||||
* @extends Filterable<T>
|
||||
* @extends Sortable<T>
|
||||
* @extends Limitable<T>
|
||||
*/
|
||||
interface Relation extends SS_List, Filterable, Sortable, Limitable
|
||||
interface Relation extends SS_List
|
||||
{
|
||||
|
||||
/**
|
||||
|
@ -8,11 +8,9 @@ use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\Model\List\Filterable;
|
||||
use SilverStripe\ORM\Filters\PartialMatchFilter;
|
||||
use SilverStripe\ORM\Filters\SearchFilter;
|
||||
use SilverStripe\Model\List\Limitable;
|
||||
use SilverStripe\Model\List\Sortable;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
|
||||
/**
|
||||
* A SearchContext that can be used with non-ORM data.
|
||||
@ -37,12 +35,12 @@ class BasicSearchContext extends SearchContext
|
||||
* for example "Comments__Name" instead of the filter name "Comments.Name".
|
||||
* @param array|bool|string $sort Field to sort on.
|
||||
* @param array|null|string $limit
|
||||
* @param Filterable&Sortable&Limitable $existingQuery
|
||||
* @param SS_List $existingQuery
|
||||
*/
|
||||
public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = null): Filterable&Sortable&Limitable
|
||||
public function getQuery($searchParams, $sort = false, $limit = false, $existingQuery = null): SS_List
|
||||
{
|
||||
if (!$existingQuery || !($existingQuery instanceof Filterable) || !($existingQuery instanceof Sortable) || !($existingQuery instanceof Limitable)) {
|
||||
throw new InvalidArgumentException('getQuery requires a pre-existing filterable/sortable/limitable list to be passed as $existingQuery.');
|
||||
if (!$existingQuery || !is_a($existingQuery, SS_List::class)) {
|
||||
throw new InvalidArgumentException('getQuery requires a pre-existing SS_List list to be passed as $existingQuery.');
|
||||
}
|
||||
|
||||
if ((count(func_get_args()) >= 3) && (!in_array(gettype($limit), ['array', 'NULL', 'string']))) {
|
||||
@ -98,7 +96,7 @@ class BasicSearchContext extends SearchContext
|
||||
return $applied;
|
||||
}
|
||||
|
||||
private function applyGeneralSearchField(array &$searchParams, Filterable $existingQuery): Filterable
|
||||
private function applyGeneralSearchField(array &$searchParams, SS_List $existingQuery): SS_List
|
||||
{
|
||||
$generalFieldName = static::config()->get('general_search_field_name');
|
||||
if (array_key_exists($generalFieldName, $searchParams)) {
|
||||
|
@ -948,7 +948,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
||||
$arguments = $res['arguments'];
|
||||
|
||||
// Note: 'type' here is important to disable subTemplates in SSViewer::getSubtemplateFor()
|
||||
$res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getItem(), [' .
|
||||
$res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getCurrentItem(), [' .
|
||||
implode(',', $arguments)."], \$scope, true);\n";
|
||||
|
||||
if ($this->includeDebuggingComments) { // Add include filename comments on dev sites
|
||||
|
@ -3897,7 +3897,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
||||
$arguments = $res['arguments'];
|
||||
|
||||
// Note: 'type' here is important to disable subTemplates in SSViewer::getSubtemplateFor()
|
||||
$res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getItem(), [' .
|
||||
$res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getCurrentItem(), [' .
|
||||
implode(',', $arguments)."], \$scope, true);\n";
|
||||
|
||||
if ($this->includeDebuggingComments) { // Add include filename comments on dev sites
|
||||
|
@ -16,6 +16,7 @@ use SilverStripe\ORM\FieldType\DBHTMLText;
|
||||
use SilverStripe\Security\Permission;
|
||||
use InvalidArgumentException;
|
||||
use SilverStripe\Model\ModelData;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
|
||||
/**
|
||||
* Parses a template file with an *.ss file extension.
|
||||
@ -87,6 +88,7 @@ class SSViewer implements Flushable
|
||||
*
|
||||
* @config
|
||||
* @var string
|
||||
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine.global_key
|
||||
*/
|
||||
private static $global_key = '$CurrentReadingMode, $CurrentUser.ID';
|
||||
|
||||
@ -135,6 +137,7 @@ class SSViewer implements Flushable
|
||||
* List of items being processed
|
||||
*
|
||||
* @var array
|
||||
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
|
||||
*/
|
||||
protected static $topLevel = [];
|
||||
|
||||
@ -142,6 +145,7 @@ class SSViewer implements Flushable
|
||||
* List of templates to select from
|
||||
*
|
||||
* @var array
|
||||
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
|
||||
*/
|
||||
protected $templates = null;
|
||||
|
||||
@ -149,6 +153,7 @@ class SSViewer implements Flushable
|
||||
* Absolute path to chosen template file
|
||||
*
|
||||
* @var string
|
||||
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
|
||||
*/
|
||||
protected $chosen = null;
|
||||
|
||||
@ -156,6 +161,7 @@ class SSViewer implements Flushable
|
||||
* Templates to use when looking up 'Layout' or 'Content'
|
||||
*
|
||||
* @var array
|
||||
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
|
||||
*/
|
||||
protected $subTemplates = [];
|
||||
|
||||
@ -166,11 +172,13 @@ class SSViewer implements Flushable
|
||||
|
||||
/**
|
||||
* @var TemplateParser
|
||||
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
|
||||
*/
|
||||
protected $parser;
|
||||
|
||||
/**
|
||||
* @var CacheInterface
|
||||
* @deprecated 5.4.0 Will be moved to SilverStripe\View\SSTemplateEngine
|
||||
*/
|
||||
protected $partialCacheStore = null;
|
||||
|
||||
@ -186,6 +194,7 @@ class SSViewer implements Flushable
|
||||
public function __construct($templates, TemplateParser $parser = null)
|
||||
{
|
||||
if ($parser) {
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'The $parser parameter is deprecated and will be removed');
|
||||
$this->setParser($parser);
|
||||
}
|
||||
|
||||
@ -208,9 +217,11 @@ class SSViewer implements Flushable
|
||||
|
||||
/**
|
||||
* Triggered early in the request when someone requests a flush.
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::flush()
|
||||
*/
|
||||
public static function flush()
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::flush()');
|
||||
SSViewer::flush_template_cache(true);
|
||||
SSViewer::flush_cacheblock_cache(true);
|
||||
}
|
||||
@ -221,9 +232,11 @@ class SSViewer implements Flushable
|
||||
* @param string $content The template content
|
||||
* @param bool|void $cacheTemplate Whether or not to cache the template from string
|
||||
* @return SSViewer
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()
|
||||
*/
|
||||
public static function fromString($content, $cacheTemplate = null)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()');
|
||||
$viewer = SSViewer_FromString::create($content);
|
||||
if ($cacheTemplate !== null) {
|
||||
$viewer->setCacheTemplate($cacheTemplate);
|
||||
@ -326,9 +339,11 @@ class SSViewer implements Flushable
|
||||
* Get the current item being processed
|
||||
*
|
||||
* @return ModelData
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
|
||||
*/
|
||||
public static function topLevel()
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.');
|
||||
if (SSViewer::$topLevel) {
|
||||
return SSViewer::$topLevel[sizeof(SSViewer::$topLevel)-1];
|
||||
}
|
||||
@ -386,9 +401,11 @@ class SSViewer implements Flushable
|
||||
|
||||
/**
|
||||
* @param string|array $templates
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setTemplate()
|
||||
*/
|
||||
public function setTemplate($templates)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setTemplate()');
|
||||
$this->templates = $templates;
|
||||
$this->chosen = $this->chooseTemplate($templates);
|
||||
$this->subTemplates = [];
|
||||
@ -399,9 +416,11 @@ class SSViewer implements Flushable
|
||||
*
|
||||
* @param array|string $templates
|
||||
* @return string
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
|
||||
*/
|
||||
public static function chooseTemplate($templates)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0');
|
||||
return ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes());
|
||||
}
|
||||
|
||||
@ -409,9 +428,11 @@ class SSViewer implements Flushable
|
||||
* Set the template parser that will be used in template generation
|
||||
*
|
||||
* @param TemplateParser $parser
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setParser()
|
||||
*/
|
||||
public function setParser(TemplateParser $parser)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setParser()');
|
||||
$this->parser = $parser;
|
||||
}
|
||||
|
||||
@ -419,9 +440,11 @@ class SSViewer implements Flushable
|
||||
* Returns the parser that is set for template generation
|
||||
*
|
||||
* @return TemplateParser
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::getParser()
|
||||
*/
|
||||
public function getParser()
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getParser()');
|
||||
if (!$this->parser) {
|
||||
$this->setParser(Injector::inst()->get('SilverStripe\\View\\SSTemplateParser'));
|
||||
}
|
||||
@ -434,9 +457,11 @@ class SSViewer implements Flushable
|
||||
* @param array|string $templates
|
||||
*
|
||||
* @return bool
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::hasTemplate()
|
||||
*/
|
||||
public static function hasTemplate($templates)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::hasTemplate()');
|
||||
return (bool)ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes());
|
||||
}
|
||||
|
||||
@ -453,9 +478,11 @@ class SSViewer implements Flushable
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
|
||||
*/
|
||||
public function exists()
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0');
|
||||
return $this->chosen;
|
||||
}
|
||||
|
||||
@ -463,9 +490,11 @@ class SSViewer implements Flushable
|
||||
* @param string $identifier A template name without '.ss' extension or path
|
||||
* @param string $type The template type, either "main", "Includes" or "Layout"
|
||||
* @return string Full system path to a template file
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
|
||||
*/
|
||||
public static function getTemplateFileByType($identifier, $type = null)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0');
|
||||
return ThemeResourceLoader::inst()->findTemplate(['type' => $type, $identifier], SSViewer::get_themes());
|
||||
}
|
||||
|
||||
@ -476,9 +505,11 @@ class SSViewer implements Flushable
|
||||
*
|
||||
* @param bool $force Set this to true to force a re-flush. If left to false, flushing
|
||||
* may only be performed once a request.
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::flushTemplateCache()
|
||||
*/
|
||||
public static function flush_template_cache($force = false)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::flushTemplateCache()');
|
||||
if (!SSViewer::$template_cache_flushed || $force) {
|
||||
$dir = dir(TEMP_PATH);
|
||||
while (false !== ($file = $dir->read())) {
|
||||
@ -497,9 +528,11 @@ class SSViewer implements Flushable
|
||||
*
|
||||
* @param bool $force Set this to true to force a re-flush. If left to false, flushing
|
||||
* may only be performed once a request.
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::flushCacheBlockCache()
|
||||
*/
|
||||
public static function flush_cacheblock_cache($force = false)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::flushCacheBlockCache()');
|
||||
if (!SSViewer::$cacheblock_cache_flushed || $force) {
|
||||
$cache = Injector::inst()->get(CacheInterface::class . '.cacheblock');
|
||||
$cache->clear();
|
||||
@ -513,9 +546,11 @@ class SSViewer implements Flushable
|
||||
* Set the cache object to use when storing / retrieving partial cache blocks.
|
||||
*
|
||||
* @param CacheInterface $cache
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::setPartialCacheStore()
|
||||
*/
|
||||
public function setPartialCacheStore($cache)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setPartialCacheStore()');
|
||||
$this->partialCacheStore = $cache;
|
||||
}
|
||||
|
||||
@ -523,9 +558,11 @@ class SSViewer implements Flushable
|
||||
* Get the cache object to use when storing / retrieving partial cache blocks.
|
||||
*
|
||||
* @return CacheInterface
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::getPartialCacheStore()
|
||||
*/
|
||||
public function getPartialCacheStore()
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getPartialCacheStore()');
|
||||
if ($this->partialCacheStore) {
|
||||
return $this->partialCacheStore;
|
||||
}
|
||||
@ -553,11 +590,13 @@ class SSViewer implements Flushable
|
||||
* @param ModelData $item The item to use as the root scope for the template
|
||||
* @param array $overlay Any variables to layer on top of the scope
|
||||
* @param array $underlay Any variables to layer underneath the scope
|
||||
* @param ModelData $inheritedScope The current scope of a parent template including a sub-template
|
||||
* @param SSViewer_Scope|null $inheritedScope The current scope of a parent template including a sub-template
|
||||
* @return string The result of executing the template
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::includeGeneratedTemplate()
|
||||
*/
|
||||
protected function includeGeneratedTemplate($cacheFile, $item, $overlay, $underlay, $inheritedScope = null)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::includeGeneratedTemplate()');
|
||||
if (isset($_GET['showtemplate']) && $_GET['showtemplate'] && Permission::check('ADMIN')) {
|
||||
$lines = file($cacheFile ?? '');
|
||||
echo "<h2>Template: $cacheFile</h2>";
|
||||
@ -597,6 +636,9 @@ class SSViewer implements Flushable
|
||||
*/
|
||||
public function process($item, $arguments = null, $inheritedScope = null)
|
||||
{
|
||||
if ($inheritedScope !== null) {
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'The $inheritedScope parameter is deprecated and will be removed');
|
||||
}
|
||||
// Set hashlinks and temporarily modify global state
|
||||
$rewrite = $this->getRewriteHashLinks();
|
||||
$origRewriteDefault = static::getRewriteHashLinksDefault();
|
||||
@ -683,9 +725,11 @@ PHP;
|
||||
* @param string $subtemplate Sub-template to use
|
||||
*
|
||||
* @return array|null
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::getSubtemplateFor()
|
||||
*/
|
||||
protected function getSubtemplateFor($subtemplate)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getSubtemplateFor()');
|
||||
// Get explicit subtemplate name
|
||||
if (isset($this->subTemplates[$subtemplate])) {
|
||||
return $this->subTemplates[$subtemplate];
|
||||
@ -723,9 +767,14 @@ PHP;
|
||||
* @param bool $globalRequirements
|
||||
*
|
||||
* @return string Evaluated result
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::execute_template()
|
||||
*/
|
||||
public static function execute_template($template, $data, $arguments = null, $scope = null, $globalRequirements = false)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment(
|
||||
'5.4.0',
|
||||
'Will be replaced with SilverStripe\View\SSTemplateEngine::execute_template()'
|
||||
);
|
||||
$v = SSViewer::create($template);
|
||||
|
||||
if ($globalRequirements) {
|
||||
@ -755,9 +804,11 @@ PHP;
|
||||
* @param bool $globalRequirements
|
||||
*
|
||||
* @return string Evaluated result
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()
|
||||
*/
|
||||
public static function execute_string($content, $data, $arguments = null, $globalRequirements = false)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()');
|
||||
$v = SSViewer::fromString($content);
|
||||
|
||||
if ($globalRequirements) {
|
||||
@ -782,9 +833,11 @@ PHP;
|
||||
* @param string $content The template contents
|
||||
* @param string $template The template file name
|
||||
* @return string
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::parseTemplateContent()
|
||||
*/
|
||||
public function parseTemplateContent($content, $template = "")
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::parseTemplateContent()');
|
||||
return $this->getParser()->compileString(
|
||||
$content,
|
||||
$template,
|
||||
@ -797,18 +850,22 @@ PHP;
|
||||
* 'Content' & 'Layout', and will have to contain 'main'
|
||||
*
|
||||
* @return array
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
|
||||
*/
|
||||
public function templates()
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0');
|
||||
return array_merge(['main' => $this->chosen], $this->subTemplates);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type "Layout" or "main"
|
||||
* @param string $file Full system path to the template file
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
|
||||
*/
|
||||
public function setTemplateFile($type, $file)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0');
|
||||
if (!$type || $type == 'main') {
|
||||
$this->chosen = $file;
|
||||
} else {
|
||||
@ -823,17 +880,29 @@ PHP;
|
||||
* @param string $contentGeneratedSoFar The content of the template generated so far; it should contain
|
||||
* the DOCTYPE declaration.
|
||||
* @return string
|
||||
* @deprecated 5.4.0 Use getBaseTag() instead
|
||||
*/
|
||||
public static function get_base_tag($contentGeneratedSoFar)
|
||||
{
|
||||
Deprecation::notice('5.4.0', 'Use getBaseTag() instead');
|
||||
// Is the document XHTML?
|
||||
$isXhtml = preg_match('/<!DOCTYPE[^>]+xhtml/i', $contentGeneratedSoFar ?? '');
|
||||
return static::getBaseTag($isXhtml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an appropriate base tag for the given template.
|
||||
* It will be closed on an XHTML document, and unclosed on an HTML document.
|
||||
*
|
||||
* @param bool $isXhtml Whether the DOCTYPE is xhtml or not.
|
||||
*/
|
||||
public static function getBaseTag(bool $isXhtml = false): string
|
||||
{
|
||||
// Base href should always have a trailing slash
|
||||
$base = rtrim(Director::absoluteBaseURL(), '/') . '/';
|
||||
|
||||
// Is the document XHTML?
|
||||
if (preg_match('/<!DOCTYPE[^>]+xhtml/i', $contentGeneratedSoFar ?? '')) {
|
||||
if ($isXhtml) {
|
||||
return "<base href=\"$base\" />";
|
||||
} else {
|
||||
return "<base href=\"$base\"><!--[if lte IE 6]></base><![endif]-->";
|
||||
}
|
||||
return "<base href=\"$base\"><!--[if lte IE 6]></base><![endif]-->";
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use InvalidArgumentException;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Model\ModelData;
|
||||
use SilverStripe\Model\List\ArrayList;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
|
||||
/**
|
||||
@ -13,7 +14,7 @@ use SilverStripe\ORM\FieldType\DBField;
|
||||
* data that is scope-independant (like BaseURL), or type-specific data that is layered on top cross-cut like
|
||||
* (like $FirstLast etc).
|
||||
*
|
||||
* It's separate from SSViewer_Scope to keep that fairly complex code as clean as possible.
|
||||
* @deprecated 5.4.0 Will be merged into SilverStripe\View\SSViewer_Scope
|
||||
*/
|
||||
class SSViewer_DataPresenter extends SSViewer_Scope
|
||||
{
|
||||
@ -67,6 +68,7 @@ class SSViewer_DataPresenter extends SSViewer_Scope
|
||||
array $underlay = null,
|
||||
SSViewer_Scope $inheritedScope = null
|
||||
) {
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be merged into ' . SSViewer_Scope::class, Deprecation::SCOPE_CLASS);
|
||||
parent::__construct($item, $inheritedScope);
|
||||
|
||||
$this->overlay = $overlay ?: [];
|
||||
|
@ -4,9 +4,11 @@ namespace SilverStripe\View;
|
||||
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
|
||||
/**
|
||||
* Special SSViewer that will process a template passed as a string, rather than a filename.
|
||||
* @deprecated 5.4.0 Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()
|
||||
*/
|
||||
class SSViewer_FromString extends SSViewer
|
||||
{
|
||||
@ -38,6 +40,11 @@ class SSViewer_FromString extends SSViewer
|
||||
*/
|
||||
public function __construct($content, TemplateParser $parser = null)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment(
|
||||
'5.4.0',
|
||||
'Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()',
|
||||
Deprecation::SCOPE_CLASS
|
||||
);
|
||||
if ($parser) {
|
||||
$this->setParser($parser);
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use ArrayIterator;
|
||||
use Countable;
|
||||
use Iterator;
|
||||
use SilverStripe\Model\List\ArrayList;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\FieldType\DBBoolean;
|
||||
use SilverStripe\ORM\FieldType\DBText;
|
||||
use SilverStripe\ORM\FieldType\DBFloat;
|
||||
@ -124,9 +125,11 @@ class SSViewer_Scope
|
||||
* Returns the current "active" item
|
||||
*
|
||||
* @return object
|
||||
* @deprecated 5.4.0 use getCurrentItem() instead.
|
||||
*/
|
||||
public function getItem()
|
||||
{
|
||||
Deprecation::notice('5.4.0', 'use getCurrentItem() instead.');
|
||||
$item = $this->itemIterator ? $this->itemIterator->current() : $this->item;
|
||||
if (is_scalar($item)) {
|
||||
$item = $this->convertScalarToDBField($item);
|
||||
@ -140,6 +143,11 @@ class SSViewer_Scope
|
||||
return $item;
|
||||
}
|
||||
|
||||
public function getCurrentItem()
|
||||
{
|
||||
return $this->getItem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called at the start of every lookup chain by SSTemplateParser to indicate a new lookup from local scope
|
||||
*
|
||||
@ -192,7 +200,7 @@ class SSViewer_Scope
|
||||
*/
|
||||
public function getObj($name, $arguments = [], $cache = false, $cacheName = null)
|
||||
{
|
||||
$on = $this->getItem();
|
||||
$on = $this->getCurrentItem();
|
||||
if ($on === null) {
|
||||
return null;
|
||||
}
|
||||
@ -205,9 +213,11 @@ class SSViewer_Scope
|
||||
* @param bool $cache
|
||||
* @param string $cacheName
|
||||
* @return $this
|
||||
* @deprecated 5.4.0 Will be renamed scopeToIntermediateValue()
|
||||
*/
|
||||
public function obj($name, $arguments = [], $cache = false, $cacheName = null)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be renamed scopeToIntermediateValue()');
|
||||
switch ($name) {
|
||||
case 'Up':
|
||||
if ($this->upIndex === null) {
|
||||
@ -259,7 +269,7 @@ class SSViewer_Scope
|
||||
*/
|
||||
public function self()
|
||||
{
|
||||
$result = $this->getItem();
|
||||
$result = $this->getCurrentItem();
|
||||
$this->resetLocalScope();
|
||||
|
||||
return $result;
|
||||
@ -359,8 +369,12 @@ class SSViewer_Scope
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
$on = $this->getItem();
|
||||
$retval = $on ? $on->$name(...$arguments) : null;
|
||||
$on = $this->getCurrentItem();
|
||||
if ($on instanceof ViewableData && $name === 'XML_val') {
|
||||
$retval = $on->XML_val(...$arguments);
|
||||
} else {
|
||||
$retval = $on ? $on->$name(...$arguments) : null;
|
||||
}
|
||||
|
||||
$this->resetLocalScope();
|
||||
return $retval;
|
||||
|
@ -9,6 +9,7 @@ use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||
use SilverStripe\Core\Manifest\ModuleResourceLoader;
|
||||
use SilverStripe\Core\Path;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
|
||||
/**
|
||||
* Handles finding templates from a stack of template manifest objects.
|
||||
@ -182,9 +183,11 @@ class ThemeResourceLoader implements Flushable, TemplateGlobalProvider
|
||||
* @return string Absolute path to resolved template file, or null if not resolved.
|
||||
* File location will be in the format themes/<theme>/templates/<directories>/<type>/<basename>.ss
|
||||
* Note that type (e.g. 'Layout') is not the root level directory under 'templates'.
|
||||
* @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
|
||||
*/
|
||||
public function findTemplate($template, $themes = null)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.');
|
||||
if ($themes === null) {
|
||||
$themes = SSViewer::get_themes();
|
||||
}
|
||||
|
@ -111,8 +111,8 @@ class DeprecationTest extends SapphireTest
|
||||
'Will be removed without equivalent functionality to replace it.',
|
||||
'Called from SilverStripe\Dev\Tests\DeprecationTest->testNoticeNoReplacement.'
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->expectException(DeprecationTestException::class);
|
||||
$this->expectExceptionMessage($message);
|
||||
$this->enableDeprecationNotices(true);
|
||||
$ret = $this->myDeprecatedMethodNoReplacement();
|
||||
$this->assertSame('abc', $ret);
|
||||
|
@ -5,7 +5,7 @@ namespace SilverStripe\Model\Tests\List;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Model\List\ArrayList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Model\List\Filterable;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
use SilverStripe\Model\ArrayData;
|
||||
use SilverStripe\Model\List\Map;
|
||||
use stdClass;
|
||||
@ -1455,7 +1455,7 @@ class ArrayListTest extends SapphireTest
|
||||
$this->assertEquals(2, $list->count());
|
||||
$this->assertEquals($steve, $list[0]->toMap(), 'List should only contain Steve and Clair');
|
||||
$this->assertEquals($clair, $list[1]->toMap(), 'List should only contain Steve and Clair');
|
||||
$this->assertTrue($list instanceof Filterable, 'The List should be of type SS_Filterable');
|
||||
$this->assertTrue($list instanceof SS_List, 'The List should be of type SS_List');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,7 +117,7 @@ class ListDecoratorTest extends SapphireTest
|
||||
public function testFilterByCallbackThrowsExceptionWhenGivenNonCallable()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->expectExceptionMessage("SS_Filterable::filterByCallback() passed callback must be callable, 'boolean' given");
|
||||
$this->expectExceptionMessage("SS_List::filterByCallback() passed callback must be callable, 'boolean' given");
|
||||
$this->decorator->filterByCallback(true);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ use SilverStripe\ORM\Connect\MySQLiConnector;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\ORM\DataQuery;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\Model\List\Filterable;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
use SilverStripe\ORM\Filters\ExactMatchFilter;
|
||||
use SilverStripe\ORM\Tests\DataObjectTest\DataListQueryCounter;
|
||||
use SilverStripe\ORM\Tests\DataObjectTest\Fixture;
|
||||
@ -1591,7 +1591,7 @@ class DataListTest extends SapphireTest
|
||||
|
||||
$this->assertEquals(2, $list->count());
|
||||
$this->assertEquals($expected, $result, 'List should only contain comments from Team 1 (Joe and Bob)');
|
||||
$this->assertTrue($list instanceof Filterable, 'The List should be of type SS_Filterable');
|
||||
$this->assertTrue($list instanceof SS_List, 'The List should be of type SS_List');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,7 @@ use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\Connect\MySQLiConnector;
|
||||
use SilverStripe\ORM\EagerLoadedList;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\Model\List\Filterable;
|
||||
use SilverStripe\Model\List\SS_List;
|
||||
use SilverStripe\ORM\Tests\DataObjectTest\EquipmentCompany;
|
||||
use SilverStripe\ORM\Tests\DataObjectTest\Fan;
|
||||
use SilverStripe\ORM\Tests\DataObjectTest\Player;
|
||||
@ -1690,7 +1690,7 @@ class EagerLoadedListTest extends SapphireTest
|
||||
|
||||
$this->assertEquals(2, $list->count());
|
||||
$this->assertEquals($expected, $result, 'List should only contain comments from Team 1 (Joe and Bob)');
|
||||
$this->assertTrue($list instanceof Filterable, 'The List should be of type SS_Filterable');
|
||||
$this->assertTrue($list instanceof SS_List, 'The List should be of type SS_List');
|
||||
}
|
||||
|
||||
public function testSimpleExclude()
|
||||
|
Loading…
Reference in New Issue
Block a user