silverstripe-framework/model/FieldType/SS_Datetime.php
Sam Minnee aeccb8b8e0 API: Move DBField subclasses into SilverStripe\Model\FieldType namespace
API: Deprecate SS_Datetime.

The DBField subclasses are have all been renamed to start with “DB” and
be in the SilverStripe\Model\FieldType namespace. To keep DataObject
definitions concise, the original short variations of their names are
preserved as service definitions. Most of the field generation code
doesn’t need to change, but where field classes are referenced directly,
changes will be needed.

SS_Datetime, which is commonly referenced outside the model system
itself, has been preserved as a subclass of DBDatetime. This has been
marked as deprecated and can be removed in SilverStripe 5.

A few places that referred to $db and $casting values weren’t using
the Injector to instantiate the relevant classes. This meant that the
remapping we have created as part of moving classes into a namespace
didn’t work.
2016-03-22 18:09:30 +13:00

50 lines
1.4 KiB
PHP

<?php
/**
* Backwards-compatibility class to preserve the functioning of references to SS_Datetime::now()
* @deprecated 4.0.0:5.0.0 Use SilverStripe\Model\FieldType\DBDatetime instead.
*/
class SS_Datetime extends SilverStripe\Model\FieldType\DBDatetime
{
public function __construct($name = null) {
self::deprecation_notice();
parent::__construct($name);
}
public static function now() {
self::deprecation_notice();
return parent::now();
}
/**
* Mock the system date temporarily, which is useful for time-based unit testing.
* Use {@link clear_mock_now()} to revert to the current system date.
* Caution: This sets a fixed date that doesn't increment with time.
*
* @param SS_Datetime|string $datetime Either in object format, or as a SS_Datetime compatible string.
*/
public static function set_mock_now($datetime) {
self::deprecation_notice();
return parent::set_mock_now($datetime);
}
/**
* Clear any mocked date, which causes
* {@link Now()} to return the current system date.
*/
public static function clear_mock_now() {
self::deprecation_notice();
return parent::clear_mock_now();
}
public static function get_template_global_variables() {
self::deprecation_notice();
return parent::get_template_global_variables();
}
protected static function deprecation_notice() {
Deprecation::notice('4.0', 'SS_Datetime is deprecated. Please use SilverStripe\Model\FieldType\DBDatetime instead.');
}
}