From b3d93ad22c4b861200fa76269e8b4c270f480bc2 Mon Sep 17 00:00:00 2001 From: mark_story Date: Thu, 14 Nov 2013 22:26:40 -0500 Subject: [PATCH] Convert Behavior + BehaviorRegistry to use config instead of settings. Refs #2298 --- Cake/ORM/Behavior.php | 50 +++++++++---------- Cake/ORM/BehaviorRegistry.php | 8 +-- .../TestCase/ORM/BehaviorRegistryTest.php | 8 +-- Cake/Test/TestCase/ORM/BehaviorTest.php | 35 ++++++------- 4 files changed, 47 insertions(+), 54 deletions(-) diff --git a/Cake/ORM/Behavior.php b/Cake/ORM/Behavior.php index f8ef00152b9..67a256e3fa7 100644 --- a/Cake/ORM/Behavior.php +++ b/Cake/ORM/Behavior.php @@ -103,61 +103,61 @@ class Behavior implements EventListener { protected static $_reflectionCache = []; /** - * Default settings + * Default configuration * - * These are merged with user-provided settings when the behavior is used. + * These are merged with user-provided configuration when the behavior is used. * * @var array */ - protected $_defaultSettings = []; + protected $_defaultConfig = []; /** - * Contains configuration settings. + * Contains configuration. * * @var array */ - protected $_settings = []; + protected $_config = []; /** * Constructor * - * Merge settings with the default and store in the settings property + * Merge config with the default and store in the config property * * Does not retain a reference to the Table object. If you need this * you should override the constructor. * * @param Table $table The table this behavior is attached to. - * @param array $settings The settings for this behavior. + * @param array $config The config for this behavior. */ - public function __construct(Table $table, array $settings = []) { - $this->_settings = $settings + $this->_defaultSettings; + public function __construct(Table $table, array $config = []) { + $this->_config = $config + $this->_defaultConfig; } /** - * Read the settings being used. + * Read the configuration being used. * * @return array */ - public function settings() { - return $this->_settings; + public function config() { + return $this->_config; } /** - * verifySettings + * verifyConfig * * Check that implemented* keys contain values pointing at callable * * @return void - * @throws Cake\Error\Exception if settings are invalid + * @throws Cake\Error\Exception if config are invalid */ - public function verifySettings() { + public function verifyConfig() { $keys = ['implementedFinders', 'implementedMethods']; foreach ($keys as $key) { - if (!isset($this->_settings[$key])) { + if (!isset($this->_config[$key])) { continue; } - foreach ($this->_settings[$key] as $method) { + foreach ($this->_config[$key] as $method) { if (!is_callable([$this, $method])) { throw new Exception(__d('cake_dev', 'The method %s is not callable on class %s', $method, get_class($this))); } @@ -184,8 +184,8 @@ public function implementedEvents() { 'Model.beforeDelete' => 'beforeDelete', 'Model.afterDelete' => 'afterDelete', ]; - $settings = $this->settings(); - $priority = isset($settings['priority']) ? $settings['priority'] : null; + $config = $this->config(); + $priority = isset($config['priority']) ? $config['priority'] : null; $events = []; foreach ($eventMap as $event => $method) { @@ -219,15 +219,15 @@ public function implementedEvents() { * With the above example, a call to `$Table->find('this')` will call `$Behavior->findThis()` * and a call to `$Table->find('alias')` will call `$Behavior->findMethodName()` * - * It is recommended, though not required, to define implementedFinders in the settings property + * It is recommended, though not required, to define implementedFinders in the config property * of child classes such that it is not necessary to use reflections to derive the available * method list. See core behaviors for examples * * @return array */ public function implementedFinders() { - if (isset($this->_settings['implementedFinders'])) { - return $this->_settings['implementedFinders']; + if (isset($this->_config['implementedFinders'])) { + return $this->_config['implementedFinders']; } $reflectionMethods = $this->_reflectionCache(); @@ -249,15 +249,15 @@ public function implementedFinders() { * With the above example, a call to `$Table->method()` will call `$Behavior->method()` * and a call to `$Table->aliasedmethod()` will call `$Behavior->somethingElse()` * - * It is recommended, though not required, to define implementedFinders in the settings property + * It is recommended, though not required, to define implementedFinders in the config property * of child classes such that it is not necessary to use reflections to derive the available * method list. See core behaviors for examples * * @return array */ public function implementedMethods() { - if (isset($this->_settings['implementedMethods'])) { - return $this->_settings['implementedMethods']; + if (isset($this->_config['implementedMethods'])) { + return $this->_config['implementedMethods']; } $reflectionMethods = $this->_reflectionCache(); diff --git a/Cake/ORM/BehaviorRegistry.php b/Cake/ORM/BehaviorRegistry.php index f0af4c8ea2d..da442adced0 100644 --- a/Cake/ORM/BehaviorRegistry.php +++ b/Cake/ORM/BehaviorRegistry.php @@ -104,12 +104,12 @@ protected function _throwMissingClassError($class, $plugin) { * * @param string $class The classname that is missing. * @param string $alias The alias of the object. - * @param array $settings An array of settings to use for the behavior. + * @param array $config An array of config to use for the behavior. * @return Behavior The constructed behavior class. */ - protected function _create($class, $alias, $settings) { - $instance = new $class($this->_table, $settings); - $enable = isset($settings['enabled']) ? $settings['enabled'] : true; + protected function _create($class, $alias, $config) { + $instance = new $class($this->_table, $config); + $enable = isset($config['enabled']) ? $config['enabled'] : true; if ($enable) { $this->_eventManager->attach($instance); } diff --git a/Cake/Test/TestCase/ORM/BehaviorRegistryTest.php b/Cake/Test/TestCase/ORM/BehaviorRegistryTest.php index fa4d560ea5a..e65733c0fce 100644 --- a/Cake/Test/TestCase/ORM/BehaviorRegistryTest.php +++ b/Cake/Test/TestCase/ORM/BehaviorRegistryTest.php @@ -56,10 +56,10 @@ public function tearDown() { */ public function testLoad() { Plugin::load('TestPlugin'); - $settings = ['alias' => 'Sluggable', 'replacement' => '-']; - $result = $this->Behaviors->load('Sluggable', $settings); + $config = ['alias' => 'Sluggable', 'replacement' => '-']; + $result = $this->Behaviors->load('Sluggable', $config); $this->assertInstanceOf('TestApp\Model\Behavior\SluggableBehavior', $result); - $this->assertEquals($settings, $result->settings()); + $this->assertEquals($config, $result->config()); $result = $this->Behaviors->load('TestPlugin.PersisterOne'); $this->assertInstanceOf('TestPlugin\Model\Behavior\PersisterOneBehavior', $result); @@ -145,7 +145,7 @@ public function testHasMethod() { $this->assertTrue($this->Behaviors->hasMethod('PERSIST')); $this->assertFalse($this->Behaviors->hasMethod('__construct')); - $this->assertFalse($this->Behaviors->hasMethod('settings')); + $this->assertFalse($this->Behaviors->hasMethod('config')); $this->assertFalse($this->Behaviors->hasMethod('implementedEvents')); $this->assertFalse($this->Behaviors->hasMethod('nope')); diff --git a/Cake/Test/TestCase/ORM/BehaviorTest.php b/Cake/Test/TestCase/ORM/BehaviorTest.php index b6b0eec51cb..28b23a9d67a 100644 --- a/Cake/Test/TestCase/ORM/BehaviorTest.php +++ b/Cake/Test/TestCase/ORM/BehaviorTest.php @@ -78,13 +78,6 @@ public function findFoo() { public function doSomething() { } -/** - * verifySettings - */ - public function verifySettings() { - parent::verifySettings(); - } - /** * implementedEvents * @@ -133,9 +126,9 @@ class BehaviorTest extends TestCase { */ public function testConstructor() { $table = $this->getMock('Cake\ORM\Table'); - $settings = ['key' => 'value']; - $behavior = new TestBehavior($table, $settings); - $this->assertEquals($settings, $behavior->settings()); + $config = ['key' => 'value']; + $behavior = new TestBehavior($table, $config); + $this->assertEquals($config, $behavior->config()); } public function testReflectionCache() { @@ -277,34 +270,34 @@ public function testImplementedFindersDisabled() { } /** - * testVerifySettings + * testVerifyConfig * * Don't expect an exception to be thrown * * @return void */ - public function testVerifySettings() { + public function testVerifyConfig() { $table = $this->getMock('Cake\ORM\Table'); $behavior = new Test2Behavior($table); - $behavior->verifySettings(); + $behavior->verifyConfig(); $this->assertTrue(true, 'No exception thrown'); } /** - * testVerifySettingsImplementedFindersOverriden + * testVerifyConfigImplementedFindersOverriden * * Simply don't expect an exception to be thrown * * @return void */ - public function testVerifySettingsImplementedFindersOverriden() { + public function testVerifyConfigImplementedFindersOverriden() { $table = $this->getMock('Cake\ORM\Table'); $behavior = new Test2Behavior($table, [ 'implementedFinders' => [ 'aliased' => 'findFoo' ] ]); - $behavior->verifySettings(); + $behavior->verifyConfig(); $this->assertTrue(true, 'No exception thrown'); } @@ -323,17 +316,17 @@ public function testVerifyImplementedFindersInvalid() { 'aliased' => 'findNotDefined' ] ]); - $behavior->verifySettings(); + $behavior->verifyConfig(); } /** - * testVerifySettingsImplementedMethodsOverriden + * testVerifyConfigImplementedMethodsOverriden * * Don't expect an exception to be thrown * * @return void */ - public function testVerifySettingsImplementedMethodsOverriden() { + public function testVerifyConfigImplementedMethodsOverriden() { $table = $this->getMock('Cake\ORM\Table'); $behavior = new Test2Behavior($table); $behavior = new Test2Behavior($table, [ @@ -341,7 +334,7 @@ public function testVerifySettingsImplementedMethodsOverriden() { 'aliased' => 'doSomething' ] ]); - $behavior->verifySettings(); + $behavior->verifyConfig(); $this->assertTrue(true, 'No exception thrown'); } @@ -360,7 +353,7 @@ public function testVerifyImplementedMethodsInvalid() { 'aliased' => 'iDoNotExist' ] ]); - $behavior->verifySettings(); + $behavior->verifyConfig(); } }