MDL-24962 backup - circular refs destroyer for backup settings

This commit is contained in:
Eloy Lafuente 2010-11-15 07:16:24 +00:00
parent 4f6ed68c1c
commit 287e804058
3 changed files with 41 additions and 2 deletions

View File

@ -113,6 +113,26 @@ abstract class base_setting {
$this->uisetting = new base_setting_ui($this);
}
/**
* Destroy all circular references. It helps PHP 5.2 a lot!
*/
public function destroy() {
// Before reseting anything, call destroy recursively
foreach ($this->dependencies as $dependency) {
$dependency->destroy();
}
foreach ($this->dependenton as $dependenton) {
$dependenton->destroy();
}
if ($this->uisetting) {
$this->uisetting->destroy();
}
// Everything has been destroyed recursively, now we can reset safely
$this->dependencies = array();
$this->dependenton = array();
$this->uisetting = null;
}
public function get_name() {
return $this->name;
}

View File

@ -77,6 +77,16 @@ abstract class setting_dependency {
$this->defaultvalue = $defaultvalue;
$this->lastvalue = $dependentsetting->get_value();
}
/**
* Destroy all circular references. It helps PHP 5.2 a lot!
*/
public function destroy() {
// No need to destroy anything recursively here, direct reset
$this->setting = null;
$this->dependentsetting = null;
}
/**
* Processes a change is setting called by the primary setting
* @param int $changetype
@ -442,4 +452,4 @@ class setting_dependency_disabledif_empty extends setting_dependency_disabledif_
// Else return based upon the dependent settings status
return ($this->dependentsetting->get_status() !== base_setting::NOT_LOCKED);
}
}
}

View File

@ -73,6 +73,15 @@ class base_setting_ui {
public function __construct(base_setting $setting) {
$this->setting = $setting;
}
/**
* Destroy all circular references. It helps PHP 5.2 a lot!
*/
public function destroy() {
// No need to destroy anything recursively here, direct reset
$this->setting = null;
}
/**
* Gets the name of this item including its prefix
* @return string
@ -581,4 +590,4 @@ class backup_setting_ui_dateselector extends backup_setting_ui_text {
}
class base_setting_ui_exception extends base_setting_exception {}
class backup_setting_ui_exception extends base_setting_ui_exception {};
class backup_setting_ui_exception extends base_setting_ui_exception {};