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:
Sam Minnée 2012-05-23 18:46:48 -07:00
commit c5616f8724
12 changed files with 29 additions and 10 deletions

View File

@ -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
* *

View File

@ -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');

View File

@ -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);

View File

@ -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);
} }

View File

@ -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;

View File

@ -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));

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);
} }

View File

@ -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);
} }

View File

@ -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;