mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
API CHANGE: Don't have any instance caching in singleton(), rely on Injector for this.
This commit is contained in:
parent
f65a7c6b21
commit
114ebb6953
@ -365,15 +365,10 @@ function getClassFile($className) {
|
||||
* @return Object
|
||||
*/
|
||||
function singleton($className) {
|
||||
global $_SINGLETONS;
|
||||
if($className == "Config") user_error("Don't pass Config to singleton()", E_USER_ERROR);
|
||||
if(!isset($className)) user_error("singleton() Called without a class", E_USER_ERROR);
|
||||
if(!is_string($className)) user_error("singleton() passed bad class_name: " . var_export($className,true), E_USER_ERROR);
|
||||
if(!isset($_SINGLETONS[$className])) {
|
||||
if(!class_exists($className)) user_error("Bad class to singleton() - $className", E_USER_ERROR);
|
||||
$_SINGLETONS[$className] = Injector::inst()->get($className);
|
||||
if(!$_SINGLETONS[$className]) user_error("singleton() Unknown class '$className'", E_USER_ERROR);
|
||||
}
|
||||
return $_SINGLETONS[$className];
|
||||
return Injector::inst()->get($className);
|
||||
}
|
||||
|
||||
function project() {
|
||||
|
@ -466,6 +466,7 @@ abstract class Object {
|
||||
}
|
||||
|
||||
Config::inst()->update($class, 'extensions', array($extension));
|
||||
Injector::inst()->unregisterAllObjects();
|
||||
|
||||
// load statics now for DataObject classes
|
||||
if(is_subclass_of($class, 'DataObject')) {
|
||||
@ -496,8 +497,7 @@ abstract class Object {
|
||||
Config::inst()->remove($class, 'extensions', Config::anything(), $extension);
|
||||
|
||||
// unset singletons to avoid side-effects
|
||||
global $_SINGLETONS;
|
||||
$_SINGLETONS = array();
|
||||
Injector::inst()->unregisterAllObjects();
|
||||
|
||||
// unset some caches
|
||||
$subclasses = ClassInfo::subclassesFor($class);
|
||||
@ -541,7 +541,6 @@ abstract class Object {
|
||||
|
||||
if($extensionClasses = ClassInfo::ancestry($this->class)) foreach($extensionClasses as $class) {
|
||||
if(in_array($class, $notExtendable)) continue;
|
||||
|
||||
if($extensions = Config::inst()->get($class, 'extensions', Config::UNINHERITED)) {
|
||||
foreach($extensions as $extension) {
|
||||
// Get the extension class for this extension
|
||||
|
@ -299,8 +299,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
}
|
||||
// clear singletons, they're caching old extension info
|
||||
// which is used in DatabaseAdmin->doBuild()
|
||||
global $_SINGLETONS;
|
||||
$_SINGLETONS = array();
|
||||
Injector::inst()->unregisterAllObjects();
|
||||
|
||||
// Set default timezone consistently to avoid NZ-specific dependencies
|
||||
date_default_timezone_set('UTC');
|
||||
@ -789,9 +788,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
||||
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');
|
||||
array_shift($dataClasses);
|
||||
|
@ -123,7 +123,8 @@ class DataQuery {
|
||||
|
||||
$this->query->setFrom("\"$baseClass\"");
|
||||
|
||||
singleton($this->dataClass)->extend('augmentDataQueryCreation', $this->query, $this);
|
||||
$obj = Injector::inst()->get($baseClass);
|
||||
$obj->extend('augmentDataQueryCreation', $this->query, $this);
|
||||
}
|
||||
|
||||
function setQueriedColumns($queriedColumns) {
|
||||
@ -225,7 +226,9 @@ class DataQuery {
|
||||
$query->selectField("CASE WHEN \"$baseClass\".\"ClassName\" IS NOT NULL THEN \"$baseClass\".\"ClassName\" ELSE '$baseClass' END", "RecordClassName");
|
||||
|
||||
// TODO: Versioned, Translatable, SiteTreeSubsites, etc, could probably be better implemented as subclasses of DataQuery
|
||||
singleton($this->dataClass)->extend('augmentSQL', $query, $this);
|
||||
|
||||
$obj = Injector::inst()->get(ClassInfo::baseDataClass($this->dataClass));
|
||||
$obj->extend('augmentSQL', $query, $this);
|
||||
|
||||
$this->ensureSelectContainsOrderbyColumns($query);
|
||||
|
||||
|
@ -11,9 +11,7 @@ class ObjectTest extends SapphireTest {
|
||||
|
||||
function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
global $_SINGLETONS;
|
||||
$_SINGLETONS = array();
|
||||
Injector::inst()->unregisterAllObjects();
|
||||
}
|
||||
|
||||
function testHasmethodBehaviour() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user