diff --git a/core/Extension.php b/core/Extension.php new file mode 100644 index 000000000..6c53ec98e --- /dev/null +++ b/core/Extension.php @@ -0,0 +1,24 @@ +owner = $owner; + } +} + +?> \ No newline at end of file diff --git a/core/model/DataObject.php b/core/model/DataObject.php index 88260429e..bff4cff67 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -39,11 +39,6 @@ class DataObject extends Controller { */ protected $components; - /** - * This DataObjects extensions, eg Versioned. - * @var array - */ - protected $extension_instances = array(); /** * True if this DataObject has been destroyed. @@ -95,14 +90,6 @@ class DataObject extends Controller { HTTP::register_modification_date($record['LastEdited']); } - // Set up the extensions - if($extensions = $this->stat('extensions')) { - foreach($extensions as $extension) { - $instance = eval("return new $extension;"); - $instance->setOwner($this); - $this->extension_instances[$instance->class] = $instance; - } - } parent::__construct(); // Must be called after parent constructor @@ -126,15 +113,16 @@ class DataObject extends Controller { /** * Create a duplicate of this node. - * It will create the duplicate in the database. + * + * @param $doWrite Perform a write() operation before returning the object. If this is true, it will create the duplicate in the database. * * @return DataObject A duplicate of this node. The exact type will be the type of this node. */ - function duplicate() { + function duplicate($doWrite = true) { $className = $this->class; $clone = new $className( $this->record ); $clone->ID = 0; - $clone->write(); + if($doWrite) $clone->write(); return $clone; } @@ -175,14 +163,14 @@ class DataObject extends Controller { */ function defineMethods() { if($this->class == 'DataObject') return; - - if($this->extension_instances) foreach($this->extension_instances as $i => $instance) { - $this->addMethodsFrom('extension_instances', $i); - // Define the extra db fields + parent::defineMethods(); + + // Define the extra db fields + if($this->extension_instances) foreach($this->extension_instances as $i => $instance) { $instance->loadExtraDBFields(); } - + // Set up accessors for joined items if($manyMany = $this->many_many()) { foreach($manyMany as $relationship => $class) { @@ -201,8 +189,6 @@ class DataObject extends Controller { $this->addWrapperMethod($relationship, 'getComponent'); } } - - parent::defineMethods(); } /** @@ -312,6 +298,9 @@ class DataObject extends Controller { */ protected function onBeforeWrite() { $this->brokenOnWrite = false; + + $dummy = null; + $this->extend('augmentBeforeWrite', $dummy); } /** @@ -1304,56 +1293,6 @@ class DataObject extends Controller { return $query; } - /** - * Run the given function on all of this object's extensions - * - * @param string $funcName The name of the function. - * @param mixed $arg An Argument to be passed to each of the extension functions. - */ - public function extend($funcName, &$arg) { - if($this->extension_instances) { - foreach($this->extension_instances as $extension) { - if($extension->hasMethod($funcName)) { - $extension->$funcName($arg); - } - } - } - } - - /** - * Get an extension on this DataObject - * - * @param string $name Classname of the Extension (e.g. 'Versioned') - * - * @return DataObjectDecorator The instance of the extension - */ - public function getExtension($name) { - return $this->extension_instances[$name]; - } - - /** - * Returns true if the given extension class is attached to this object - * - * @param string $requiredExtension Classname of the extension - * - * @return boolean True if the given extension class is attached to this object - */ - public function hasExtension($requiredExtension) { - return isset($this->extension_instances[$requiredExtension]) ? true : false; - } - - /** - * Add an extension to the given object. - * This can be used to add extensions to built-in objects, such as role decorators on Member - */ - public static function add_extension($className, $extensionName) { - Object::addStaticVars($className, array( - 'extensions' => array( - $extensionName, - ), - )); - } - /** * Get a bunch of fields in a list - a