From 4c6be2931b71a5b9c2a1e6df308e99e081e8552d Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Wed, 18 Apr 2012 23:10:57 +1200 Subject: [PATCH] BUGFIX Removing use of deprecated Object static functions like get_static(), set_static(), uninherited() etc. Replace with equivalent Config system get(), update() --- admin/code/CMSBatchActionHandler.php | 6 +++--- admin/code/CMSMenu.php | 18 +++++++++--------- control/RequestHandler.php | 4 ++-- core/Object.php | 22 +++++++--------------- dev/Deprecation.php | 2 +- dev/SapphireTest.php | 6 +++--- model/DataObject.php | 3 +-- model/Versioned.php | 2 +- view/ViewableData.php | 2 +- 9 files changed, 28 insertions(+), 37 deletions(-) diff --git a/admin/code/CMSBatchActionHandler.php b/admin/code/CMSBatchActionHandler.php index 23ee16129..95bbc7102 100644 --- a/admin/code/CMSBatchActionHandler.php +++ b/admin/code/CMSBatchActionHandler.php @@ -130,7 +130,7 @@ class CMSBatchActionHandler extends RequestHandler { function handleApplicablePages($request) { // Find the action handler - $actions = Object::get_static($this->class, 'batch_actions'); + $actions = Config::inst()->get($this->class, 'batch_actions', Config::FIRST_SET); $actionClass = $actions[$request->param('BatchAction')]; $actionHandler = new $actionClass['class'](); @@ -152,7 +152,7 @@ class CMSBatchActionHandler extends RequestHandler { function handleConfirmation($request) { // Find the action handler - $actions = Object::get_static($this->class, 'batch_actions'); + $actions = Config::inst()->get($this->class, 'batch_actions', Config::FIRST_SET); $actionClass = $actions[$request->param('BatchAction')]; $actionHandler = new $actionClass(); @@ -203,7 +203,7 @@ class CMSBatchActionHandler extends RequestHandler { * @return array See {@link register()} for the returned format. */ function batchActions() { - $actions = Object::get_static($this->class, 'batch_actions'); + $actions = Config::inst()->get($this->class, 'batch_actions', Config::FIRST_SET) if($actions) foreach($actions as $action) { if($action['recordClass'] != $this->recordClass) unset($action); } diff --git a/admin/code/CMSMenu.php b/admin/code/CMSMenu.php index d95c6d289..1e133e2ca 100644 --- a/admin/code/CMSMenu.php +++ b/admin/code/CMSMenu.php @@ -59,9 +59,9 @@ class CMSMenu extends Object implements IteratorAggregate, i18nEntityProvider * Return a CMSMenuItem to add the given controller to the CMSMenu */ protected static function menuitem_for_controller($controllerClass) { - $urlBase = Object::get_static($controllerClass, 'url_base'); - $urlSegment = Object::get_static($controllerClass, 'url_segment'); - $menuPriority = Object::get_static($controllerClass, 'menu_priority'); + $urlBase = Config::inst()->get($controllerClass, 'url_base', Config::FIRST_SET); + $urlSegment = Config::inst()->get($controllerClass, 'url_segment', Config::FIRST_SET); + $menuPriority = Config::inst()->get($controllerClass, 'menu_priority', Config::FIRST_SET); // Don't add menu items defined the old way if($urlSegment === null && $controllerClass != "CMSMain") return; @@ -81,12 +81,12 @@ class CMSMenu extends Object implements IteratorAggregate, i18nEntityProvider * Add the appropriate Director rules for the given controller. */ protected static function add_director_rule_for_controller($controllerClass) { - $urlBase = Object::get_static($controllerClass, 'url_base'); - $urlSegment = Object::get_static($controllerClass, 'url_segment'); - $urlRule = Object::get_static($controllerClass, 'url_rule'); - $urlPriority = Object::get_static($controllerClass, 'url_priority'); - - if($urlSegment || $controllerClass == "CMSMain") { + $urlBase = Config::inst()->get($controllerClass, 'url_base', Config::FIRST_SET); + $urlSegment = Config::inst()->get($controllerClass, 'url_segment', Config::FIRST_SET); + $urlRule = Config::inst()->get($controllerClass, 'url_rule', Config::FIRST_SET); + $urlPriority = Config::inst()->get($controllerClass, 'url_priority', Config::FIRST_SET); + + if($urlSegment || $controllerClass == 'CMSMain') { $link = Controller::join_links($urlBase, $urlSegment) . '/'; // Make director rule diff --git a/control/RequestHandler.php b/control/RequestHandler.php index f6cd39d15..47e724fef 100644 --- a/control/RequestHandler.php +++ b/control/RequestHandler.php @@ -138,8 +138,8 @@ class RequestHandler extends ViewableData { // We stop after RequestHandler; in other words, at ViewableData while($handlerClass && $handlerClass != 'ViewableData') { - $urlHandlers = Object::get_static($handlerClass, 'url_handlers'); - + $urlHandlers = Config::inst()->get($handlerClass, 'url_handlers', Config::FIRST_SET); + if($urlHandlers) foreach($urlHandlers as $rule => $action) { if(isset($_REQUEST['debug_request'])) Debug::message("Testing '$rule' with '" . $request->remaining() . "' on $this->class"); if($params = $request->match($rule, true)) { diff --git a/core/Object.php b/core/Object.php index b6a186333..d32bc20b8 100755 --- a/core/Object.php +++ b/core/Object.php @@ -333,9 +333,6 @@ abstract class Object { * If any extra values are discovered, they are then merged with the default PHP static values, or in some cases * completely replace the default PHP static when you set $replace = true, and do not define extra data on any child * classes - * - * Note that from SilverStripe 2.3.2, Object::get_static() can only be used to get public - * static variables, not protected ones. * * @param string $class * @param string $name the property name @@ -343,7 +340,7 @@ abstract class Object { * @return mixed */ public static function get_static($class, $name, $uncached = false) { - Deprecation::notice('3.1.0', 'combined_static is deprecated, replaced by Config#get'); + Deprecation::notice('3.1.0', 'get_static is deprecated, replaced by Config#get'); return Config::inst()->get($class, $name, Config::FIRST_SET); } @@ -355,17 +352,12 @@ abstract class Object { * @param mixed $value */ public static function set_static($class, $name, $value) { - Deprecation::notice('3.1.0', 'set_static is deprecated, replaced by Config#set'); + Deprecation::notice('3.1.0', 'set_static is deprecated, replaced by Config#update'); Config::inst()->update($class, $name, $value); } /** * Get an uninherited static variable - a variable that is explicity set in this class, and not in the parent class. - * - * Note that from SilverStripe 2.3.2, Object::uninherited_static() can only be used to get public - * static variables, not protected ones. - * - * @todo Recursively filter out parent statics, currently only inspects the parent class * * @param string $class * @param string $name @@ -401,7 +393,7 @@ abstract class Object { * @param bool $replace replace existing static vars */ public static function addStaticVars($class, $properties, $replace = false) { - Deprecation::notice('3.1.0', 'addStaticVars is deprecated, replaced by Config#set'); + Deprecation::notice('3.1.0', 'addStaticVars is deprecated, replaced by Config#update'); foreach($properties as $prop => $value) self::add_static_var($class, $prop, $value, $replace); } @@ -422,7 +414,7 @@ abstract class Object { * @param bool $replace completely replace existing static values */ public static function add_static_var($class, $name, $value, $replace = false) { - Deprecation::notice('3.1.0', 'add_static_var is deprecated, replaced by Config#set'); + Deprecation::notice('3.1.0', 'add_static_var is deprecated, replaced by Config#remove and Config#update'); if ($replace) Config::inst()->remove($class, $name); Config::inst()->update($class, $name, $value); @@ -783,21 +775,21 @@ abstract class Object { * @see Object::get_static() */ public function stat($name, $uncached = false) { - return self::get_static(($this->class ? $this->class : get_class($this)), $name, $uncached); + return Config::inst()->get(($this->class ? $this->class : get_class($this)), $name, Config::FIRST_SET); } /** * @see Object::set_static() */ public function set_stat($name, $value) { - self::set_static(($this->class ? $this->class : get_class($this)), $name, $value); + Config::inst()->update(($this->class ? $this->class : get_class($this)), $name, $value); } /** * @see Object::uninherited_static() */ public function uninherited($name) { - return self::uninherited_static(($this->class ? $this->class : get_class($this)), $name); + return Config::inst()->get(($this->class ? $this->class : get_class($this)), $name, Config::UNINHERITED); } /** diff --git a/dev/Deprecation.php b/dev/Deprecation.php index b25966200..071e31146 100644 --- a/dev/Deprecation.php +++ b/dev/Deprecation.php @@ -145,7 +145,7 @@ class Deprecation { // Get the level to raise the notice as $level = self::$notice_level; - if (!$level) $level = defined('E_USER_DEPRECATED') ? E_USER_DEPRECATED : E_USER_NOTICE; + if (!$level) $level = E_USER_DEPRECATED; // Then raise the notice if(substr($string,-1) != '.') $string .= "."; diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index 386d26b2c..e27bf19f2 100644 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -332,8 +332,8 @@ class SapphireTest extends PHPUnit_Framework_TestCase { $match = $fixture->idFromFixture($className, $identifier); if($match) return $match; } - - $fixtureFiles = Object::get_static(get_class($this), 'fixture_file'); + + $fixtureFiles = Config::inst()->get(get_class($this), 'fixture_file', Config::FIRST_SET); user_error(sprintf( "Couldn't find object '%s' (class: %s) in files %s", $identifier, @@ -381,7 +381,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase { if($match) return $match; } - $fixtureFiles = Object::get_static(get_class($this), 'fixture_file'); + $fixtureFiles = Config::inst()->get(get_class($this), 'fixture_file', Config::FIRST_SET); user_error(sprintf( "Couldn't find object '%s' (class: %s) in files %s", $identifier, diff --git a/model/DataObject.php b/model/DataObject.php index 8f2176ec3..70e125b29 100644 --- a/model/DataObject.php +++ b/model/DataObject.php @@ -2229,10 +2229,9 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity } } - $this->set_uninherited('permissionCache', $permissionCache); + Config::inst()->update($this->class, 'permissionCache', $permissionCache); } - if($permissionCache[$memberID][$perm]) { return in_array($this->ID, $permissionCache[$memberID][$perm]); } diff --git a/model/Versioned.php b/model/Versioned.php index 5612cb201..53fb299de 100644 --- a/model/Versioned.php +++ b/model/Versioned.php @@ -308,7 +308,7 @@ class Versioned extends DataExtension { else $table = $classTable; if($fields = DataObject::database_fields($this->owner->class)) { - $options = Object::get_static($this->owner->class, 'create_table_options'); + $options = Config::inst()->get($this->owner->class, 'create_table_options', Config::FIRST_SET); $indexes = $this->owner->databaseIndexes(); if ($suffix && ($ext = $this->owner->getExtensionInstance($allSuffixes[$suffix]))) { if (!$ext->isVersionedTable($table)) continue; diff --git a/view/ViewableData.php b/view/ViewableData.php index 913bfd835..e712d5b54 100644 --- a/view/ViewableData.php +++ b/view/ViewableData.php @@ -243,7 +243,7 @@ class ViewableData extends Object implements IteratorAggregate { return $fieldSpec; } - $specs = Object::combined_static(get_class($this), 'casting'); + $specs = Config::inst()->get(get_class($this), 'casting'); if(isset($specs[$field])) return $specs[$field]; if($this->failover) return $this->failover->castingHelper($field);