mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Versioned's constructor doesn't provide suitable defaults. Previously a bug/feature in singleton, where it would pass null,true as params to strong_create, which would then get passed through as params to Versioned's constructor, meant that the code still executed fine (as was set to something that wasn't an array, so the null and true were instead taken as args). The fact that the usage of singleton(Versioned) never really used the classes code, purely for value lookup, meant that this never propagated errors. I've now switched singleton() to use the injector for retrieving values, which means these dud values are no longer passed through
CHANGE Given that Config::inst is an implementation of the singleton pattern itself, I've removed the extra call to singleton(). A side effect of this is that it gets around a possibly nasty circular reference with the dependency injector (which relies on the config object); in future, this dependency structure should really be structured from the DI directly. MINOR Change singleton and strong_create to use dependency injector BUGFIX: Provide default constructor values for classes (fixes issues when used in 'singleton' scenario during dev/build in particular) MINOR Clear out injector state when resetting db schema during tests (a follow on from changing singleton() calls to use the injector underneath)
This commit is contained in:
parent
5eaca340b4
commit
82495f5a7e
@ -641,6 +641,24 @@ class Injector {
|
|||||||
$this->inject($service);
|
$this->inject($service);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes a named object from the cached list of objects managed
|
||||||
|
* by the inject
|
||||||
|
*
|
||||||
|
* @param type $name
|
||||||
|
* The name to unregister
|
||||||
|
*/
|
||||||
|
public function unregisterNamedObject($name) {
|
||||||
|
unset($this->serviceCache[$name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear out all objects that are managed by the injetor.
|
||||||
|
*/
|
||||||
|
public function unregisterAllObjects() {
|
||||||
|
$this->serviceCache = array();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a named managed object
|
* Get a named managed object
|
||||||
*
|
*
|
||||||
|
@ -766,6 +766,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
|||||||
if(self::using_temp_db()) {
|
if(self::using_temp_db()) {
|
||||||
// clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild()
|
// clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild()
|
||||||
global $_SINGLETONS;
|
global $_SINGLETONS;
|
||||||
|
Injector::inst()->unregisterAllObjects();
|
||||||
$_SINGLETONS = array();
|
$_SINGLETONS = array();
|
||||||
|
|
||||||
$dataClasses = ClassInfo::subclassesFor('DataObject');
|
$dataClasses = ClassInfo::subclassesFor('DataObject');
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
class Boolean extends DBField {
|
class Boolean extends DBField {
|
||||||
|
|
||||||
function __construct($name, $defaultVal = 0) {
|
function __construct($name = null, $defaultVal = 0) {
|
||||||
$this->defaultVal = ($defaultVal) ? 1 : 0;
|
$this->defaultVal = ($defaultVal) ? 1 : 0;
|
||||||
|
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
class Currency extends Decimal {
|
class Currency extends Decimal {
|
||||||
protected static $currencySymbol = '$';
|
protected static $currencySymbol = '$';
|
||||||
|
|
||||||
function __construct($name, $wholeSize = 9, $decimalSize = 2, $defaultValue = 0) {
|
function __construct($name = null, $wholeSize = 9, $decimalSize = 2, $defaultValue = 0) {
|
||||||
parent::__construct($name, $wholeSize, $decimalSize, $defaultValue);
|
parent::__construct($name, $wholeSize, $decimalSize, $defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ class Decimal extends DBField {
|
|||||||
/**
|
/**
|
||||||
* Create a new Decimal field.
|
* Create a new Decimal field.
|
||||||
*/
|
*/
|
||||||
function __construct($name, $wholeSize = 9, $decimalSize = 2, $defaultValue = 0) {
|
function __construct($name = null, $wholeSize = 9, $decimalSize = 2, $defaultValue = 0) {
|
||||||
$this->wholeSize = isset($wholeSize) ? $wholeSize : 9;
|
$this->wholeSize = isset($wholeSize) ? $wholeSize : 9;
|
||||||
$this->decimalSize = isset($decimalSize) ? $decimalSize : 2;
|
$this->decimalSize = isset($decimalSize) ? $decimalSize : 2;
|
||||||
$this->defaultValue = $defaultValue;
|
$this->defaultValue = $defaultValue;
|
||||||
|
@ -28,7 +28,7 @@ class Enum extends DBField {
|
|||||||
* @param enum: A string containing a comma separated list of options or an array of Vals.
|
* @param enum: A string containing a comma separated list of options or an array of Vals.
|
||||||
* @param default The default option, which is either NULL or one of the items in the enumeration.
|
* @param default The default option, which is either NULL or one of the items in the enumeration.
|
||||||
*/
|
*/
|
||||||
function __construct($name, $enum = NULL, $default = NULL) {
|
function __construct($name = null, $enum = NULL, $default = NULL) {
|
||||||
if($enum) {
|
if($enum) {
|
||||||
if(!is_array($enum)){
|
if(!is_array($enum)){
|
||||||
$enum = preg_split("/ *, */", trim($enum));
|
$enum = preg_split("/ *, */", trim($enum));
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
class Float extends DBField {
|
class Float extends DBField {
|
||||||
|
|
||||||
function __construct($name, $defaultVal = 0) {
|
function __construct($name = null, $defaultVal = 0) {
|
||||||
$this->defaultVal = is_float($defaultVal) ? $defaultVal : (float) 0;
|
$this->defaultVal = is_float($defaultVal) ? $defaultVal : (float) 0;
|
||||||
|
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
class Int extends DBField {
|
class Int extends DBField {
|
||||||
|
|
||||||
function __construct($name, $defaultVal = 0) {
|
function __construct($name = null, $defaultVal = 0) {
|
||||||
$this->defaultVal = is_int($defaultVal) ? $defaultVal : 0;
|
$this->defaultVal = is_int($defaultVal) ? $defaultVal : 0;
|
||||||
|
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
|
@ -18,7 +18,7 @@ class Percentage extends Decimal {
|
|||||||
/**
|
/**
|
||||||
* Create a new Decimal field.
|
* Create a new Decimal field.
|
||||||
*/
|
*/
|
||||||
function __construct($name, $precision = 4) {
|
function __construct($name = null, $precision = 4) {
|
||||||
if(!$precision) $precision = 4;
|
if(!$precision) $precision = 4;
|
||||||
|
|
||||||
parent::__construct($name, $precision + 1, $precision);
|
parent::__construct($name, $precision + 1, $precision);
|
||||||
|
@ -19,7 +19,7 @@ class PrimaryKey extends Int {
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @param DataOject $object The object that this is primary key for (should have a relation with $name)
|
* @param DataOject $object The object that this is primary key for (should have a relation with $name)
|
||||||
*/
|
*/
|
||||||
function __construct($name, $object) {
|
function __construct($name = null, $object) {
|
||||||
$this->object = $object;
|
$this->object = $object;
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ class Varchar extends StringField {
|
|||||||
* @param $options array Optional parameters, e.g. array("nullifyEmpty"=>false). See {@link StringField::setOptions()} for information on the available options
|
* @param $options array Optional parameters, e.g. array("nullifyEmpty"=>false). See {@link StringField::setOptions()} for information on the available options
|
||||||
* @return unknown_type
|
* @return unknown_type
|
||||||
*/
|
*/
|
||||||
function __construct($name, $size = 50, $options = array()) {
|
function __construct($name = null, $size = 50, $options = array()) {
|
||||||
$this->size = $size ? $size : 50;
|
$this->size = $size ? $size : 50;
|
||||||
parent::__construct($name, $options);
|
parent::__construct($name, $options);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ class FulltextSearchable extends DataExtension {
|
|||||||
* @param Array|String $searchFields Comma-separated list (or array) of database column names
|
* @param Array|String $searchFields Comma-separated list (or array) of database column names
|
||||||
* that can be searched on. Used for generation of the database index defintions.
|
* that can be searched on. Used for generation of the database index defintions.
|
||||||
*/
|
*/
|
||||||
function __construct($searchFields) {
|
function __construct($searchFields = array()) {
|
||||||
if(is_array($searchFields)) $this->searchFields = implode(',', $searchFields);
|
if(is_array($searchFields)) $this->searchFields = implode(',', $searchFields);
|
||||||
else $this->searchFields = $searchFields;
|
else $this->searchFields = $searchFields;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user