Permalink
Browse files

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
  • Loading branch information...
2 parents 45465dc + 82495f5 commit c5616f87243779dc076acbcd869099dbe493298a @sminnee sminnee committed May 24, 2012
View
18 control/injector/Injector.php
@@ -642,6 +642,24 @@ public function registerNamedService($name, $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
*
* Will first check to see if the item has been registered as a configured service/bean
View
1 dev/SapphireTest.php
@@ -766,6 +766,7 @@ function resetDBSchema($includeExtraDataObjects = false) {
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');
View
2 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);
View
2 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);
}
View
2 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;
View
2 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));
View
2 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);
View
2 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);
View
2 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);
View
2 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);
}
View
2 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);
}
View
2 search/FulltextSearchable.php
@@ -68,7 +68,7 @@ static function enable($searchableClasses = array('SiteTree', 'File')) {
* @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;

0 comments on commit c5616f8

Please sign in to comment.