diff --git a/src/Control/Controller.php b/src/Control/Controller.php
index 299ce72a7..3cc112f61 100644
--- a/src/Control/Controller.php
+++ b/src/Control/Controller.php
@@ -4,6 +4,7 @@ namespace SilverStripe\Control;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Dev\Debug;
+use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
@@ -455,7 +456,8 @@ class Controller extends RequestHandler implements TemplateGlobalProvider
$class = static::class;
while ($class != 'SilverStripe\\Control\\RequestHandler') {
$templateName = strtok($class ?? '', '_') . '_' . $action;
- if (SSViewer::hasTemplate($templateName)) {
+ $templateExists = Deprecation::withSuppressedNotice(fn() => SSViewer::hasTemplate($templateName));
+ if ($templateExists) {
return $class;
}
@@ -487,7 +489,7 @@ class Controller extends RequestHandler implements TemplateGlobalProvider
$parentClass = get_parent_class($parentClass ?? '');
}
- return SSViewer::hasTemplate($templates);
+ return Deprecation::withSuppressedNotice(fn() => SSViewer::hasTemplate($templates));
}
/**
diff --git a/src/Control/Email/Email.php b/src/Control/Email/Email.php
index 52b05dc94..fd1bc8195 100644
--- a/src/Control/Email/Email.php
+++ b/src/Control/Email/Email.php
@@ -12,6 +12,7 @@ use SilverStripe\Core\Environment;
use SilverStripe\Core\Extensible;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector;
+use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
@@ -402,9 +403,11 @@ class Email extends SymfonyEmail
return $this->HTMLTemplate;
}
- return ThemeResourceLoader::inst()->findTemplate(
- SSViewer::get_templates_by_class(static::class, '', Email::class),
- SSViewer::get_themes()
+ return Deprecation::withSuppressedNotice(
+ fn() => ThemeResourceLoader::inst()->findTemplate(
+ SSViewer::get_templates_by_class(static::class, '', Email::class),
+ SSViewer::get_themes()
+ )
);
}
diff --git a/src/Forms/GridField/GridFieldAddExistingAutocompleter.php b/src/Forms/GridField/GridFieldAddExistingAutocompleter.php
index 8db2bc627..8c2c6f18f 100644
--- a/src/Forms/GridField/GridFieldAddExistingAutocompleter.php
+++ b/src/Forms/GridField/GridFieldAddExistingAutocompleter.php
@@ -17,6 +17,7 @@ use SilverStripe\View\ArrayData;
use SilverStripe\View\SSViewer;
use LogicException;
use SilverStripe\Control\HTTPResponse_Exception;
+use SilverStripe\Dev\Deprecation;
/**
* This class is is responsible for adding objects to another object's has_many
@@ -283,7 +284,7 @@ class GridFieldAddExistingAutocompleter extends AbstractGridFieldComponent imple
$json = [];
Config::nest();
SSViewer::config()->set('source_file_comments', false);
- $viewer = SSViewer::fromString($this->resultsFormat);
+ $viewer = Deprecation::withSuppressedNotice(fn() => SSViewer::fromString($this->resultsFormat));
foreach ($results as $result) {
if (!$result->canView()) {
continue;
diff --git a/src/Forms/GridField/GridFieldDataColumns.php b/src/Forms/GridField/GridFieldDataColumns.php
index 41b0713d9..89aa85177 100644
--- a/src/Forms/GridField/GridFieldDataColumns.php
+++ b/src/Forms/GridField/GridFieldDataColumns.php
@@ -5,6 +5,7 @@ namespace SilverStripe\Forms\GridField;
use SilverStripe\Core\Convert;
use InvalidArgumentException;
use LogicException;
+use SilverStripe\Dev\Deprecation;
use SilverStripe\View\ViewableData;
/**
@@ -228,16 +229,18 @@ class GridFieldDataColumns extends AbstractGridFieldComponent implements GridFie
* @param ViewableData $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++) {
$methodName = $fieldNameParts[$idx];
// Last mmethod call from $columnName return what that method is returning
if ($idx == sizeof($fieldNameParts ?? []) - 1) {
- return $tmpItem->XML_val($methodName);
+ return Deprecation::withSuppressedNotice(fn() => $tmpItem->XML_val($methodName));
}
// else get the object from this $methodName
$tmpItem = $tmpItem->$methodName();
diff --git a/src/Forms/HTMLEditor/HTMLEditorField.php b/src/Forms/HTMLEditor/HTMLEditorField.php
index 90c3fad75..285d0ae9e 100644
--- a/src/Forms/HTMLEditor/HTMLEditorField.php
+++ b/src/Forms/HTMLEditor/HTMLEditorField.php
@@ -8,6 +8,7 @@ use SilverStripe\Forms\TextareaField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectInterface;
use Exception;
+use SilverStripe\Dev\Deprecation;
use SilverStripe\View\Parsers\HTMLValue;
/**
@@ -129,7 +130,9 @@ class HTMLEditorField extends TextareaField
*/
public function saveInto(DataObjectInterface $record)
{
- if ($record->hasField($this->name) && $record->escapeTypeForField($this->name) != 'xml') {
+ if ($record->hasField($this->name)
+ && Deprecation::withSuppressedNotice(fn () => $record->escapeTypeForField($this->name)) != 'xml'
+ ) {
throw new Exception(
'HTMLEditorField->saveInto(): This field should save into a HTMLText or HTMLVarchar field.'
);
diff --git a/src/View/SSTemplateParser.peg b/src/View/SSTemplateParser.peg
index 0f15460f9..76c40ed98 100644
--- a/src/View/SSTemplateParser.peg
+++ b/src/View/SSTemplateParser.peg
@@ -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
diff --git a/src/View/SSTemplateParser.php b/src/View/SSTemplateParser.php
index 9ca62eaa5..c7c273414 100644
--- a/src/View/SSTemplateParser.php
+++ b/src/View/SSTemplateParser.php
@@ -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
diff --git a/src/View/SSViewer.php b/src/View/SSViewer.php
index 3b82eb3fd..55f2fc087 100644
--- a/src/View/SSViewer.php
+++ b/src/View/SSViewer.php
@@ -15,6 +15,7 @@ use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\Security\Permission;
use InvalidArgumentException;
+use SilverStripe\Dev\Deprecation;
/**
* Parses a template file with an *.ss file extension.
@@ -86,6 +87,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';
@@ -134,6 +136,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 = [];
@@ -141,6 +144,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;
@@ -148,6 +152,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;
@@ -155,6 +160,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 = [];
@@ -165,11 +171,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;
@@ -185,10 +193,11 @@ class SSViewer implements Flushable
public function __construct($templates, TemplateParser $parser = null)
{
if ($parser) {
- $this->setParser($parser);
+ Deprecation::notice('5.4.0', 'The $parser parameter is deprecated and will be removed');
+ Deprecation::withSuppressedNotice(fn() => $this->setParser($parser));
}
- $this->setTemplate($templates);
+ Deprecation::withSuppressedNotice(fn() => $this->setTemplate($templates));
if (!$this->chosen) {
$message = 'None of the following templates could be found: ';
@@ -207,11 +216,15 @@ 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()
{
- SSViewer::flush_template_cache(true);
- SSViewer::flush_cacheblock_cache(true);
+ Deprecation::withSuppressedNotice(function () {
+ Deprecation::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::flush()');
+ SSViewer::flush_template_cache(true);
+ SSViewer::flush_cacheblock_cache(true);
+ });
}
/**
@@ -220,10 +233,12 @@ 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)
{
- $viewer = SSViewer_FromString::create($content);
+ Deprecation::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()');
+ $viewer = Deprecation::withSuppressedNotice(fn() => SSViewer_FromString::create($content));
if ($cacheTemplate !== null) {
$viewer->setCacheTemplate($cacheTemplate);
}
@@ -325,9 +340,11 @@ class SSViewer implements Flushable
* Get the current item being processed
*
* @return ViewableData
+ * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
*/
public static function topLevel()
{
+ Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it.');
if (SSViewer::$topLevel) {
return SSViewer::$topLevel[sizeof(SSViewer::$topLevel)-1];
}
@@ -385,9 +402,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::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setTemplate()');
$this->templates = $templates;
$this->chosen = $this->chooseTemplate($templates);
$this->subTemplates = [];
@@ -398,19 +417,25 @@ 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)
{
- return ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes());
+ Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it');
+ return Deprecation::withSuppressedNotice(
+ fn() => ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes())
+ );
}
/**
* 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::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setParser()');
$this->parser = $parser;
}
@@ -418,11 +443,15 @@ 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::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getParser()');
if (!$this->parser) {
- $this->setParser(Injector::inst()->get('SilverStripe\\View\\SSTemplateParser'));
+ Deprecation::withSuppressedNotice(
+ fn() => $this->setParser(Injector::inst()->get('SilverStripe\\View\\SSTemplateParser'))
+ );
}
return $this->parser;
}
@@ -433,10 +462,14 @@ 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)
{
- return (bool)ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes());
+ Deprecation::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::hasTemplate()');
+ return Deprecation::withSuppressedNotice(
+ fn() => (bool)ThemeResourceLoader::inst()->findTemplate($templates, SSViewer::get_themes())
+ );
}
/**
@@ -452,9 +485,11 @@ class SSViewer implements Flushable
/**
* @return string
+ * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
*/
public function exists()
{
+ Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it');
return $this->chosen;
}
@@ -462,10 +497,14 @@ 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)
{
- return ThemeResourceLoader::inst()->findTemplate(['type' => $type, $identifier], SSViewer::get_themes());
+ Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it');
+ return Deprecation::withSuppressedNotice(
+ fn() => ThemeResourceLoader::inst()->findTemplate(['type' => $type, $identifier], SSViewer::get_themes())
+ );
}
/**
@@ -475,9 +514,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::notice('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())) {
@@ -496,9 +537,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::notice('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();
@@ -512,9 +555,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::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::setPartialCacheStore()');
$this->partialCacheStore = $cache;
}
@@ -522,9 +567,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::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getPartialCacheStore()');
if ($this->partialCacheStore) {
return $this->partialCacheStore;
}
@@ -552,11 +599,13 @@ class SSViewer implements Flushable
* @param ViewableData $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 ViewableData $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::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::includeGeneratedTemplate()');
if (isset($_GET['showtemplate']) && $_GET['showtemplate'] && Permission::check('ADMIN')) {
$lines = file($cacheFile ?? '');
echo "
Template: $cacheFile
";
@@ -567,8 +616,10 @@ class SSViewer implements Flushable
echo "";
}
- $cache = $this->getPartialCacheStore();
- $scope = new SSViewer_DataPresenter($item, $overlay, $underlay, $inheritedScope);
+ $cache = Deprecation::withSuppressedNotice(fn() => $this->getPartialCacheStore());
+ $scope = Deprecation::withSuppressedNotice(
+ fn() => new SSViewer_DataPresenter($item, $overlay, $underlay, $inheritedScope)
+ );
$val = '';
// Placeholder for values exposed to $cacheFile
@@ -596,6 +647,11 @@ class SSViewer implements Flushable
*/
public function process($item, $arguments = null, $inheritedScope = null)
{
+ if ($inheritedScope !== null) {
+ Deprecation::withSuppressedNotice(
+ fn() => Deprecation::notice('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();
@@ -611,7 +667,7 @@ class SSViewer implements Flushable
if (!file_exists($cacheFile ?? '') || filemtime($cacheFile ?? '') < $lastEdited) {
$content = file_get_contents($template ?? '');
- $content = $this->parseTemplateContent($content, $template);
+ $content = Deprecation::withSuppressedNotice(fn() => $this->parseTemplateContent($content, $template));
$fh = fopen($cacheFile ?? '', 'w');
fwrite($fh, $content ?? '');
@@ -624,7 +680,7 @@ class SSViewer implements Flushable
// through $Content and $Layout placeholders.
foreach (['Content', 'Layout'] as $subtemplate) {
// Detect sub-template to use
- $sub = $this->getSubtemplateFor($subtemplate);
+ $sub = Deprecation::withSuppressedNotice(fn() => $this->getSubtemplateFor($subtemplate));
if (!$sub) {
continue;
}
@@ -635,17 +691,19 @@ class SSViewer implements Flushable
// Disable requirements - this will be handled by the parent template
$subtemplateViewer->includeRequirements(false);
// Select the right template
- $subtemplateViewer->setTemplate($sub);
+ Deprecation::withSuppressedNotice(fn() => $subtemplateViewer->setTemplate($sub));
// Render if available
- if ($subtemplateViewer->exists()) {
+ if (Deprecation::withSuppressedNotice(fn() => $subtemplateViewer->exists())) {
return $subtemplateViewer->process($item, $arguments);
}
return null;
};
}
- $output = $this->includeGeneratedTemplate($cacheFile, $item, $arguments, $underlay, $inheritedScope);
+ $output = Deprecation::withSuppressedNotice(
+ fn() => $this->includeGeneratedTemplate($cacheFile, $item, $arguments, $underlay, $inheritedScope)
+ );
if ($this->includeRequirements) {
$output = Requirements::includeInHTML($output);
@@ -682,9 +740,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::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::getSubtemplateFor()');
// Get explicit subtemplate name
if (isset($this->subTemplates[$subtemplate])) {
return $this->subTemplates[$subtemplate];
@@ -722,9 +782,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::withSuppressedNotice(fn() => Deprecation::notice(
+ '5.4.0',
+ 'Will be replaced with SilverStripe\View\SSTemplateEngine::execute_template()'
+ ));
$v = SSViewer::create($template);
if ($globalRequirements) {
@@ -754,10 +819,12 @@ 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)
{
- $v = SSViewer::fromString($content);
+ Deprecation::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()');
+ $v = Deprecation::withSuppressedNotice(fn() => SSViewer::fromString($content));
if ($globalRequirements) {
$v->includeRequirements(false);
@@ -781,9 +848,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::notice('5.4.0', 'Will be replaced with SilverStripe\View\SSTemplateEngine::parseTemplateContent()');
return $this->getParser()->compileString(
$content,
$template,
@@ -796,18 +865,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::notice('5.4.0', 'Will be removed without equivalent functionality to replace it');
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::notice('5.4.0', 'Will be removed without equivalent functionality to replace it');
if (!$type || $type == 'main') {
$this->chosen = $file;
} else {
@@ -822,17 +895,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::withSuppressedNotice(fn() => Deprecation::notice('5.4.0', 'Use getBaseTag() instead'));
+ // Is the document XHTML?
+ $isXhtml = preg_match('/]+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('/]+xhtml/i', $contentGeneratedSoFar ?? '')) {
+ if ($isXhtml) {
return "";
- } else {
- return "";
}
+ return "";
}
}
diff --git a/src/View/SSViewer_DataPresenter.php b/src/View/SSViewer_DataPresenter.php
index 7c5b6e5ec..a4e82cbad 100644
--- a/src/View/SSViewer_DataPresenter.php
+++ b/src/View/SSViewer_DataPresenter.php
@@ -4,6 +4,7 @@ namespace SilverStripe\View;
use InvalidArgumentException;
use SilverStripe\Core\ClassInfo;
+use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBField;
/**
@@ -11,7 +12,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
{
@@ -65,6 +66,7 @@ class SSViewer_DataPresenter extends SSViewer_Scope
array $underlay = null,
SSViewer_Scope $inheritedScope = null
) {
+ Deprecation::notice('5.4.0', 'Will be merged into ' . SSViewer_Scope::class, Deprecation::SCOPE_CLASS);
parent::__construct($item, $inheritedScope);
$this->overlay = $overlay ?: [];
diff --git a/src/View/SSViewer_FromString.php b/src/View/SSViewer_FromString.php
index 40dfed6a0..6ee92403b 100644
--- a/src/View/SSViewer_FromString.php
+++ b/src/View/SSViewer_FromString.php
@@ -3,9 +3,11 @@
namespace SilverStripe\View;
use SilverStripe\Core\Config\Config;
+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
{
@@ -37,8 +39,13 @@ class SSViewer_FromString extends SSViewer
*/
public function __construct($content, TemplateParser $parser = null)
{
+ Deprecation::notice(
+ '5.4.0',
+ 'Will be replaced with SilverStripe\View\SSTemplateEngine::renderString()',
+ Deprecation::SCOPE_CLASS
+ );
if ($parser) {
- $this->setParser($parser);
+ Deprecation::withSuppressedNotice(fn() => $this->setParser($parser));
}
$this->content = $content;
@@ -53,13 +60,17 @@ class SSViewer_FromString extends SSViewer
$cacheFile = TEMP_PATH . DIRECTORY_SEPARATOR . ".cache.$hash";
if (!file_exists($cacheFile ?? '') || isset($_GET['flush'])) {
- $content = $this->parseTemplateContent($this->content, "string sha1=$hash");
+ $content = Deprecation::withSuppressedNotice(
+ fn() => $this->parseTemplateContent($this->content, "string sha1=$hash")
+ );
$fh = fopen($cacheFile ?? '', 'w');
fwrite($fh, $content ?? '');
fclose($fh);
}
- $val = $this->includeGeneratedTemplate($cacheFile, $item, $arguments, null, $scope);
+ $val = Deprecation::withSuppressedNotice(
+ fn() => $this->includeGeneratedTemplate($cacheFile, $item, $arguments, null, $scope)
+ );
if ($this->cacheTemplate !== null) {
$cacheTemplate = $this->cacheTemplate;
diff --git a/src/View/SSViewer_Scope.php b/src/View/SSViewer_Scope.php
index 15a674477..6af57b035 100644
--- a/src/View/SSViewer_Scope.php
+++ b/src/View/SSViewer_Scope.php
@@ -5,6 +5,7 @@ namespace SilverStripe\View;
use ArrayIterator;
use Countable;
use Iterator;
+use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBBoolean;
use SilverStripe\ORM\FieldType\DBText;
use SilverStripe\ORM\FieldType\DBFloat;
@@ -123,9 +124,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);
@@ -133,6 +136,11 @@ class SSViewer_Scope
return $item;
}
+ public function getCurrentItem()
+ {
+ return Deprecation::withSuppressedNotice(fn() => $this->getItem());
+ }
+
/**
* Called at the start of every lookup chain by SSTemplateParser to indicate a new lookup from local scope
*
@@ -185,7 +193,7 @@ class SSViewer_Scope
*/
public function getObj($name, $arguments = [], $cache = false, $cacheName = null)
{
- $on = $this->getItem();
+ $on = $this->getCurrentItem();
if ($on === null) {
return null;
}
@@ -198,9 +206,13 @@ 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::withSuppressedNotice(
+ fn() => Deprecation::notice('5.4.0', 'Will be renamed scopeToIntermediateValue()')
+ );
switch ($name) {
case 'Up':
if ($this->upIndex === null) {
@@ -252,7 +264,7 @@ class SSViewer_Scope
*/
public function self()
{
- $result = $this->getItem();
+ $result = $this->getCurrentItem();
$this->resetLocalScope();
return $result;
@@ -350,8 +362,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 = Deprecation::withSuppressedNotice(fn() => $on->XML_val(...$arguments));
+ } else {
+ $retval = $on ? $on->$name(...$arguments) : null;
+ }
$this->resetLocalScope();
return $retval;
diff --git a/src/View/ThemeResourceLoader.php b/src/View/ThemeResourceLoader.php
index 8799fe13a..30f560e05 100644
--- a/src/View/ThemeResourceLoader.php
+++ b/src/View/ThemeResourceLoader.php
@@ -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//templates///.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::notice('5.4.0', 'Will be removed without equivalent functionality to replace it.');
if ($themes === null) {
$themes = SSViewer::get_themes();
}
@@ -211,7 +214,7 @@ class ThemeResourceLoader implements Flushable, TemplateGlobalProvider
foreach ($templateList as $i => $template) {
// Check if passed list of templates in array format
if (is_array($template)) {
- $path = $this->findTemplate($template, $themes);
+ $path = Deprecation::withSuppressedNotice(fn() => $this->findTemplate($template, $themes));
if ($path) {
$this->getCache()->set($cacheKey, $path);
return $path;
diff --git a/src/View/ViewableData.php b/src/View/ViewableData.php
index 080edcea8..51ed3e973 100644
--- a/src/View/ViewableData.php
+++ b/src/View/ViewableData.php
@@ -426,9 +426,11 @@ class ViewableData implements IteratorAggregate
*
* @param string $field
* @return string
+ * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
*/
public function castingClass($field)
{
+ Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it.');
// Strip arguments
$spec = $this->castingHelper($field);
return trim(strtok($spec ?? '', '(') ?? '');
@@ -439,10 +441,13 @@ class ViewableData implements IteratorAggregate
*
* @param string $field
* @return string 'xml'|'raw'
+ * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it.
*/
public function escapeTypeForField($field)
{
- $class = $this->castingClass($field) ?: $this->config()->get('default_cast');
+ Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it.');
+ $class = Deprecation::withSuppressedNotice(fn() => $this->castingClass($field))
+ ?: $this->config()->get('default_cast');
/** @var DBField $type */
$type = Injector::inst()->get($class, true);
@@ -488,9 +493,11 @@ class ViewableData implements IteratorAggregate
* @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::notice('5.4.0', 'Will be made private');
return $arguments
? $fieldName . ":" . var_export($arguments, true)
: $fieldName;
@@ -546,8 +553,11 @@ class ViewableData implements IteratorAggregate
*/
public function obj($fieldName, $arguments = [], $cache = false, $cacheName = null)
{
+ if ($cacheName !== null) {
+ Deprecation::notice('5.4.0', 'The $cacheName parameter has been deprecated and will be removed');
+ }
if (!$cacheName && $cache) {
- $cacheName = $this->objCacheName($fieldName, $arguments);
+ $cacheName = Deprecation::withSuppressedNotice(fn() => $this->objCacheName($fieldName, $arguments));
}
// Check pre-cached value
@@ -588,9 +598,11 @@ class ViewableData implements IteratorAggregate
* @param array $arguments
* @param string $identifier an optional custom cache identifier
* @return Object|DBField
+ * @deprecated 5.4.0 use obj() instead
*/
public function cachedCall($fieldName, $arguments = [], $identifier = null)
{
+ Deprecation::notice('5.4.0', 'Use obj() instead');
return $this->obj($fieldName, $arguments, true, $identifier);
}
@@ -617,9 +629,11 @@ class ViewableData implements IteratorAggregate
* @param array $arguments
* @param bool $cache
* @return string
+ * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
*/
public function XML_val($field, $arguments = [], $cache = false)
{
+ Deprecation::notice('5.4.0', 'Will be removed without equivalent functionality to replace it');
$result = $this->obj($field, $arguments, $cache);
// Might contain additional formatting over ->XML(). E.g. parse shortcodes, nl2br()
return $result->forTemplate();
@@ -630,13 +644,14 @@ class ViewableData implements IteratorAggregate
*
* @param array $fields an array of field names
* @return array
+ * @deprecated 5.4.0 Will be removed without equivalent functionality to replace it
*/
public function getXMLValues($fields)
{
$result = [];
foreach ($fields as $field) {
- $result[$field] = $this->XML_val($field);
+ $result[$field] = Deprecation::withSuppressedNotice(fn() => $this->XML_val($field));
}
return $result;
diff --git a/tests/php/Core/Manifest/ThemeResourceLoaderTest.php b/tests/php/Core/Manifest/ThemeResourceLoaderTest.php
index 0c4c424f7..c96c58af0 100644
--- a/tests/php/Core/Manifest/ThemeResourceLoaderTest.php
+++ b/tests/php/Core/Manifest/ThemeResourceLoaderTest.php
@@ -9,6 +9,7 @@ use SilverStripe\View\ThemeResourceLoader;
use SilverStripe\View\ThemeManifest;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Core\Manifest\ModuleManifest;
+use SilverStripe\Dev\Deprecation;
/**
* Tests for the {@link TemplateLoader} class.
@@ -73,41 +74,46 @@ class ThemeResourceLoaderTest extends SapphireTest
{
$this->assertEquals(
"$this->base/module/templates/Page.ss",
- $this->loader->findTemplate('Page', ['$default'])
+ Deprecation::withSuppressedNotice(fn() => $this->loader->findTemplate('Page', ['$default']))
);
$this->assertEquals(
"$this->base/module/templates/Layout/Page.ss",
- $this->loader->findTemplate(['type' => 'Layout', 'Page'], ['$default'])
+ Deprecation::withSuppressedNotice(
+ fn() => $this->loader->findTemplate(['type' => 'Layout', 'Page'], ['$default'])
+ )
);
}
public function testFindNestedThemeTemplates()
{
// Without including the theme this template cannot be found
- $this->assertEquals(null, $this->loader->findTemplate('NestedThemePage', ['$default']));
+ $this->assertEquals(
+ null,
+ Deprecation::withSuppressedNotice(fn() => $this->loader->findTemplate('NestedThemePage', ['$default']))
+ );
// With a nested theme available then it is available
$this->assertEquals(
"{$this->base}/module/themes/subtheme/templates/NestedThemePage.ss",
- $this->loader->findTemplate(
+ Deprecation::withSuppressedNotice(fn() => $this->loader->findTemplate(
'NestedThemePage',
[
'silverstripe/module:subtheme',
'$default'
]
- )
+ ))
);
// Can also be found if excluding $default theme
$this->assertEquals(
"{$this->base}/module/themes/subtheme/templates/NestedThemePage.ss",
- $this->loader->findTemplate(
+ Deprecation::withSuppressedNotice(fn() => $this->loader->findTemplate(
'NestedThemePage',
[
'silverstripe/module:subtheme',
]
- )
+ ))
);
}
@@ -116,7 +122,7 @@ class ThemeResourceLoaderTest extends SapphireTest
// Test that "type" is respected properly
$this->assertEquals(
"{$this->base}/module/templates/MyNamespace/Layout/MyClass.ss",
- $this->loader->findTemplate(
+ Deprecation::withSuppressedNotice(fn() => $this->loader->findTemplate(
[
[
'type' => 'Layout',
@@ -133,13 +139,13 @@ class ThemeResourceLoaderTest extends SapphireTest
'theme',
'$default',
]
- )
+ ))
);
// Non-typed template can be found even if looking for typed theme at a lower priority
$this->assertEquals(
"{$this->base}/module/templates/MyNamespace/MyClass.ss",
- $this->loader->findTemplate(
+ Deprecation::withSuppressedNotice(fn() => $this->loader->findTemplate(
[
[
'type' => 'Layout',
@@ -156,7 +162,7 @@ class ThemeResourceLoaderTest extends SapphireTest
'theme',
'$default',
]
- )
+ ))
);
}
@@ -165,30 +171,32 @@ class ThemeResourceLoaderTest extends SapphireTest
// Items given as full paths are returned directly
$this->assertEquals(
"$this->base/themes/theme/templates/Page.ss",
- $this->loader->findTemplate("$this->base/themes/theme/templates/Page.ss", ['theme'])
+ Deprecation::withSuppressedNotice(
+ fn() => $this->loader->findTemplate("$this->base/themes/theme/templates/Page.ss", ['theme'])
+ )
);
$this->assertEquals(
"$this->base/themes/theme/templates/Page.ss",
- $this->loader->findTemplate(
+ Deprecation::withSuppressedNotice(fn() => $this->loader->findTemplate(
[
"$this->base/themes/theme/templates/Page.ss",
"Page"
],
['theme']
- )
+ ))
);
// Ensure checks for file_exists
$this->assertEquals(
"$this->base/themes/theme/templates/Page.ss",
- $this->loader->findTemplate(
+ Deprecation::withSuppressedNotice(fn() => $this->loader->findTemplate(
[
"$this->base/themes/theme/templates/NotAPage.ss",
"$this->base/themes/theme/templates/Page.ss",
],
['theme']
- )
+ ))
);
}
@@ -199,12 +207,14 @@ class ThemeResourceLoaderTest extends SapphireTest
{
$this->assertEquals(
"$this->base/themes/theme/templates/Page.ss",
- $this->loader->findTemplate('Page', ['theme'])
+ Deprecation::withSuppressedNotice(fn() => $this->loader->findTemplate('Page', ['theme']))
);
$this->assertEquals(
"$this->base/themes/theme/templates/Layout/Page.ss",
- $this->loader->findTemplate(['type' => 'Layout', 'Page'], ['theme'])
+ Deprecation::withSuppressedNotice(
+ fn() => $this->loader->findTemplate(['type' => 'Layout', 'Page'], ['theme'])
+ )
);
}
@@ -221,12 +231,14 @@ class ThemeResourceLoaderTest extends SapphireTest
$this->assertEquals(
"$this->base/myproject/templates/Page.ss",
- $this->loader->findTemplate('Page', ['$default'])
+ Deprecation::withSuppressedNotice(fn() => $this->loader->findTemplate('Page', ['$default']))
);
$this->assertEquals(
"$this->base/myproject/templates/Layout/Page.ss",
- $this->loader->findTemplate(['type' => 'Layout', 'Page'], ['$default'])
+ Deprecation::withSuppressedNotice(
+ fn() => $this->loader->findTemplate(['type' => 'Layout', 'Page'], ['$default'])
+ )
);
$this->removeTestTemplates($templates);
@@ -239,12 +251,16 @@ class ThemeResourceLoaderTest extends SapphireTest
{
$this->assertEquals(
"$this->base/themes/theme/templates/CustomThemePage.ss",
- $this->loader->findTemplate('CustomThemePage', ['theme', '$default'])
+ Deprecation::withSuppressedNotice(
+ fn() => $this->loader->findTemplate('CustomThemePage', ['theme', '$default'])
+ )
);
$this->assertEquals(
"$this->base/module/templates/Layout/CustomThemePage.ss",
- $this->loader->findTemplate(['type' => 'Layout', 'CustomThemePage'], ['theme', '$default'])
+ Deprecation::withSuppressedNotice(
+ fn() => $this->loader->findTemplate(['type' => 'Layout', 'CustomThemePage'], ['theme', '$default'])
+ )
);
}
@@ -390,7 +406,7 @@ class ThemeResourceLoaderTest extends SapphireTest
$loader = new ThemeResourceLoader();
$loader->setCache($mockCache);
- $loader->findTemplate('Page', ['$default']);
+ Deprecation::withSuppressedNotice(fn() => $loader->findTemplate('Page', ['$default']));
}
public function testFindTemplateWithCacheHit()
@@ -402,6 +418,9 @@ class ThemeResourceLoaderTest extends SapphireTest
$loader = new ThemeResourceLoader();
$loader->setCache($mockCache);
- $this->assertSame('mock_template.ss', $loader->findTemplate('Page', ['$default']));
+ $this->assertSame(
+ 'mock_template.ss',
+ Deprecation::withSuppressedNotice(fn() => $loader->findTemplate('Page', ['$default']))
+ );
}
}
diff --git a/tests/php/View/ContentNegotiatorTest.php b/tests/php/View/ContentNegotiatorTest.php
index 7465e55fa..ec2fdf602 100644
--- a/tests/php/View/ContentNegotiatorTest.php
+++ b/tests/php/View/ContentNegotiatorTest.php
@@ -5,6 +5,7 @@ namespace SilverStripe\View\Tests;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\ContentNegotiator;
use SilverStripe\Control\HTTPResponse;
+use SilverStripe\Dev\Deprecation;
use SilverStripe\View\SSViewer;
use SilverStripe\View\Tests\SSViewerTest\TestFixture;
@@ -17,7 +18,7 @@ class ContentNegotiatorTest extends SapphireTest
*/
private function render($templateString, $data = null)
{
- $t = SSViewer::fromString($templateString);
+ $t = Deprecation::withSuppressedNotice(fn() => SSViewer::fromString($templateString));
if (!$data) {
$data = new TestFixture();
}
diff --git a/tests/php/View/SSViewerCacheBlockTest.php b/tests/php/View/SSViewerCacheBlockTest.php
index 09f334884..931ca51a4 100644
--- a/tests/php/View/SSViewerCacheBlockTest.php
+++ b/tests/php/View/SSViewerCacheBlockTest.php
@@ -9,6 +9,7 @@ use SilverStripe\Versioned\Versioned;
use Psr\SimpleCache\CacheInterface;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\Director;
+use SilverStripe\Dev\Deprecation;
use SilverStripe\View\SSTemplateParseException;
use SilverStripe\View\SSViewer;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
@@ -64,7 +65,7 @@ class SSViewerCacheBlockTest extends SapphireTest
$data = $this->data->customise($data);
}
- return SSViewer::execute_string($template, $data);
+ return Deprecation::withSuppressedNotice(fn() => SSViewer::execute_string($template, $data));
}
public function testParsing()
@@ -177,13 +178,13 @@ class SSViewerCacheBlockTest extends SapphireTest
$data->setEntropy('default');
$this->assertEquals(
'default Stage.Stage',
- SSViewer::execute_string('<% cached %>$Inspect<% end_cached %>', $data)
+ Deprecation::withSuppressedNotice(fn() => SSViewer::execute_string('<% cached %>$Inspect<% end_cached %>', $data))
);
$data = new SSViewerCacheBlockTest\VersionedModel();
$data->setEntropy('first');
$this->assertEquals(
'first Stage.Stage',
- SSViewer::execute_string('<% cached %>$Inspect<% end_cached %>', $data)
+ Deprecation::withSuppressedNotice(fn() => SSViewer::execute_string('<% cached %>$Inspect<% end_cached %>', $data))
);
// Run without caching in live to prove data is uncached
diff --git a/tests/php/View/SSViewerTest.php b/tests/php/View/SSViewerTest.php
index 3b55fa9d9..2b06e8e55 100644
--- a/tests/php/View/SSViewerTest.php
+++ b/tests/php/View/SSViewerTest.php
@@ -13,6 +13,7 @@ use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injector;
+use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\ArrayList;
@@ -196,7 +197,7 @@ class SSViewerTest extends SapphireTest
*/
public function render($templateString, $data = null, $cacheTemplate = false)
{
- $t = SSViewer::fromString($templateString, $cacheTemplate);
+ $t = Deprecation::withSuppressedNotice(fn() => SSViewer::fromString($templateString, $cacheTemplate));
if (!$data) {
$data = new SSViewerTest\TestFixture();
}
@@ -1304,29 +1305,29 @@ after'
// Value casted as "Text"
$this->assertEquals(
'<b>html</b>',
- $t = SSViewer::fromString('$TextValue')->process($vd)
+ Deprecation::withSuppressedNotice(fn() => SSViewer::fromString('$TextValue'))->process($vd)
);
$this->assertEquals(
'html',
- $t = SSViewer::fromString('$TextValue.RAW')->process($vd)
+ Deprecation::withSuppressedNotice(fn() => SSViewer::fromString('$TextValue.RAW'))->process($vd)
);
$this->assertEquals(
'<b>html</b>',
- $t = SSViewer::fromString('$TextValue.XML')->process($vd)
+ Deprecation::withSuppressedNotice(fn() => SSViewer::fromString('$TextValue.XML'))->process($vd)
);
// Value casted as "HTMLText"
$this->assertEquals(
'html',
- $t = SSViewer::fromString('$HTMLValue')->process($vd)
+ Deprecation::withSuppressedNotice(fn() => SSViewer::fromString('$HTMLValue'))->process($vd)
);
$this->assertEquals(
'html',
- $t = SSViewer::fromString('$HTMLValue.RAW')->process($vd)
+ Deprecation::withSuppressedNotice(fn() => SSViewer::fromString('$HTMLValue.RAW'))->process($vd)
);
$this->assertEquals(
'<b>html</b>',
- $t = SSViewer::fromString('$HTMLValue.XML')->process($vd)
+ Deprecation::withSuppressedNotice(fn() => SSViewer::fromString('$HTMLValue.XML'))->process($vd)
);
// Uncasted value (falls back to ViewableData::$default_cast="Text")
@@ -1334,15 +1335,15 @@ after'
$vd->UncastedValue = 'html';
$this->assertEquals(
'<b>html</b>',
- $t = SSViewer::fromString('$UncastedValue')->process($vd)
+ Deprecation::withSuppressedNotice(fn() => SSViewer::fromString('$UncastedValue'))->process($vd)
);
$this->assertEquals(
'html',
- $t = SSViewer::fromString('$UncastedValue.RAW')->process($vd)
+ Deprecation::withSuppressedNotice(fn() => SSViewer::fromString('$UncastedValue.RAW'))->process($vd)
);
$this->assertEquals(
'<b>html</b>',
- $t = SSViewer::fromString('$UncastedValue.XML')->process($vd)
+ Deprecation::withSuppressedNotice(fn() => SSViewer::fromString('$UncastedValue.XML'))->process($vd)
);
}
@@ -2039,7 +2040,9 @@ EOC;
public function testLoopIteratorIterator()
{
$list = new PaginatedList(new ArrayList());
- $viewer = new SSViewer_FromString('<% loop List %>$ID - $FirstName
<% end_loop %>');
+ $viewer = Deprecation::withSuppressedNotice(
+ fn() => new SSViewer_FromString('<% loop List %>$ID - $FirstName
<% end_loop %>')
+ );
$result = $viewer->process(new ArrayData(['List' => $list]));
$this->assertEquals($result, '');
}
@@ -2182,7 +2185,9 @@ EOC;
}
);
- $template = new SSViewer_FromString("<% test %><% end_test %>", $parser);
+ $template = Deprecation::withSuppressedNotice(
+ fn() => new SSViewer_FromString("<% test %><% end_test %>", $parser)
+ );
$template->process(new SSViewerTest\TestFixture());
$this->assertEquals(1, $count);
@@ -2199,7 +2204,7 @@ EOC;
}
);
- $template = new SSViewer_FromString("<% test %>", $parser);
+ $template = Deprecation::withSuppressedNotice(fn() => new SSViewer_FromString("<% test %>", $parser));
$template->process(new SSViewerTest\TestFixture());
$this->assertEquals(1, $count);
diff --git a/tests/php/View/ViewableDataTest.php b/tests/php/View/ViewableDataTest.php
index 15ff74252..983ea1a37 100644
--- a/tests/php/View/ViewableDataTest.php
+++ b/tests/php/View/ViewableDataTest.php
@@ -3,6 +3,7 @@
namespace SilverStripe\View\Tests;
use ReflectionMethod;
+use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\View\ArrayData;
@@ -77,12 +78,12 @@ class ViewableDataTest extends SapphireTest
{
$caster = new ViewableDataTest\Castable();
- $this->assertEquals('casted', $caster->XML_val('alwaysCasted'));
- $this->assertEquals('casted', $caster->XML_val('noCastingInformation'));
+ $this->assertEquals('casted', Deprecation::withSuppressedNotice(fn() => $caster->XML_val('alwaysCasted')));
+ $this->assertEquals('casted', Deprecation::withSuppressedNotice(fn() => $caster->XML_val('noCastingInformation')));
// Test automatic escaping is applied even to fields with no 'casting'
- $this->assertEquals('casted', $caster->XML_val('unsafeXML'));
- $this->assertEquals('<foo>', $caster->XML_val('castedUnsafeXML'));
+ $this->assertEquals('casted', Deprecation::withSuppressedNotice(fn() => $caster->XML_val('unsafeXML')));
+ $this->assertEquals('<foo>', Deprecation::withSuppressedNotice(fn() => $caster->XML_val('castedUnsafeXML')));
}
public function testArrayCustomise()
@@ -95,11 +96,11 @@ class ViewableDataTest extends SapphireTest
]
);
- $this->assertEquals('test', $viewableData->XML_val('test'));
- $this->assertEquals('casted', $viewableData->XML_val('alwaysCasted'));
+ $this->assertEquals('test', Deprecation::withSuppressedNotice(fn() => $viewableData->XML_val('test')));
+ $this->assertEquals('casted', Deprecation::withSuppressedNotice(fn() => $viewableData->XML_val('alwaysCasted')));
- $this->assertEquals('overwritten', $newViewableData->XML_val('test'));
- $this->assertEquals('overwritten', $newViewableData->XML_val('alwaysCasted'));
+ $this->assertEquals('overwritten', Deprecation::withSuppressedNotice(fn() => $newViewableData->XML_val('test')));
+ $this->assertEquals('overwritten', Deprecation::withSuppressedNotice(fn() => $newViewableData->XML_val('alwaysCasted')));
$this->assertEquals('castable', $viewableData->forTemplate());
$this->assertEquals('castable', $newViewableData->forTemplate());
@@ -110,11 +111,11 @@ class ViewableDataTest extends SapphireTest
$viewableData = new ViewableDataTest\Castable();
$newViewableData = $viewableData->customise(new ViewableDataTest\RequiresCasting());
- $this->assertEquals('test', $viewableData->XML_val('test'));
- $this->assertEquals('casted', $viewableData->XML_val('alwaysCasted'));
+ $this->assertEquals('test', Deprecation::withSuppressedNotice(fn() => $viewableData->XML_val('test')));
+ $this->assertEquals('casted', Deprecation::withSuppressedNotice(fn() => $viewableData->XML_val('alwaysCasted')));
- $this->assertEquals('overwritten', $newViewableData->XML_val('test'));
- $this->assertEquals('casted', $newViewableData->XML_val('alwaysCasted'));
+ $this->assertEquals('overwritten', Deprecation::withSuppressedNotice(fn() => $newViewableData->XML_val('test')));
+ $this->assertEquals('casted', Deprecation::withSuppressedNotice(fn() => $newViewableData->XML_val('alwaysCasted')));
$this->assertEquals('castable', $viewableData->forTemplate());
$this->assertEquals('casted', $newViewableData->forTemplate());
@@ -147,7 +148,7 @@ class ViewableDataTest extends SapphireTest
foreach ($expected as $field => $class) {
$this->assertEquals(
$class,
- $obj->castingClass($field),
+ Deprecation::withSuppressedNotice(fn() => $obj->castingClass($field)),
"castingClass() returns correct results for ::\$$field"
);
}
@@ -159,7 +160,7 @@ class ViewableDataTest extends SapphireTest
// Save a literal string into cache
$cache = true;
- $uncastedData = $obj->obj('noCastingInformation', null, false, $cache);
+ $uncastedData = $obj->obj('noCastingInformation', null, $cache);
// Fetch the cached string as an object
$forceReturnedObject = true;
@@ -184,15 +185,15 @@ class ViewableDataTest extends SapphireTest
$objCached->Test = 'AAA';
$objNotCached->Test = 'AAA';
- $this->assertEquals('AAA', $objCached->obj('Test', null, true, true));
- $this->assertEquals('AAA', $objNotCached->obj('Test', null, true, true));
+ $this->assertEquals('AAA', $objCached->obj('Test', null, true));
+ $this->assertEquals('AAA', $objNotCached->obj('Test', null, true));
$objCached->Test = 'BBB';
$objNotCached->Test = 'BBB';
// Cached data must be always the same
- $this->assertEquals('AAA', $objCached->obj('Test', null, true, true));
- $this->assertEquals('BBB', $objNotCached->obj('Test', null, true, true));
+ $this->assertEquals('AAA', $objCached->obj('Test', null, true));
+ $this->assertEquals('BBB', $objNotCached->obj('Test', null, true));
}
public function testSetFailover()
diff --git a/tests/php/i18n/i18nTestManifest.php b/tests/php/i18n/i18nTestManifest.php
index c345a2166..b81a54ae7 100644
--- a/tests/php/i18n/i18nTestManifest.php
+++ b/tests/php/i18n/i18nTestManifest.php
@@ -8,6 +8,7 @@ use SilverStripe\Core\Manifest\ClassManifest;
use SilverStripe\Core\Manifest\ClassLoader;
use SilverStripe\Core\Manifest\ModuleLoader;
use SilverStripe\Core\Manifest\ModuleManifest;
+use SilverStripe\Dev\Deprecation;
use SilverStripe\i18n\i18n;
use SilverStripe\i18n\Messages\MessageProvider;
use SilverStripe\i18n\Messages\Symfony\ModuleYamlLoader;
@@ -73,7 +74,7 @@ trait i18nTestManifest
{
// force SSViewer_DataPresenter to cache global template vars before we switch to the
// test-project class manifest (since it will lose visibility of core classes)
- $presenter = new SSViewer_DataPresenter(new ViewableData());
+ $presenter = Deprecation::withSuppressedNotice(fn() => new SSViewer_DataPresenter(new ViewableData()));
unset($presenter);
// Switch to test manifest