diff --git a/control/injector/Injector.php b/control/injector/Injector.php index 994cc2915..233c64987 100644 --- a/control/injector/Injector.php +++ b/control/injector/Injector.php @@ -641,6 +641,24 @@ class Injector { $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 * diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index d4a6205b8..7cd59395a 100644 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -766,6 +766,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase { if(self::using_temp_db()) { // clear singletons, they're caching old extension info which is used in DatabaseAdmin->doBuild() global $_SINGLETONS; + Injector::inst()->unregisterAllObjects(); $_SINGLETONS = array(); $dataClasses = ClassInfo::subclassesFor('DataObject'); diff --git a/model/fieldtypes/Boolean.php b/model/fieldtypes/Boolean.php index 195d2d457..a8e0a8ea8 100644 --- a/model/fieldtypes/Boolean.php +++ b/model/fieldtypes/Boolean.php @@ -7,7 +7,7 @@ */ class Boolean extends DBField { - function __construct($name, $defaultVal = 0) { + function __construct($name = null, $defaultVal = 0) { $this->defaultVal = ($defaultVal) ? 1 : 0; parent::__construct($name); diff --git a/model/fieldtypes/Currency.php b/model/fieldtypes/Currency.php index 3864d4e4a..9ea225990 100644 --- a/model/fieldtypes/Currency.php +++ b/model/fieldtypes/Currency.php @@ -18,7 +18,7 @@ class Currency extends Decimal { 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); } diff --git a/model/fieldtypes/Decimal.php b/model/fieldtypes/Decimal.php index 2c34b03f6..300446efd 100644 --- a/model/fieldtypes/Decimal.php +++ b/model/fieldtypes/Decimal.php @@ -10,7 +10,7 @@ class Decimal extends DBField { /** * 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->decimalSize = isset($decimalSize) ? $decimalSize : 2; $this->defaultValue = $defaultValue; diff --git a/model/fieldtypes/Enum.php b/model/fieldtypes/Enum.php index 8aec1380e..d9af908c4 100644 --- a/model/fieldtypes/Enum.php +++ b/model/fieldtypes/Enum.php @@ -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 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(!is_array($enum)){ $enum = preg_split("/ *, */", trim($enum)); diff --git a/model/fieldtypes/Float.php b/model/fieldtypes/Float.php index fca5041d5..dd7f5ca89 100644 --- a/model/fieldtypes/Float.php +++ b/model/fieldtypes/Float.php @@ -7,7 +7,7 @@ */ class Float extends DBField { - function __construct($name, $defaultVal = 0) { + function __construct($name = null, $defaultVal = 0) { $this->defaultVal = is_float($defaultVal) ? $defaultVal : (float) 0; parent::__construct($name); diff --git a/model/fieldtypes/Int.php b/model/fieldtypes/Int.php index 5de2a30dd..8e6d925d6 100644 --- a/model/fieldtypes/Int.php +++ b/model/fieldtypes/Int.php @@ -7,7 +7,7 @@ */ class Int extends DBField { - function __construct($name, $defaultVal = 0) { + function __construct($name = null, $defaultVal = 0) { $this->defaultVal = is_int($defaultVal) ? $defaultVal : 0; parent::__construct($name); diff --git a/model/fieldtypes/Percentage.php b/model/fieldtypes/Percentage.php index d58d7b7df..7ef13c1c3 100644 --- a/model/fieldtypes/Percentage.php +++ b/model/fieldtypes/Percentage.php @@ -18,7 +18,7 @@ class Percentage extends Decimal { /** * Create a new Decimal field. */ - function __construct($name, $precision = 4) { + function __construct($name = null, $precision = 4) { if(!$precision) $precision = 4; parent::__construct($name, $precision + 1, $precision); diff --git a/model/fieldtypes/PrimaryKey.php b/model/fieldtypes/PrimaryKey.php index 95f7c2920..2e4a43b8c 100644 --- a/model/fieldtypes/PrimaryKey.php +++ b/model/fieldtypes/PrimaryKey.php @@ -19,7 +19,7 @@ class PrimaryKey extends Int { * @param string $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; parent::__construct($name); } diff --git a/model/fieldtypes/Varchar.php b/model/fieldtypes/Varchar.php index d53acda23..63f7642f7 100644 --- a/model/fieldtypes/Varchar.php +++ b/model/fieldtypes/Varchar.php @@ -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 * @return unknown_type */ - function __construct($name, $size = 50, $options = array()) { + function __construct($name = null, $size = 50, $options = array()) { $this->size = $size ? $size : 50; parent::__construct($name, $options); } diff --git a/search/FulltextSearchable.php b/search/FulltextSearchable.php index 0cd900e0f..77f660fb1 100644 --- a/search/FulltextSearchable.php +++ b/search/FulltextSearchable.php @@ -68,7 +68,7 @@ class FulltextSearchable extends DataExtension { * @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. */ - function __construct($searchFields) { + function __construct($searchFields = array()) { if(is_array($searchFields)) $this->searchFields = implode(',', $searchFields); else $this->searchFields = $searchFields;