mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #487 from nyeholt/injector_bugfixes
Change singleton and strong_create to use dependency injector, with additional fixes to existing classes to behave correctly
This commit is contained in:
commit
c5616f8724
@ -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
|
||||
*
|
||||
|
@ -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');
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user