mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Compare commits
1 Commits
cdd5a46aeb
...
121c8737fa
Author | SHA1 | Date | |
---|---|---|---|
|
121c8737fa |
@ -36,9 +36,8 @@
|
||||
"psr/container": "^1.1 || ^2.0",
|
||||
"psr/http-message": "^1",
|
||||
"sebastian/diff": "^4.0",
|
||||
"silverstripe/config": "^2.2",
|
||||
"silverstripe/config": "^2",
|
||||
"silverstripe/assets": "^2.3",
|
||||
"silverstripe/supported-modules": "^1.1",
|
||||
"silverstripe/vendor-plugin": "^2",
|
||||
"sminnee/callbacklist": "^0.1.1",
|
||||
"symfony/cache": "^6.1",
|
||||
|
@ -19,6 +19,7 @@ use SilverStripe\View\TemplateGlobalProvider;
|
||||
*/
|
||||
class Controller extends RequestHandler implements TemplateGlobalProvider
|
||||
{
|
||||
|
||||
/**
|
||||
* An array of arguments extracted from the URL.
|
||||
*
|
||||
|
@ -3,14 +3,11 @@
|
||||
namespace SilverStripe\Dev;
|
||||
|
||||
use BadMethodCallException;
|
||||
use RuntimeException;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Core\Environment;
|
||||
use SilverStripe\Core\Injector\InjectionCreator;
|
||||
use SilverStripe\Core\Injector\InjectorLoader;
|
||||
use SilverStripe\Core\Manifest\Module;
|
||||
use SilverStripe\Core\Path;
|
||||
use SilverStripe\SupportedModules\MetaData;
|
||||
|
||||
/**
|
||||
* Handles raising an notice when accessing a deprecated method, class, configuration, or behaviour.
|
||||
@ -80,18 +77,6 @@ class Deprecation
|
||||
*/
|
||||
private static bool $showNoReplacementNotices = false;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
private static bool $showNoticesCalledFromSupportedCode = false;
|
||||
|
||||
/**
|
||||
* Cache of supported module directories, read from silverstripe/supported-modules repositories.json
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
private static array $supportedModuleDirectories = [];
|
||||
|
||||
/**
|
||||
* Enable throwing deprecation warnings. By default, this excludes warnings for
|
||||
* deprecated code which is called by core Silverstripe modules.
|
||||
@ -161,12 +146,6 @@ class Deprecation
|
||||
if (!$level) {
|
||||
$level = 1;
|
||||
}
|
||||
$called = Deprecation::get_called_from_trace($backtrace, $level);
|
||||
return ($called['class'] ?? '') . ($called['type'] ?? '') . ($called['function'] ?? '');
|
||||
}
|
||||
|
||||
private static function get_called_from_trace(array $backtrace, int $level): array
|
||||
{
|
||||
$newLevel = $level;
|
||||
// handle closures inside withSuppressedNotice()
|
||||
if (Deprecation::$insideNoticeSuppression
|
||||
@ -184,51 +163,8 @@ class Deprecation
|
||||
if ($level == 4 && ($backtrace[$newLevel]['class'] ?? '') === InjectionCreator::class) {
|
||||
$newLevel = $newLevel + 4;
|
||||
}
|
||||
// handle noticeWithNoReplacment()
|
||||
foreach ($backtrace as $trace) {
|
||||
if (($trace['class'] ?? '') === Deprecation::class
|
||||
&& ($trace['function'] ?? '') === 'noticeWithNoReplacment'
|
||||
) {
|
||||
$newLevel = $newLevel + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$called = $backtrace[$newLevel] ?? [];
|
||||
return $called;
|
||||
}
|
||||
|
||||
private static function isCalledFromSupportedCode(array $backtrace): bool
|
||||
{
|
||||
$called = Deprecation::get_called_from_trace($backtrace, 1);
|
||||
$file = $called['file'] ?? '';
|
||||
if (!$file) {
|
||||
return false;
|
||||
}
|
||||
return Deprecation::fileIsInSupportedModule($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a file (path to file) is in a supported module
|
||||
*/
|
||||
public static function fileIsInSupportedModule(string $file): bool
|
||||
{
|
||||
// Cache the supported modules list
|
||||
if (count(Deprecation::$supportedModuleDirectories) === 0) {
|
||||
// Do not make a network request when fetching metadata which could slow down a website
|
||||
// While there is a small risk of the list being out of date, there is minimal downside to this
|
||||
$metaData = MetaData::getAllRepositoryMetaData(fromRemote: false);
|
||||
$dirs = array_map(fn($module) => "/vendor/{$module['packagist']}/", $metaData['supportedModules']);
|
||||
// This is a special case for silverstripe-framework when running in CI
|
||||
// Needed because module is run in the root folder rather than in the vendor folder
|
||||
$dirs[] = '/silverstripe-framework/';
|
||||
Deprecation::$supportedModuleDirectories = $dirs;
|
||||
}
|
||||
foreach (Deprecation::$supportedModuleDirectories as $dir) {
|
||||
if (str_contains($file, $dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return ($called['class'] ?? '') . ($called['type'] ?? '') . ($called['function'] ?? '');
|
||||
}
|
||||
|
||||
public static function isEnabled(): bool
|
||||
@ -309,22 +245,6 @@ class Deprecation
|
||||
return Deprecation::$shouldShowForCli;
|
||||
}
|
||||
|
||||
/**
|
||||
* If true, deprecation warnings will be shown for deprecated code which is called by core Silverstripe modules.
|
||||
*/
|
||||
public static function getShowNoticesCalledFromSupportedCode(): bool
|
||||
{
|
||||
return Deprecation::$showNoticesCalledFromSupportedCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether deprecation warnings will be shown for deprecated code which is called by core Silverstripe modules.
|
||||
*/
|
||||
public static function setShowNoticesCalledFromSupportedCode(bool $value): void
|
||||
{
|
||||
Deprecation::$showNoticesCalledFromSupportedCode = $value;
|
||||
}
|
||||
|
||||
public static function outputNotices(): void
|
||||
{
|
||||
if (!Deprecation::isEnabled()) {
|
||||
@ -338,13 +258,9 @@ class Deprecation
|
||||
$arr = array_shift(Deprecation::$userErrorMessageBuffer);
|
||||
$message = $arr['message'];
|
||||
$calledWithNoticeSuppression = $arr['calledWithNoticeSuppression'];
|
||||
$isCalledFromSupportedCode = $arr['isCalledFromSupportedCode'];
|
||||
if ($calledWithNoticeSuppression && !Deprecation::$showNoReplacementNotices) {
|
||||
continue;
|
||||
}
|
||||
if ($isCalledFromSupportedCode && !Deprecation::$showNoticesCalledFromSupportedCode) {
|
||||
continue;
|
||||
}
|
||||
Deprecation::$isTriggeringError = true;
|
||||
user_error($message, E_USER_DEPRECATED);
|
||||
Deprecation::$isTriggeringError = false;
|
||||
@ -378,10 +294,6 @@ class Deprecation
|
||||
$data = [
|
||||
'key' => sha1($string),
|
||||
'message' => $string,
|
||||
// Setting to `false` as here as any SCOPE_CONFIG notices from supported modules have
|
||||
// already been filtered out if needed if they came from a supported module in
|
||||
// SilverStripe\Config\Transformer\YamlTransformer::checkForDeprecatedConfig()
|
||||
'isCalledFromSupportedCode' => false,
|
||||
'calledWithNoticeSuppression' => Deprecation::$insideNoticeSuppression
|
||||
];
|
||||
} else {
|
||||
@ -410,13 +322,13 @@ class Deprecation
|
||||
|
||||
$level = Deprecation::$insideNoticeSuppression ? 4 : 2;
|
||||
$string .= " Called from " . Deprecation::get_called_method_from_trace($backtrace, $level) . '.';
|
||||
|
||||
if ($caller) {
|
||||
$string = $caller . ' is deprecated.' . ($string ? ' ' . $string : '');
|
||||
}
|
||||
$data = [
|
||||
'key' => sha1($string),
|
||||
'message' => $string,
|
||||
'isCalledFromSupportedCode' => Deprecation::isCalledFromSupportedCode($backtrace),
|
||||
'calledWithNoticeSuppression' => Deprecation::$insideNoticeSuppression
|
||||
];
|
||||
}
|
||||
@ -448,23 +360,6 @@ class Deprecation
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand method to create a suppressed notice for something with no immediate replacement.
|
||||
* If $message is empty, then a standardised message will be used
|
||||
*/
|
||||
public static function noticeWithNoReplacment(
|
||||
string $atVersion,
|
||||
string $message = '',
|
||||
int $scope = Deprecation::SCOPE_METHOD
|
||||
): void {
|
||||
if ($message === '') {
|
||||
$message = 'Will be removed without equivalent functionality to replace it.';
|
||||
}
|
||||
Deprecation::withSuppressedNotice(
|
||||
fn() => Deprecation::notice($atVersion, $message, $scope)
|
||||
);
|
||||
}
|
||||
|
||||
private static function varAsBoolean($val): bool
|
||||
{
|
||||
if (is_string($val)) {
|
||||
|
@ -5,7 +5,6 @@ namespace SilverStripe\Forms\GridField;
|
||||
use SilverStripe\Core\Convert;
|
||||
use InvalidArgumentException;
|
||||
use LogicException;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\View\ViewableData;
|
||||
|
||||
/**
|
||||
@ -229,11 +228,9 @@ 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++) {
|
||||
|
@ -13,8 +13,7 @@ class DBBoolean extends DBField
|
||||
{
|
||||
public function __construct($name = null, $defaultVal = 0)
|
||||
{
|
||||
$defaultValue = $defaultVal ? 1 : 0;
|
||||
$this->setDefaultValue($defaultValue);
|
||||
$this->defaultVal = ($defaultVal) ? 1 : 0;
|
||||
|
||||
parent::__construct($name);
|
||||
}
|
||||
@ -26,7 +25,7 @@ class DBBoolean extends DBField
|
||||
'precision' => 1,
|
||||
'sign' => 'unsigned',
|
||||
'null' => 'not null',
|
||||
'default' => $this->getDefaultValue(),
|
||||
'default' => $this->defaultVal,
|
||||
'arrayValue' => $this->arrayValue
|
||||
];
|
||||
$values = ['type' => 'boolean', 'parts' => $parts];
|
||||
|
@ -122,7 +122,6 @@ abstract class DBField extends ViewableData implements DBIndexable
|
||||
* @var $default mixed Default-value in the database.
|
||||
* Might be overridden on DataObject-level, but still useful for setting defaults on
|
||||
* already existing records after a db-build.
|
||||
* @deprecated 5.4.0 Use getDefaultValue() and setDefaultValue() instead
|
||||
*/
|
||||
protected $defaultVal;
|
||||
|
||||
|
@ -13,8 +13,7 @@ class DBFloat extends DBField
|
||||
|
||||
public function __construct($name = null, $defaultVal = 0)
|
||||
{
|
||||
$defaultValue = is_float($defaultVal) ? $defaultVal : (float) 0;
|
||||
$this->setDefaultValue($defaultValue);
|
||||
$this->defaultVal = is_float($defaultVal) ? $defaultVal : (float) 0;
|
||||
|
||||
parent::__construct($name);
|
||||
}
|
||||
@ -24,7 +23,7 @@ class DBFloat extends DBField
|
||||
$parts = [
|
||||
'datatype' => 'float',
|
||||
'null' => 'not null',
|
||||
'default' => $this->getDefaultValue(),
|
||||
'default' => $this->defaultVal,
|
||||
'arrayValue' => $this->arrayValue
|
||||
];
|
||||
$values = ['type' => 'float', 'parts' => $parts];
|
||||
|
@ -15,8 +15,7 @@ class DBInt extends DBField
|
||||
|
||||
public function __construct($name = null, $defaultVal = 0)
|
||||
{
|
||||
$defaultValue = is_int($defaultVal) ? $defaultVal : 0;
|
||||
$this->setDefaultValue($defaultValue);
|
||||
$this->defaultVal = is_int($defaultVal) ? $defaultVal : 0;
|
||||
|
||||
parent::__construct($name);
|
||||
}
|
||||
@ -44,7 +43,7 @@ class DBInt extends DBField
|
||||
'datatype' => 'int',
|
||||
'precision' => 11,
|
||||
'null' => 'not null',
|
||||
'default' => $this->getDefaultValue(),
|
||||
'default' => $this->defaultVal,
|
||||
'arrayValue' => $this->arrayValue
|
||||
];
|
||||
$values = ['type' => 'int', 'parts' => $parts];
|
||||
|
@ -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->getCurrentItem(), [' .
|
||||
$res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getItem(), [' .
|
||||
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->getCurrentItem(), [' .
|
||||
$res['php'] = '$val .= \\SilverStripe\\View\\SSViewer::execute_template([["type" => "Includes", '.$template.'], '.$template.'], $scope->getItem(), [' .
|
||||
implode(',', $arguments)."], \$scope, true);\n";
|
||||
|
||||
if ($this->includeDebuggingComments) { // Add include filename comments on dev sites
|
||||
|
@ -15,7 +15,6 @@ 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.
|
||||
@ -87,7 +86,6 @@ 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';
|
||||
|
||||
@ -136,7 +134,6 @@ 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 = [];
|
||||
|
||||
@ -144,7 +141,6 @@ 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;
|
||||
|
||||
@ -152,7 +148,6 @@ 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;
|
||||
|
||||
@ -160,7 +155,6 @@ 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 = [];
|
||||
|
||||
@ -171,13 +165,11 @@ 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;
|
||||
|
||||
@ -193,7 +185,6 @@ 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);
|
||||
}
|
||||
|
||||
@ -216,11 +207,9 @@ 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);
|
||||
}
|
||||
@ -231,11 +220,9 @@ 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);
|
||||
@ -338,11 +325,9 @@ 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::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.');
|
||||
if (SSViewer::$topLevel) {
|
||||
return SSViewer::$topLevel[sizeof(SSViewer::$topLevel)-1];
|
||||
}
|
||||
@ -400,11 +385,9 @@ 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 = [];
|
||||
@ -415,11 +398,9 @@ 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());
|
||||
}
|
||||
|
||||
@ -427,11 +408,9 @@ 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;
|
||||
}
|
||||
|
||||
@ -439,11 +418,9 @@ 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'));
|
||||
}
|
||||
@ -456,11 +433,9 @@ 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());
|
||||
}
|
||||
|
||||
@ -477,11 +452,9 @@ 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;
|
||||
}
|
||||
|
||||
@ -489,11 +462,9 @@ 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());
|
||||
}
|
||||
|
||||
@ -504,11 +475,9 @@ 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())) {
|
||||
@ -527,11 +496,9 @@ 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();
|
||||
@ -545,11 +512,9 @@ 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;
|
||||
}
|
||||
|
||||
@ -557,11 +522,9 @@ 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;
|
||||
}
|
||||
@ -589,13 +552,11 @@ 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 SSViewer_Scope|null $inheritedScope The current scope of a parent template including a sub-template
|
||||
* @param ViewableData $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>";
|
||||
@ -635,9 +596,6 @@ 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();
|
||||
@ -724,11 +682,9 @@ 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];
|
||||
@ -766,14 +722,9 @@ 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) {
|
||||
@ -803,11 +754,9 @@ 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) {
|
||||
@ -832,11 +781,9 @@ 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,
|
||||
@ -849,22 +796,18 @@ 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 {
|
||||
@ -879,29 +822,17 @@ 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(), '/') . '/';
|
||||
if ($isXhtml) {
|
||||
|
||||
// Is the document XHTML?
|
||||
if (preg_match('/<!DOCTYPE[^>]+xhtml/i', $contentGeneratedSoFar ?? '')) {
|
||||
return "<base href=\"$base\" />";
|
||||
}
|
||||
} else {
|
||||
return "<base href=\"$base\"><!--[if lte IE 6]></base><![endif]-->";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ namespace SilverStripe\View;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use SilverStripe\Core\ClassInfo;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
|
||||
/**
|
||||
@ -12,7 +11,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).
|
||||
*
|
||||
* @deprecated 5.4.0 Will be merged into SilverStripe\View\SSViewer_Scope
|
||||
* It's separate from SSViewer_Scope to keep that fairly complex code as clean as possible.
|
||||
*/
|
||||
class SSViewer_DataPresenter extends SSViewer_Scope
|
||||
{
|
||||
@ -66,7 +65,6 @@ 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 ?: [];
|
||||
|
@ -3,11 +3,9 @@
|
||||
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
|
||||
{
|
||||
@ -39,11 +37,6 @@ 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);
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ 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;
|
||||
@ -124,11 +123,9 @@ 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);
|
||||
@ -136,11 +133,6 @@ 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
|
||||
*
|
||||
@ -193,7 +185,7 @@ class SSViewer_Scope
|
||||
*/
|
||||
public function getObj($name, $arguments = [], $cache = false, $cacheName = null)
|
||||
{
|
||||
$on = $this->getCurrentItem();
|
||||
$on = $this->getItem();
|
||||
if ($on === null) {
|
||||
return null;
|
||||
}
|
||||
@ -206,11 +198,9 @@ 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) {
|
||||
@ -262,7 +252,7 @@ class SSViewer_Scope
|
||||
*/
|
||||
public function self()
|
||||
{
|
||||
$result = $this->getCurrentItem();
|
||||
$result = $this->getItem();
|
||||
$this->resetLocalScope();
|
||||
|
||||
return $result;
|
||||
@ -360,12 +350,8 @@ class SSViewer_Scope
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
$on = $this->getCurrentItem();
|
||||
if ($on instanceof ViewableData && $name === 'XML_val') {
|
||||
$retval = $on->XML_val(...$arguments);
|
||||
} else {
|
||||
$on = $this->getItem();
|
||||
$retval = $on ? $on->$name(...$arguments) : null;
|
||||
}
|
||||
|
||||
$this->resetLocalScope();
|
||||
return $retval;
|
||||
|
@ -9,7 +9,6 @@ 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.
|
||||
@ -183,11 +182,9 @@ 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();
|
||||
}
|
||||
|
@ -426,11 +426,9 @@ 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::noticeWithNoReplacment('5.4.0', 'Will be removed without equivalent functionality to replace it.');
|
||||
// Strip arguments
|
||||
$spec = $this->castingHelper($field);
|
||||
return trim(strtok($spec ?? '', '(') ?? '');
|
||||
@ -441,11 +439,9 @@ 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)
|
||||
{
|
||||
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 */
|
||||
@ -492,11 +488,9 @@ 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::noticeWithNoReplacment('5.4.0', 'Will be made private');
|
||||
return $arguments
|
||||
? $fieldName . ":" . var_export($arguments, true)
|
||||
: $fieldName;
|
||||
@ -552,9 +546,6 @@ class ViewableData implements IteratorAggregate
|
||||
*/
|
||||
public function obj($fieldName, $arguments = [], $cache = false, $cacheName = null)
|
||||
{
|
||||
if ($cacheName !== null) {
|
||||
Deprecation::noticeWithNoReplacment('5.4.0', 'The $cacheName parameter has been deprecated and will be removed');
|
||||
}
|
||||
if (!$cacheName && $cache) {
|
||||
$cacheName = $this->objCacheName($fieldName, $arguments);
|
||||
}
|
||||
@ -597,11 +588,9 @@ 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);
|
||||
}
|
||||
|
||||
@ -628,11 +617,9 @@ 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::noticeWithNoReplacment('5.4.0');
|
||||
$result = $this->obj($field, $arguments, $cache);
|
||||
// Might contain additional formatting over ->XML(). E.g. parse shortcodes, nl2br()
|
||||
return $result->forTemplate();
|
||||
@ -643,11 +630,9 @@ 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)
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('5.4.0');
|
||||
$result = [];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
|
@ -23,8 +23,6 @@ class DeprecationTest extends SapphireTest
|
||||
|
||||
private bool $noticesWereEnabled = false;
|
||||
|
||||
private bool $showSupportedNoticesWasEnabled = false;
|
||||
|
||||
protected function setup(): void
|
||||
{
|
||||
// Use custom error handler for two reasons:
|
||||
@ -33,7 +31,6 @@ class DeprecationTest extends SapphireTest
|
||||
// https://github.com/laminas/laminas-di/pull/30#issuecomment-927585210
|
||||
parent::setup();
|
||||
$this->noticesWereEnabled = Deprecation::isEnabled();
|
||||
$this->showSupportedNoticesWasEnabled = Deprecation::getShowNoticesCalledFromSupportedCode();
|
||||
$this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
|
||||
if ($errno === E_USER_DEPRECATED) {
|
||||
if (str_contains($errstr, 'SilverStripe\\Dev\\Tests\\DeprecationTest')) {
|
||||
@ -49,8 +46,6 @@ class DeprecationTest extends SapphireTest
|
||||
// Fallback to default PHP error handler
|
||||
return false;
|
||||
});
|
||||
// This is required to clear out the notice from instantiating DeprecationTestObject in TableBuilder::buildTables().
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
@ -60,7 +55,6 @@ class DeprecationTest extends SapphireTest
|
||||
} else {
|
||||
Deprecation::disable();
|
||||
}
|
||||
Deprecation::setShowNoticesCalledFromSupportedCode($this->showSupportedNoticesWasEnabled);
|
||||
restore_error_handler();
|
||||
$this->oldHandler = null;
|
||||
parent::tearDown();
|
||||
@ -72,18 +66,6 @@ class DeprecationTest extends SapphireTest
|
||||
return 'abc';
|
||||
}
|
||||
|
||||
private function myDeprecatedMethodNoReplacement(): string
|
||||
{
|
||||
Deprecation::noticeWithNoReplacment('1.2.3');
|
||||
return 'abc';
|
||||
}
|
||||
|
||||
private function enableDeprecationNotices(bool $showNoReplacementNotices = false): void
|
||||
{
|
||||
Deprecation::enable($showNoReplacementNotices);
|
||||
Deprecation::setShowNoticesCalledFromSupportedCode(true);
|
||||
}
|
||||
|
||||
public function testNotice()
|
||||
{
|
||||
$message = implode(' ', [
|
||||
@ -93,7 +75,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices();
|
||||
Deprecation::enable();
|
||||
$ret = $this->myDeprecatedMethod();
|
||||
$this->assertSame('abc', $ret);
|
||||
// call outputNotices() directly because the regular shutdown function that emits
|
||||
@ -101,29 +83,6 @@ class DeprecationTest extends SapphireTest
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
|
||||
public function testNoticeNoReplacement()
|
||||
{
|
||||
$message = implode(' ', [
|
||||
'SilverStripe\Dev\Tests\DeprecationTest->myDeprecatedMethodNoReplacement is deprecated.',
|
||||
'Will be removed without equivalent functionality to replace it.',
|
||||
'Called from SilverStripe\Dev\Tests\DeprecationTest->testNoticeNoReplacement.'
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices(true);
|
||||
$ret = $this->myDeprecatedMethodNoReplacement();
|
||||
$this->assertSame('abc', $ret);
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
|
||||
public function testNoticeNoReplacementNoSupressed()
|
||||
{
|
||||
$this->enableDeprecationNotices();
|
||||
$ret = $this->myDeprecatedMethodNoReplacement();
|
||||
$this->assertSame('abc', $ret);
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
|
||||
public function testCallUserFunc()
|
||||
{
|
||||
$message = implode(' ', [
|
||||
@ -133,7 +92,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices();
|
||||
Deprecation::enable();
|
||||
$ret = call_user_func([$this, 'myDeprecatedMethod']);
|
||||
$this->assertSame('abc', $ret);
|
||||
Deprecation::outputNotices();
|
||||
@ -148,7 +107,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices();
|
||||
Deprecation::enable();
|
||||
$ret = call_user_func_array([$this, 'myDeprecatedMethod'], []);
|
||||
$this->assertSame('abc', $ret);
|
||||
Deprecation::outputNotices();
|
||||
@ -156,7 +115,7 @@ class DeprecationTest extends SapphireTest
|
||||
|
||||
public function testwithSuppressedNoticeDefault()
|
||||
{
|
||||
$this->enableDeprecationNotices();
|
||||
Deprecation::enable();
|
||||
$ret = Deprecation::withSuppressedNotice(function () {
|
||||
return $this->myDeprecatedMethod();
|
||||
});
|
||||
@ -173,7 +132,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices(true);
|
||||
Deprecation::enable(true);
|
||||
$ret = Deprecation::withSuppressedNotice(function () {
|
||||
return $this->myDeprecatedMethod();
|
||||
});
|
||||
@ -190,7 +149,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices(true);
|
||||
Deprecation::enable(true);
|
||||
$ret = Deprecation::withSuppressedNotice(function () {
|
||||
return call_user_func([$this, 'myDeprecatedMethod']);
|
||||
});
|
||||
@ -207,7 +166,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices(true);
|
||||
Deprecation::enable(true);
|
||||
Deprecation::withSuppressedNotice(function () {
|
||||
Deprecation::notice('123', 'My message.');
|
||||
});
|
||||
@ -223,7 +182,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices(true);
|
||||
Deprecation::enable(true);
|
||||
// using this syntax because my IDE was complaining about DeprecationTestObject not existing
|
||||
// when trying to use `new DeprecationTestObject();`
|
||||
$class = DeprecationTestObject::class;
|
||||
@ -240,7 +199,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices(true);
|
||||
Deprecation::enable(true);
|
||||
Injector::inst()->get(DeprecationTestObject::class);
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
@ -258,50 +217,6 @@ class DeprecationTest extends SapphireTest
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
|
||||
public function testshowNoticesCalledFromSupportedCode()
|
||||
{
|
||||
$this->expectNotToPerformAssertions();
|
||||
$this->enableDeprecationNotices(true);
|
||||
// showNoticesCalledFromSupportedCode is set to true by default for these unit tests
|
||||
// as it is testing code within vendor/silverstripe
|
||||
// This test is to ensure that the method works as expected when we disable this
|
||||
// and we should expect no exceptions to be thrown
|
||||
//
|
||||
// Note specifically NOT testing the following because it's counted as being called
|
||||
// from phpunit itself, which is not considered supported code
|
||||
// Deprecation::withSuppressedNotice(function () {
|
||||
// Deprecation::notice('123', 'My message.');
|
||||
// });
|
||||
Deprecation::setShowNoticesCalledFromSupportedCode(false);
|
||||
// notice()
|
||||
$this->myDeprecatedMethod();
|
||||
// noticeNoReplacement()
|
||||
$this->myDeprecatedMethodNoReplacement();
|
||||
// callUserFunc()
|
||||
call_user_func([$this, 'myDeprecatedMethod']);
|
||||
// callUserFuncArray()
|
||||
call_user_func_array([$this, 'myDeprecatedMethod'], []);
|
||||
// withSuppressedNotice()
|
||||
Deprecation::withSuppressedNotice(
|
||||
fn() => $this->myDeprecatedMethod()
|
||||
);
|
||||
// withSuppressedNoticeTrue()
|
||||
Deprecation::withSuppressedNotice(function () {
|
||||
$this->myDeprecatedMethod();
|
||||
});
|
||||
// withSuppressedNoticeTrueCallUserFunc()
|
||||
Deprecation::withSuppressedNotice(function () {
|
||||
call_user_func([$this, 'myDeprecatedMethod']);
|
||||
});
|
||||
// classWithSuppressedNotice()
|
||||
$class = DeprecationTestObject::class;
|
||||
new $class();
|
||||
// classWithInjectorwithSuppressedNotice()
|
||||
Injector::inst()->get(DeprecationTestObject::class);
|
||||
// Output notices - there should be none
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
|
||||
// The following tests would be better to put in the silverstripe/config module, however this is not
|
||||
// possible to do in a clean way as the config for the DeprecationTestObject will not load if it
|
||||
// is inside the silverstripe/config directory, as there is no _config.php file or _config folder.
|
||||
@ -316,7 +231,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices();
|
||||
Deprecation::enable();
|
||||
Config::inst()->get(DeprecationTestObject::class, 'first_config');
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
@ -329,7 +244,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices();
|
||||
Deprecation::enable();
|
||||
Config::inst()->get(DeprecationTestObject::class, 'second_config');
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
@ -339,7 +254,7 @@ class DeprecationTest extends SapphireTest
|
||||
$message = 'Config SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestObject.third_config is deprecated.';
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices();
|
||||
Deprecation::enable();
|
||||
Config::inst()->get(DeprecationTestObject::class, 'third_config');
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
@ -352,7 +267,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices();
|
||||
Deprecation::enable();
|
||||
Config::modify()->set(DeprecationTestObject::class, 'first_config', 'abc');
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
@ -365,7 +280,7 @@ class DeprecationTest extends SapphireTest
|
||||
]);
|
||||
$this->expectDeprecation();
|
||||
$this->expectDeprecationMessage($message);
|
||||
$this->enableDeprecationNotices();
|
||||
Deprecation::enable();
|
||||
Config::modify()->merge(DeprecationTestObject::class, 'array_config', ['abc']);
|
||||
Deprecation::outputNotices();
|
||||
}
|
||||
@ -451,7 +366,7 @@ class DeprecationTest extends SapphireTest
|
||||
switch ($varName) {
|
||||
case 'SS_DEPRECATION_ENABLED':
|
||||
if ($configVal) {
|
||||
$this->enableDeprecationNotices();
|
||||
Deprecation::enable();
|
||||
} else {
|
||||
Deprecation::disable();
|
||||
}
|
||||
@ -627,7 +542,7 @@ class DeprecationTest extends SapphireTest
|
||||
private function setEnabledViaStatic(bool $enabled): void
|
||||
{
|
||||
if ($enabled) {
|
||||
$this->enableDeprecationNotices();
|
||||
Deprecation::enable();
|
||||
} else {
|
||||
Deprecation::disable();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user