mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Compare commits
1 Commits
d18c931ecf
...
25126267af
Author | SHA1 | Date | |
---|---|---|---|
|
25126267af |
@ -39,7 +39,6 @@
|
|||||||
"sensiolabs/ansi-to-html": "^1.2",
|
"sensiolabs/ansi-to-html": "^1.2",
|
||||||
"silverstripe/config": "^3",
|
"silverstripe/config": "^3",
|
||||||
"silverstripe/assets": "^3",
|
"silverstripe/assets": "^3",
|
||||||
"silverstripe/supported-modules": "^1.1",
|
|
||||||
"silverstripe/vendor-plugin": "^2",
|
"silverstripe/vendor-plugin": "^2",
|
||||||
"sminnee/callbacklist": "^0.1.1",
|
"sminnee/callbacklist": "^0.1.1",
|
||||||
"symfony/cache": "^7.0",
|
"symfony/cache": "^7.0",
|
||||||
|
@ -22,6 +22,7 @@ use SilverStripe\View\TemplateGlobalProvider;
|
|||||||
*/
|
*/
|
||||||
class Controller extends RequestHandler implements TemplateGlobalProvider
|
class Controller extends RequestHandler implements TemplateGlobalProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of arguments extracted from the URL.
|
* An array of arguments extracted from the URL.
|
||||||
*
|
*
|
||||||
@ -640,8 +641,9 @@ class Controller extends RequestHandler implements TemplateGlobalProvider
|
|||||||
* Caution: All parameters are expected to be URI-encoded already.
|
* Caution: All parameters are expected to be URI-encoded already.
|
||||||
*
|
*
|
||||||
* @param string|array $arg One or more link segments, or list of link segments as an array
|
* @param string|array $arg One or more link segments, or list of link segments as an array
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function join_links($arg = null): string
|
public static function join_links($arg = null)
|
||||||
{
|
{
|
||||||
if (func_num_args() === 1 && is_array($arg)) {
|
if (func_num_args() === 1 && is_array($arg)) {
|
||||||
$args = $arg;
|
$args = $arg;
|
||||||
|
@ -8,11 +8,12 @@ use SilverStripe\Core\Convert;
|
|||||||
use SilverStripe\Core\Injector\Injectable;
|
use SilverStripe\Core\Injector\Injectable;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\View\Requirements;
|
use SilverStripe\View\Requirements;
|
||||||
|
use Stringable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a response returned by a controller.
|
* Represents a response returned by a controller.
|
||||||
*/
|
*/
|
||||||
class HTTPResponse
|
class HTTPResponse implements Stringable
|
||||||
{
|
{
|
||||||
use Injectable;
|
use Injectable;
|
||||||
|
|
||||||
@ -445,7 +446,7 @@ EOT
|
|||||||
/**
|
/**
|
||||||
* The HTTP response represented as a raw string
|
* The HTTP response represented as a raw string
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
$headers = [];
|
$headers = [];
|
||||||
foreach ($this->getHeaders() as $header => $values) {
|
foreach ($this->getHeaders() as $header => $values) {
|
||||||
|
@ -5,12 +5,13 @@ namespace SilverStripe\Core\Manifest;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\Core\Path;
|
use SilverStripe\Core\Path;
|
||||||
|
use Stringable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This object represents a single resource file attached to a module, and can be used
|
* This object represents a single resource file attached to a module, and can be used
|
||||||
* as a reference to this to be later turned into either a URL or file path.
|
* as a reference to this to be later turned into either a URL or file path.
|
||||||
*/
|
*/
|
||||||
class ModuleResource
|
class ModuleResource implements Stringable
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var Module
|
* @var Module
|
||||||
@ -115,7 +116,7 @@ class ModuleResource
|
|||||||
/**
|
/**
|
||||||
* Get relative path
|
* Get relative path
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return $this->getRelativePath();
|
return $this->getRelativePath();
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,11 @@
|
|||||||
namespace SilverStripe\Dev;
|
namespace SilverStripe\Dev;
|
||||||
|
|
||||||
use BadMethodCallException;
|
use BadMethodCallException;
|
||||||
use RuntimeException;
|
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Core\Environment;
|
use SilverStripe\Core\Environment;
|
||||||
use SilverStripe\Core\Injector\InjectionCreator;
|
use SilverStripe\Core\Injector\InjectionCreator;
|
||||||
use SilverStripe\Core\Injector\InjectorLoader;
|
use SilverStripe\Core\Injector\InjectorLoader;
|
||||||
use SilverStripe\Core\Manifest\Module;
|
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.
|
* Handles raising an notice when accessing a deprecated method, class, configuration, or behaviour.
|
||||||
@ -80,18 +77,6 @@ class Deprecation
|
|||||||
*/
|
*/
|
||||||
private static bool $showNoReplacementNotices = false;
|
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
|
* Enable throwing deprecation warnings. By default, this excludes warnings for
|
||||||
* deprecated code which is called by core Silverstripe modules.
|
* deprecated code which is called by core Silverstripe modules.
|
||||||
@ -161,12 +146,6 @@ class Deprecation
|
|||||||
if (!$level) {
|
if (!$level) {
|
||||||
$level = 1;
|
$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;
|
$newLevel = $level;
|
||||||
// handle closures inside withSuppressedNotice()
|
// handle closures inside withSuppressedNotice()
|
||||||
if (Deprecation::$insideNoticeSuppression
|
if (Deprecation::$insideNoticeSuppression
|
||||||
@ -184,51 +163,8 @@ class Deprecation
|
|||||||
if ($level == 4 && ($backtrace[$newLevel]['class'] ?? '') === InjectionCreator::class) {
|
if ($level == 4 && ($backtrace[$newLevel]['class'] ?? '') === InjectionCreator::class) {
|
||||||
$newLevel = $newLevel + 4;
|
$newLevel = $newLevel + 4;
|
||||||
}
|
}
|
||||||
// handle noticeWithNoReplacment()
|
|
||||||
foreach ($backtrace as $trace) {
|
|
||||||
if (($trace['class'] ?? '') === Deprecation::class
|
|
||||||
&& ($trace['function'] ?? '') === 'noticeWithNoReplacment'
|
|
||||||
) {
|
|
||||||
$newLevel = $newLevel + 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$called = $backtrace[$newLevel] ?? [];
|
$called = $backtrace[$newLevel] ?? [];
|
||||||
return $called;
|
return ($called['class'] ?? '') . ($called['type'] ?? '') . ($called['function'] ?? '');
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isEnabled(): bool
|
public static function isEnabled(): bool
|
||||||
@ -309,22 +245,6 @@ class Deprecation
|
|||||||
return Deprecation::$shouldShowForCli;
|
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
|
public static function outputNotices(): void
|
||||||
{
|
{
|
||||||
if (!Deprecation::isEnabled()) {
|
if (!Deprecation::isEnabled()) {
|
||||||
@ -338,13 +258,9 @@ class Deprecation
|
|||||||
$arr = array_shift(Deprecation::$userErrorMessageBuffer);
|
$arr = array_shift(Deprecation::$userErrorMessageBuffer);
|
||||||
$message = $arr['message'];
|
$message = $arr['message'];
|
||||||
$calledWithNoticeSuppression = $arr['calledWithNoticeSuppression'];
|
$calledWithNoticeSuppression = $arr['calledWithNoticeSuppression'];
|
||||||
$isCalledFromSupportedCode = $arr['isCalledFromSupportedCode'];
|
|
||||||
if ($calledWithNoticeSuppression && !Deprecation::$showNoReplacementNotices) {
|
if ($calledWithNoticeSuppression && !Deprecation::$showNoReplacementNotices) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($isCalledFromSupportedCode && !Deprecation::$showNoticesCalledFromSupportedCode) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Deprecation::$isTriggeringError = true;
|
Deprecation::$isTriggeringError = true;
|
||||||
user_error($message, E_USER_DEPRECATED);
|
user_error($message, E_USER_DEPRECATED);
|
||||||
Deprecation::$isTriggeringError = false;
|
Deprecation::$isTriggeringError = false;
|
||||||
@ -378,10 +294,6 @@ class Deprecation
|
|||||||
$data = [
|
$data = [
|
||||||
'key' => sha1($string),
|
'key' => sha1($string),
|
||||||
'message' => $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
|
'calledWithNoticeSuppression' => Deprecation::$insideNoticeSuppression
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
@ -410,13 +322,13 @@ class Deprecation
|
|||||||
|
|
||||||
$level = Deprecation::$insideNoticeSuppression ? 4 : 2;
|
$level = Deprecation::$insideNoticeSuppression ? 4 : 2;
|
||||||
$string .= " Called from " . Deprecation::get_called_method_from_trace($backtrace, $level) . '.';
|
$string .= " Called from " . Deprecation::get_called_method_from_trace($backtrace, $level) . '.';
|
||||||
|
|
||||||
if ($caller) {
|
if ($caller) {
|
||||||
$string = $caller . ' is deprecated.' . ($string ? ' ' . $string : '');
|
$string = $caller . ' is deprecated.' . ($string ? ' ' . $string : '');
|
||||||
}
|
}
|
||||||
$data = [
|
$data = [
|
||||||
'key' => sha1($string),
|
'key' => sha1($string),
|
||||||
'message' => $string,
|
'message' => $string,
|
||||||
'isCalledFromSupportedCode' => Deprecation::isCalledFromSupportedCode($backtrace),
|
|
||||||
'calledWithNoticeSuppression' => Deprecation::$insideNoticeSuppression
|
'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
|
private static function varAsBoolean($val): bool
|
||||||
{
|
{
|
||||||
if (is_string($val)) {
|
if (is_string($val)) {
|
||||||
|
@ -6,7 +6,6 @@ use SilverStripe\Core\Convert;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use LogicException;
|
use LogicException;
|
||||||
use SilverStripe\Model\ModelData;
|
use SilverStripe\Model\ModelData;
|
||||||
use SilverStripe\Dev\Deprecation;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see GridField
|
* @see GridField
|
||||||
|
@ -5,6 +5,7 @@ namespace SilverStripe\Forms\GridField;
|
|||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Forms\HiddenField;
|
use SilverStripe\Forms\HiddenField;
|
||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\ORM\DataList;
|
||||||
|
use Stringable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is a snapshot of the current status of a {@link GridField}.
|
* This class is a snapshot of the current status of a {@link GridField}.
|
||||||
@ -14,7 +15,7 @@ use SilverStripe\ORM\DataList;
|
|||||||
*
|
*
|
||||||
* @see GridField
|
* @see GridField
|
||||||
*/
|
*/
|
||||||
class GridState extends HiddenField
|
class GridState extends HiddenField implements Stringable
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -129,7 +130,7 @@ class GridState extends HiddenField
|
|||||||
return Convert::raw2att($this->Value());
|
return Convert::raw2att($this->Value());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return $this->Value();
|
return $this->Value();
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,15 @@
|
|||||||
|
|
||||||
namespace SilverStripe\Forms\GridField;
|
namespace SilverStripe\Forms\GridField;
|
||||||
|
|
||||||
|
use Stringable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple set of data, similar to stdClass, but without the notice-level
|
* Simple set of data, similar to stdClass, but without the notice-level
|
||||||
* errors.
|
* errors.
|
||||||
*
|
*
|
||||||
* @see GridState
|
* @see GridState
|
||||||
*/
|
*/
|
||||||
class GridState_Data
|
class GridState_Data implements Stringable
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,7 +96,7 @@ class GridState_Data
|
|||||||
unset($this->data[$name]);
|
unset($this->data[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
if (!$this->data) {
|
if (!$this->data) {
|
||||||
return "";
|
return "";
|
||||||
|
@ -18,6 +18,7 @@ use SilverStripe\ORM\FieldType\DBHTMLText;
|
|||||||
use SilverStripe\Model\ArrayData;
|
use SilverStripe\Model\ArrayData;
|
||||||
use SilverStripe\View\CastingService;
|
use SilverStripe\View\CastingService;
|
||||||
use SilverStripe\View\SSViewer;
|
use SilverStripe\View\SSViewer;
|
||||||
|
use Stringable;
|
||||||
use UnexpectedValueException;
|
use UnexpectedValueException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,7 +28,7 @@ use UnexpectedValueException;
|
|||||||
* is provided and automatically escaped by ModelData. Any class that needs to be available to a view (controllers,
|
* is provided and automatically escaped by ModelData. Any class that needs to be available to a view (controllers,
|
||||||
* {@link DataObject}s, page controls) should inherit from this class.
|
* {@link DataObject}s, page controls) should inherit from this class.
|
||||||
*/
|
*/
|
||||||
class ModelData
|
class ModelData implements Stringable
|
||||||
{
|
{
|
||||||
use Extensible {
|
use Extensible {
|
||||||
defineMethods as extensibleDefineMethods;
|
defineMethods as extensibleDefineMethods;
|
||||||
@ -305,12 +306,9 @@ class ModelData
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the class name (though subclasses may return something else)
|
|
||||||
*/
|
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return static::class;
|
return $this->forTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -550,9 +548,8 @@ class ModelData
|
|||||||
*/
|
*/
|
||||||
private function objCacheName(string $fieldName, array $arguments = []): string
|
private function objCacheName(string $fieldName, array $arguments = []): string
|
||||||
{
|
{
|
||||||
$name = empty($arguments)
|
return empty($arguments)
|
||||||
? $fieldName
|
? $fieldName
|
||||||
: $fieldName . ":" . var_export($arguments, true);
|
: $fieldName . ":" . var_export($arguments, true);
|
||||||
return md5($name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ use SilverStripe\Model\List\PaginatedList;
|
|||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\ORM\DataList;
|
||||||
use SilverStripe\Model\List\ArrayList;
|
use SilverStripe\Model\List\ArrayList;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\ORM\Queries\SQLSelect;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,7 +31,7 @@ class MySQLDatabase extends Database implements TransactionManager
|
|||||||
* @config
|
* @config
|
||||||
* @var String
|
* @var String
|
||||||
*/
|
*/
|
||||||
private static $connection_charset = 'utf8mb4';
|
private static $connection_charset = 'utf8';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default connection collation
|
* Default connection collation
|
||||||
@ -38,7 +39,7 @@ class MySQLDatabase extends Database implements TransactionManager
|
|||||||
* @config
|
* @config
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private static $connection_collation = 'utf8mb4_unicode_ci';
|
private static $connection_collation = 'utf8_general_ci';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default charset
|
* Default charset
|
||||||
@ -46,7 +47,7 @@ class MySQLDatabase extends Database implements TransactionManager
|
|||||||
* @config
|
* @config
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private static $charset = 'utf8mb4';
|
private static $charset = 'utf8';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL Mode used on connections to MySQL. Defaults to ANSI. For basic ORM
|
* SQL Mode used on connections to MySQL. Defaults to ANSI. For basic ORM
|
||||||
@ -72,7 +73,7 @@ class MySQLDatabase extends Database implements TransactionManager
|
|||||||
* @config
|
* @config
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private static $collation = 'utf8mb4_unicode_ci';
|
private static $collation = 'utf8_general_ci';
|
||||||
|
|
||||||
public function connect($parameters)
|
public function connect($parameters)
|
||||||
{
|
{
|
||||||
|
@ -15,8 +15,7 @@ class DBBoolean extends DBField
|
|||||||
{
|
{
|
||||||
public function __construct(?string $name = null, bool|int $defaultVal = 0)
|
public function __construct(?string $name = null, bool|int $defaultVal = 0)
|
||||||
{
|
{
|
||||||
$defaultValue = $defaultVal ? 1 : 0;
|
$this->defaultVal = ($defaultVal) ? 1 : 0;
|
||||||
$this->setDefaultValue($defaultValue);
|
|
||||||
|
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
}
|
}
|
||||||
@ -28,7 +27,7 @@ class DBBoolean extends DBField
|
|||||||
'precision' => 1,
|
'precision' => 1,
|
||||||
'sign' => 'unsigned',
|
'sign' => 'unsigned',
|
||||||
'null' => 'not null',
|
'null' => 'not null',
|
||||||
'default' => $this->getDefaultValue(),
|
'default' => $this->defaultVal,
|
||||||
'arrayValue' => $this->arrayValue
|
'arrayValue' => $this->arrayValue
|
||||||
];
|
];
|
||||||
$values = ['type' => 'boolean', 'parts' => $parts];
|
$values = ['type' => 'boolean', 'parts' => $parts];
|
||||||
|
@ -103,7 +103,6 @@ abstract class DBField extends ModelData implements DBIndexable
|
|||||||
* Default value in the database.
|
* Default value in the database.
|
||||||
* Might be overridden on DataObject-level, but still useful for setting defaults on
|
* Might be overridden on DataObject-level, but still useful for setting defaults on
|
||||||
* already existing records after a db-build.
|
* already existing records after a db-build.
|
||||||
* @deprecated 5.4.0 Use getDefaultValue() and setDefaultValue() instead
|
|
||||||
*/
|
*/
|
||||||
protected mixed $defaultVal = null;
|
protected mixed $defaultVal = null;
|
||||||
|
|
||||||
@ -521,11 +520,6 @@ abstract class DBField extends ModelData implements DBIndexable
|
|||||||
DBG;
|
DBG;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString(): string
|
|
||||||
{
|
|
||||||
return (string)$this->forTemplate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getArrayValue()
|
public function getArrayValue()
|
||||||
{
|
{
|
||||||
return $this->arrayValue;
|
return $this->arrayValue;
|
||||||
|
@ -13,8 +13,7 @@ class DBFloat extends DBField
|
|||||||
{
|
{
|
||||||
public function __construct(?string $name = null, float|int $defaultVal = 0)
|
public function __construct(?string $name = null, float|int $defaultVal = 0)
|
||||||
{
|
{
|
||||||
$defaultValue = is_float($defaultVal) ? $defaultVal : (float) 0;
|
$this->defaultVal = is_float($defaultVal) ? $defaultVal : (float) 0;
|
||||||
$this->setDefaultValue($defaultValue);
|
|
||||||
|
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
}
|
}
|
||||||
@ -24,7 +23,7 @@ class DBFloat extends DBField
|
|||||||
$parts = [
|
$parts = [
|
||||||
'datatype' => 'float',
|
'datatype' => 'float',
|
||||||
'null' => 'not null',
|
'null' => 'not null',
|
||||||
'default' => $this->getDefaultValue(),
|
'default' => $this->defaultVal,
|
||||||
'arrayValue' => $this->arrayValue
|
'arrayValue' => $this->arrayValue
|
||||||
];
|
];
|
||||||
$values = ['type' => 'float', 'parts' => $parts];
|
$values = ['type' => 'float', 'parts' => $parts];
|
||||||
|
@ -16,8 +16,7 @@ class DBInt extends DBField
|
|||||||
{
|
{
|
||||||
public function __construct(?string $name = null, int $defaultVal = 0)
|
public function __construct(?string $name = null, int $defaultVal = 0)
|
||||||
{
|
{
|
||||||
$defaultValue = is_int($defaultVal) ? $defaultVal : 0;
|
$this->defaultVal = is_int($defaultVal) ? $defaultVal : 0;
|
||||||
$this->setDefaultValue($defaultValue);
|
|
||||||
|
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
}
|
}
|
||||||
@ -45,7 +44,7 @@ class DBInt extends DBField
|
|||||||
'datatype' => 'int',
|
'datatype' => 'int',
|
||||||
'precision' => 11,
|
'precision' => 11,
|
||||||
'null' => 'not null',
|
'null' => 'not null',
|
||||||
'default' => $this->getDefaultValue(),
|
'default' => $this->defaultVal,
|
||||||
'arrayValue' => $this->arrayValue
|
'arrayValue' => $this->arrayValue
|
||||||
];
|
];
|
||||||
$values = ['type' => 'int', 'parts' => $parts];
|
$values = ['type' => 'int', 'parts' => $parts];
|
||||||
|
@ -6,12 +6,13 @@ use SilverStripe\Core\Convert;
|
|||||||
use SilverStripe\ORM\Connect\Query;
|
use SilverStripe\ORM\Connect\Query;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Stringable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for an object representing an SQL query.
|
* Abstract base class for an object representing an SQL query.
|
||||||
* The various parts of the SQL query can be manipulated individually.
|
* The various parts of the SQL query can be manipulated individually.
|
||||||
*/
|
*/
|
||||||
abstract class SQLExpression
|
abstract class SQLExpression implements Stringable
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +46,7 @@ abstract class SQLExpression
|
|||||||
/**
|
/**
|
||||||
* Return the generated SQL string for this query
|
* Return the generated SQL string for this query
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$sql = $this->sql($parameters);
|
$sql = $this->sql($parameters);
|
||||||
|
@ -21,33 +21,33 @@ class CastingService
|
|||||||
/**
|
/**
|
||||||
* Cast a value to the relevant object (usually a DBField instance) for use in the view layer.
|
* Cast a value to the relevant object (usually a DBField instance) for use in the view layer.
|
||||||
*
|
*
|
||||||
* @param ModelData|array|null $source Where the data originates from. This is used both to check for casting helpers
|
* @param null|array|ModelData $source Where the data originates from. This is used both to check for casting helpers
|
||||||
* and to help set the value in cast DBField instances.
|
* and to help set the value in cast DBField instances.
|
||||||
* @param bool $strict If true, an object will be returned even if $data is null.
|
* @param bool $strict If true, an object will be returned even if $data is null.
|
||||||
*/
|
*/
|
||||||
public function cast(mixed $data, ModelData|array|null $source = null, string $fieldName = '', bool $strict = false): ?object
|
public function cast(mixed $data, null|array|ModelData $source = null, string $fieldName = '', bool $strict = false): ?object
|
||||||
{
|
{
|
||||||
// Assume anything that's an object is intentionally using whatever class it's using
|
|
||||||
// and don't cast it.
|
|
||||||
if (is_object($data)) {
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// null is null - we shouldn't cast it to an object, because that makes it harder
|
// null is null - we shouldn't cast it to an object, because that makes it harder
|
||||||
// for downstream checks to know there's "no value".
|
// for downstream checks to know there's "no value".
|
||||||
if (!$strict && $data === null) {
|
if (!$strict && $data === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$serviceKey = null;
|
// Assume anything that's an object is intentionally using whatever class it's using
|
||||||
|
// and don't cast it.
|
||||||
|
if (is_object($data)) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
$service = null;
|
||||||
if ($source instanceof ModelData) {
|
if ($source instanceof ModelData) {
|
||||||
$serviceKey = $source->castingHelper($fieldName);
|
$service = $source->castingHelper($fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cast to object if there's an explicit casting for this field
|
// Cast to object if there's an explicit casting for this field
|
||||||
// Explicit casts take precedence over array casting
|
// Explicit casts take precedence over array casting
|
||||||
if ($serviceKey) {
|
if ($service) {
|
||||||
$castObject = Injector::inst()->create($serviceKey, $fieldName);
|
$castObject = Injector::inst()->create($service, $fieldName);
|
||||||
if (!ClassInfo::hasMethod($castObject, 'setValue')) {
|
if (!ClassInfo::hasMethod($castObject, 'setValue')) {
|
||||||
throw new LogicException('Explicit casting service must have a setValue method.');
|
throw new LogicException('Explicit casting service must have a setValue method.');
|
||||||
}
|
}
|
||||||
@ -61,8 +61,8 @@ class CastingService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fall back to default casting
|
// Fall back to default casting
|
||||||
$serviceKey = $this->getDefaultServiceKey($data, $source, $fieldName);
|
$service = $this->defaultService($data, $source, $fieldName);
|
||||||
$castObject = Injector::inst()->create($serviceKey, $fieldName);
|
$castObject = Injector::inst()->create($service, $fieldName);
|
||||||
if (!ClassInfo::hasMethod($castObject, 'setValue')) {
|
if (!ClassInfo::hasMethod($castObject, 'setValue')) {
|
||||||
throw new LogicException('Default service must have a setValue method.');
|
throw new LogicException('Default service must have a setValue method.');
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ class CastingService
|
|||||||
/**
|
/**
|
||||||
* Get the default service to use if no explicit service is declared for this field on the source model.
|
* Get the default service to use if no explicit service is declared for this field on the source model.
|
||||||
*/
|
*/
|
||||||
private function getDefaultServiceKey(mixed $data, mixed $source = null, string $fieldName = ''): ?string
|
private function defaultService(mixed $data, mixed $source = null, string $fieldName = ''): ?string
|
||||||
{
|
{
|
||||||
$default = null;
|
$default = null;
|
||||||
if ($source instanceof ModelData) {
|
if ($source instanceof ModelData) {
|
||||||
@ -81,7 +81,7 @@ class CastingService
|
|||||||
if ($default === null) {
|
if ($default === null) {
|
||||||
$failover = $source->getFailover();
|
$failover = $source->getFailover();
|
||||||
if ($failover) {
|
if ($failover) {
|
||||||
$default = $this->getDefaultServiceKey($data, $failover, $fieldName);
|
$default = $this->defaultService($data, $failover, $fieldName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1189,7 +1189,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
|||||||
$matchrule = "QuotedString"; $result = $this->construct($matchrule, $matchrule, null);
|
$matchrule = "QuotedString"; $result = $this->construct($matchrule, $matchrule, null);
|
||||||
$_154 = NULL;
|
$_154 = NULL;
|
||||||
do {
|
do {
|
||||||
$stack[] = $result; $result = $this->construct( $matchrule, "q" );
|
$stack[] = $result; $result = $this->construct( $matchrule, "q" );
|
||||||
if (( $subres = $this->rx( '/[\'"]/' ) ) !== FALSE) {
|
if (( $subres = $this->rx( '/[\'"]/' ) ) !== FALSE) {
|
||||||
$result["text"] .= $subres;
|
$result["text"] .= $subres;
|
||||||
$subres = $result; $result = array_pop($stack);
|
$subres = $result; $result = array_pop($stack);
|
||||||
@ -1199,7 +1199,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
|||||||
$result = array_pop($stack);
|
$result = array_pop($stack);
|
||||||
$_154 = FALSE; break;
|
$_154 = FALSE; break;
|
||||||
}
|
}
|
||||||
$stack[] = $result; $result = $this->construct( $matchrule, "String" );
|
$stack[] = $result; $result = $this->construct( $matchrule, "String" );
|
||||||
if (( $subres = $this->rx( '/ (\\\\\\\\ | \\\\. | [^'.$this->expression($result, $stack, 'q').'\\\\])* /' ) ) !== FALSE) {
|
if (( $subres = $this->rx( '/ (\\\\\\\\ | \\\\. | [^'.$this->expression($result, $stack, 'q').'\\\\])* /' ) ) !== FALSE) {
|
||||||
$result["text"] .= $subres;
|
$result["text"] .= $subres;
|
||||||
$subres = $result; $result = array_pop($stack);
|
$subres = $result; $result = array_pop($stack);
|
||||||
@ -1842,7 +1842,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
|||||||
$pos_255 = $this->pos;
|
$pos_255 = $this->pos;
|
||||||
$_254 = NULL;
|
$_254 = NULL;
|
||||||
do {
|
do {
|
||||||
$stack[] = $result; $result = $this->construct( $matchrule, "Not" );
|
$stack[] = $result; $result = $this->construct( $matchrule, "Not" );
|
||||||
if (( $subres = $this->literal( 'not' ) ) !== FALSE) {
|
if (( $subres = $this->literal( 'not' ) ) !== FALSE) {
|
||||||
$result["text"] .= $subres;
|
$result["text"] .= $subres;
|
||||||
$subres = $result; $result = array_pop($stack);
|
$subres = $result; $result = array_pop($stack);
|
||||||
@ -2235,7 +2235,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
|||||||
else { $_330 = FALSE; break; }
|
else { $_330 = FALSE; break; }
|
||||||
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
||||||
else { $_330 = FALSE; break; }
|
else { $_330 = FALSE; break; }
|
||||||
$stack[] = $result; $result = $this->construct( $matchrule, "Call" );
|
$stack[] = $result; $result = $this->construct( $matchrule, "Call" );
|
||||||
$_326 = NULL;
|
$_326 = NULL;
|
||||||
do {
|
do {
|
||||||
$matcher = 'match_'.'Word'; $key = $matcher; $pos = $this->pos;
|
$matcher = 'match_'.'Word'; $key = $matcher; $pos = $this->pos;
|
||||||
@ -2740,7 +2740,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
|||||||
$_423 = NULL;
|
$_423 = NULL;
|
||||||
do {
|
do {
|
||||||
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
||||||
$stack[] = $result; $result = $this->construct( $matchrule, "Conditional" );
|
$stack[] = $result; $result = $this->construct( $matchrule, "Conditional" );
|
||||||
$_419 = NULL;
|
$_419 = NULL;
|
||||||
do {
|
do {
|
||||||
$_417 = NULL;
|
$_417 = NULL;
|
||||||
@ -3166,7 +3166,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
|||||||
if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
|
if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
|
||||||
else { $_555 = FALSE; break; }
|
else { $_555 = FALSE; break; }
|
||||||
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
||||||
$stack[] = $result; $result = $this->construct( $matchrule, "CacheTag" );
|
$stack[] = $result; $result = $this->construct( $matchrule, "CacheTag" );
|
||||||
$_508 = NULL;
|
$_508 = NULL;
|
||||||
do {
|
do {
|
||||||
$_506 = NULL;
|
$_506 = NULL;
|
||||||
@ -3225,7 +3225,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
|||||||
$_524 = NULL;
|
$_524 = NULL;
|
||||||
do {
|
do {
|
||||||
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
||||||
$stack[] = $result; $result = $this->construct( $matchrule, "Conditional" );
|
$stack[] = $result; $result = $this->construct( $matchrule, "Conditional" );
|
||||||
$_520 = NULL;
|
$_520 = NULL;
|
||||||
do {
|
do {
|
||||||
$_518 = NULL;
|
$_518 = NULL;
|
||||||
@ -4165,7 +4165,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
|||||||
unset( $pos_685 );
|
unset( $pos_685 );
|
||||||
}
|
}
|
||||||
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
||||||
$stack[] = $result; $result = $this->construct( $matchrule, "Zap" );
|
$stack[] = $result; $result = $this->construct( $matchrule, "Zap" );
|
||||||
if (( $subres = $this->literal( '%>' ) ) !== FALSE) {
|
if (( $subres = $this->literal( '%>' ) ) !== FALSE) {
|
||||||
$result["text"] .= $subres;
|
$result["text"] .= $subres;
|
||||||
$subres = $result; $result = array_pop($stack);
|
$subres = $result; $result = array_pop($stack);
|
||||||
@ -4556,7 +4556,7 @@ class SSTemplateParser extends Parser implements TemplateParser
|
|||||||
if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
|
if (( $subres = $this->literal( '<%' ) ) !== FALSE) { $result["text"] .= $subres; }
|
||||||
else { $_743 = FALSE; break; }
|
else { $_743 = FALSE; break; }
|
||||||
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
if (( $subres = $this->whitespace( ) ) !== FALSE) { $result["text"] .= $subres; }
|
||||||
$stack[] = $result; $result = $this->construct( $matchrule, "Tag" );
|
$stack[] = $result; $result = $this->construct( $matchrule, "Tag" );
|
||||||
$_737 = NULL;
|
$_737 = NULL;
|
||||||
do {
|
do {
|
||||||
if (( $subres = $this->literal( 'end_' ) ) !== FALSE) { $result["text"] .= $subres; }
|
if (( $subres = $this->literal( 'end_' ) ) !== FALSE) { $result["text"] .= $subres; }
|
||||||
|
@ -372,8 +372,9 @@ PHP;
|
|||||||
|
|
||||||
if ($isXhtml) {
|
if ($isXhtml) {
|
||||||
return "<base href=\"$base\" />";
|
return "<base href=\"$base\" />";
|
||||||
|
} else {
|
||||||
|
return "<base href=\"$base\">";
|
||||||
}
|
}
|
||||||
return "<base href=\"$base\">";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,7 +9,6 @@ use SilverStripe\Core\Injector\Injector;
|
|||||||
use SilverStripe\Core\Manifest\ModuleLoader;
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||||
use SilverStripe\Core\Manifest\ModuleResourceLoader;
|
use SilverStripe\Core\Manifest\ModuleResourceLoader;
|
||||||
use SilverStripe\Core\Path;
|
use SilverStripe\Core\Path;
|
||||||
use SilverStripe\Dev\Deprecation;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles finding templates from a stack of template manifest objects.
|
* Handles finding templates from a stack of template manifest objects.
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace SilverStripe\i18n\Messages\Symfony;
|
namespace SilverStripe\i18n\Messages\Symfony;
|
||||||
|
|
||||||
use SilverStripe\Core\Flushable;
|
use SilverStripe\Core\Flushable;
|
||||||
|
use Stringable;
|
||||||
use Symfony\Component\Config\Resource\SelfCheckingResourceInterface;
|
use Symfony\Component\Config\Resource\SelfCheckingResourceInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,9 +13,9 @@ use Symfony\Component\Config\Resource\SelfCheckingResourceInterface;
|
|||||||
* @link https://media.giphy.com/media/fRRD3T37DeY6Y/giphy.gif for use case
|
* @link https://media.giphy.com/media/fRRD3T37DeY6Y/giphy.gif for use case
|
||||||
* @see DirectoryResource
|
* @see DirectoryResource
|
||||||
*/
|
*/
|
||||||
class FlushInvalidatedResource implements SelfCheckingResourceInterface, Flushable
|
class FlushInvalidatedResource implements SelfCheckingResourceInterface, Flushable, Stringable
|
||||||
{
|
{
|
||||||
public function __toString()
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
return md5(__CLASS__);
|
return md5(__CLASS__);
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
|
|
||||||
private bool $noticesWereEnabled = false;
|
private bool $noticesWereEnabled = false;
|
||||||
|
|
||||||
private bool $showSupportedNoticesWasEnabled = false;
|
|
||||||
|
|
||||||
protected function setup(): void
|
protected function setup(): void
|
||||||
{
|
{
|
||||||
// Use custom error handler for two reasons:
|
// Use custom error handler for two reasons:
|
||||||
@ -36,7 +34,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
// https://github.com/laminas/laminas-di/pull/30#issuecomment-927585210
|
// https://github.com/laminas/laminas-di/pull/30#issuecomment-927585210
|
||||||
parent::setup();
|
parent::setup();
|
||||||
$this->noticesWereEnabled = Deprecation::isEnabled();
|
$this->noticesWereEnabled = Deprecation::isEnabled();
|
||||||
$this->showSupportedNoticesWasEnabled = Deprecation::getShowNoticesCalledFromSupportedCode();
|
|
||||||
$this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
|
$this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
|
||||||
if ($errno === E_USER_DEPRECATED) {
|
if ($errno === E_USER_DEPRECATED) {
|
||||||
if (str_contains($errstr, 'SilverStripe\\Dev\\Tests\\DeprecationTest')) {
|
if (str_contains($errstr, 'SilverStripe\\Dev\\Tests\\DeprecationTest')) {
|
||||||
@ -52,8 +49,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
// Fallback to default PHP error handler
|
// Fallback to default PHP error handler
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
// This is required to clear out the notice from instantiating DeprecationTestObject in TableBuilder::buildTables().
|
|
||||||
Deprecation::outputNotices();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
@ -63,7 +58,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
} else {
|
} else {
|
||||||
Deprecation::disable();
|
Deprecation::disable();
|
||||||
}
|
}
|
||||||
Deprecation::setShowNoticesCalledFromSupportedCode($this->showSupportedNoticesWasEnabled);
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
$this->oldHandler = null;
|
$this->oldHandler = null;
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
@ -75,18 +69,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
return 'abc';
|
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()
|
public function testNotice()
|
||||||
{
|
{
|
||||||
$message = implode(' ', [
|
$message = implode(' ', [
|
||||||
@ -96,7 +78,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
$ret = $this->myDeprecatedMethod();
|
$ret = $this->myDeprecatedMethod();
|
||||||
$this->assertSame('abc', $ret);
|
$this->assertSame('abc', $ret);
|
||||||
// call outputNotices() directly because the regular shutdown function that emits
|
// call outputNotices() directly because the regular shutdown function that emits
|
||||||
@ -104,29 +86,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
Deprecation::outputNotices();
|
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()
|
public function testCallUserFunc()
|
||||||
{
|
{
|
||||||
$message = implode(' ', [
|
$message = implode(' ', [
|
||||||
@ -136,7 +95,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
$ret = call_user_func([$this, 'myDeprecatedMethod']);
|
$ret = call_user_func([$this, 'myDeprecatedMethod']);
|
||||||
$this->assertSame('abc', $ret);
|
$this->assertSame('abc', $ret);
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
@ -151,7 +110,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
$ret = call_user_func_array([$this, 'myDeprecatedMethod'], []);
|
$ret = call_user_func_array([$this, 'myDeprecatedMethod'], []);
|
||||||
$this->assertSame('abc', $ret);
|
$this->assertSame('abc', $ret);
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
@ -159,7 +118,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
|
|
||||||
public function testwithSuppressedNoticeDefault()
|
public function testwithSuppressedNoticeDefault()
|
||||||
{
|
{
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
$ret = Deprecation::withSuppressedNotice(function () {
|
$ret = Deprecation::withSuppressedNotice(function () {
|
||||||
return $this->myDeprecatedMethod();
|
return $this->myDeprecatedMethod();
|
||||||
});
|
});
|
||||||
@ -176,7 +135,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices(true);
|
Deprecation::enable(true);
|
||||||
$ret = Deprecation::withSuppressedNotice(function () {
|
$ret = Deprecation::withSuppressedNotice(function () {
|
||||||
return $this->myDeprecatedMethod();
|
return $this->myDeprecatedMethod();
|
||||||
});
|
});
|
||||||
@ -193,7 +152,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices(true);
|
Deprecation::enable(true);
|
||||||
$ret = Deprecation::withSuppressedNotice(function () {
|
$ret = Deprecation::withSuppressedNotice(function () {
|
||||||
return call_user_func([$this, 'myDeprecatedMethod']);
|
return call_user_func([$this, 'myDeprecatedMethod']);
|
||||||
});
|
});
|
||||||
@ -210,7 +169,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices(true);
|
Deprecation::enable(true);
|
||||||
Deprecation::withSuppressedNotice(function () {
|
Deprecation::withSuppressedNotice(function () {
|
||||||
Deprecation::notice('123', 'My message.');
|
Deprecation::notice('123', 'My message.');
|
||||||
});
|
});
|
||||||
@ -226,7 +185,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices(true);
|
Deprecation::enable(true);
|
||||||
// using this syntax because my IDE was complaining about DeprecationTestObject not existing
|
// using this syntax because my IDE was complaining about DeprecationTestObject not existing
|
||||||
// when trying to use `new DeprecationTestObject();`
|
// when trying to use `new DeprecationTestObject();`
|
||||||
$class = DeprecationTestObject::class;
|
$class = DeprecationTestObject::class;
|
||||||
@ -243,7 +202,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices(true);
|
Deprecation::enable(true);
|
||||||
Injector::inst()->get(DeprecationTestObject::class);
|
Injector::inst()->get(DeprecationTestObject::class);
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -259,50 +218,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
Deprecation::outputNotices();
|
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
|
// 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
|
// 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.
|
// is inside the silverstripe/config directory, as there is no _config.php file or _config folder.
|
||||||
@ -317,7 +232,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
Config::inst()->get(DeprecationTestObject::class, 'first_config');
|
Config::inst()->get(DeprecationTestObject::class, 'first_config');
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -330,7 +245,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
Config::inst()->get(DeprecationTestObject::class, 'second_config');
|
Config::inst()->get(DeprecationTestObject::class, 'second_config');
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -340,7 +255,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
$message = 'Config SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestObject.third_config is deprecated.';
|
$message = 'Config SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestObject.third_config is deprecated.';
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
Config::inst()->get(DeprecationTestObject::class, 'third_config');
|
Config::inst()->get(DeprecationTestObject::class, 'third_config');
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -353,7 +268,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
Config::modify()->set(DeprecationTestObject::class, 'first_config', 'abc');
|
Config::modify()->set(DeprecationTestObject::class, 'first_config', 'abc');
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -366,7 +281,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectException(DeprecationTestException::class);
|
$this->expectException(DeprecationTestException::class);
|
||||||
$this->expectExceptionMessage($message);
|
$this->expectExceptionMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
Config::modify()->merge(DeprecationTestObject::class, 'array_config', ['abc']);
|
Config::modify()->merge(DeprecationTestObject::class, 'array_config', ['abc']);
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -446,7 +361,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
switch ($varName) {
|
switch ($varName) {
|
||||||
case 'SS_DEPRECATION_ENABLED':
|
case 'SS_DEPRECATION_ENABLED':
|
||||||
if ($configVal) {
|
if ($configVal) {
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
} else {
|
} else {
|
||||||
Deprecation::disable();
|
Deprecation::disable();
|
||||||
}
|
}
|
||||||
@ -618,7 +533,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
private function setEnabledViaStatic(bool $enabled): void
|
private function setEnabledViaStatic(bool $enabled): void
|
||||||
{
|
{
|
||||||
if ($enabled) {
|
if ($enabled) {
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
} else {
|
} else {
|
||||||
Deprecation::disable();
|
Deprecation::disable();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user