mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE: Extension no longer inherits from Object.
ENHANCEMENT: Object::__construct() performance improved slightly. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84160 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
81eeef25e8
commit
d8113a667e
@ -11,7 +11,7 @@
|
|||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage core
|
* @subpackage core
|
||||||
*/
|
*/
|
||||||
abstract class Extension extends Object {
|
abstract class Extension {
|
||||||
/**
|
/**
|
||||||
* This is used by extensions designed to be applied to controllers.
|
* This is used by extensions designed to be applied to controllers.
|
||||||
* It works the same way as {@link Controller::$allowed_actions}.
|
* It works the same way as {@link Controller::$allowed_actions}.
|
||||||
@ -36,6 +36,12 @@ abstract class Extension extends Object {
|
|||||||
*/
|
*/
|
||||||
private $ownerRefs = 0;
|
private $ownerRefs = 0;
|
||||||
|
|
||||||
|
public $class;
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
$this->class = get_class($this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the owner of this decorator.
|
* Set the owner of this decorator.
|
||||||
* @param Object $owner The owner object,
|
* @param Object $owner The owner object,
|
||||||
|
@ -506,8 +506,14 @@ abstract class Object {
|
|||||||
// Don't do magic methods and/or extensions on extensions themselves.
|
// Don't do magic methods and/or extensions on extensions themselves.
|
||||||
if($this instanceof Extension) return;
|
if($this instanceof Extension) return;
|
||||||
|
|
||||||
|
// Don't bother checking some classes that should never be extended
|
||||||
|
static $notExtendable = array('Object', 'ViewableData', 'DataObject', 'RequestHandler');
|
||||||
|
|
||||||
if($extensionClasses = ClassInfo::ancestry($this->class)) foreach($extensionClasses as $class) {
|
if($extensionClasses = ClassInfo::ancestry($this->class)) foreach($extensionClasses as $class) {
|
||||||
if($extensions = self::uninherited_static($class, 'extensions')) foreach($extensions as $extension) {
|
if(in_array($class, $notExtendable)) continue;
|
||||||
|
|
||||||
|
if($extensions = self::uninherited_static($class, 'extensions')) {
|
||||||
|
foreach($extensions as $extension) {
|
||||||
// an $extension value can contain parameters as a string,
|
// an $extension value can contain parameters as a string,
|
||||||
// e.g. "Versioned('Stage','Live')"
|
// e.g. "Versioned('Stage','Live')"
|
||||||
if(strpos($extension,'(') === false) $instance = new $extension();
|
if(strpos($extension,'(') === false) $instance = new $extension();
|
||||||
@ -517,6 +523,7 @@ abstract class Object {
|
|||||||
$this->extension_instances[$instance->class] = $instance;
|
$this->extension_instances[$instance->class] = $instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!isset(self::$classes_constructed[$this->class])) {
|
if(!isset(self::$classes_constructed[$this->class])) {
|
||||||
$this->defineMethods();
|
$this->defineMethods();
|
||||||
@ -655,13 +662,23 @@ abstract class Object {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(method_exists($extension, 'allMethodNames')) {
|
if(method_exists($extension, 'allMethodNames')) {
|
||||||
|
$methods = $extension->allMethodNames(true);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if(!isset(self::$built_in_methods[$extension->class])) {
|
||||||
|
self::$built_in_methods[$extension->class] = array_map('strtolower', get_class_methods($extension));
|
||||||
|
}
|
||||||
|
$methods = self::$built_in_methods[$extension->class];
|
||||||
|
}
|
||||||
|
|
||||||
|
if($methods) {
|
||||||
$methodInfo = array(
|
$methodInfo = array(
|
||||||
'property' => $property,
|
'property' => $property,
|
||||||
'index' => $index,
|
'index' => $index,
|
||||||
'callSetOwnerFirst' => $extension instanceof Extension,
|
'callSetOwnerFirst' => $extension instanceof Extension,
|
||||||
);
|
);
|
||||||
|
|
||||||
$newMethods = array_fill_keys($extension->allMethodNames(true), $methodInfo);
|
$newMethods = array_fill_keys($methods, $methodInfo);
|
||||||
|
|
||||||
if(isset(self::$extra_methods[$this->class])) {
|
if(isset(self::$extra_methods[$this->class])) {
|
||||||
self::$extra_methods[$this->class] =
|
self::$extra_methods[$this->class] =
|
||||||
@ -806,7 +823,7 @@ abstract class Object {
|
|||||||
$values = array();
|
$values = array();
|
||||||
|
|
||||||
if($this->extension_instances) foreach($this->extension_instances as $instance) {
|
if($this->extension_instances) foreach($this->extension_instances as $instance) {
|
||||||
if($instance->hasMethod($method)) {
|
if(method_exists($instance, $method)) {
|
||||||
$instance->setOwner($this);
|
$instance->setOwner($this);
|
||||||
$value = $instance->$method($a1, $a2, $a3, $a4, $a5, $a6, $a7);
|
$value = $instance->$method($a1, $a2, $a3, $a4, $a5, $a6, $a7);
|
||||||
if($value !== null) $values[] = $value;
|
if($value !== null) $values[] = $value;
|
||||||
|
@ -66,9 +66,9 @@ abstract class DataObjectDecorator extends Extension {
|
|||||||
|
|
||||||
// Array to be merged
|
// Array to be merged
|
||||||
if(self::$decoratable_statics[$name]) {
|
if(self::$decoratable_statics[$name]) {
|
||||||
$origVal = self::uninherited_static($class, $name);
|
$origVal = Object::uninherited_static($class, $name);
|
||||||
// Can't use add_static_var() here as it would merge the array rather than replacing
|
// Can't use add_static_var() here as it would merge the array rather than replacing
|
||||||
self::set_static($class, $name, array_merge((array)$origVal, $newVal));
|
Object::set_static($class, $name, array_merge((array)$origVal, $newVal));
|
||||||
|
|
||||||
// Value to be overwritten
|
// Value to be overwritten
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user