From 6d4f4b57d76cd733ed0ecc39f4b97f343a14642e Mon Sep 17 00:00:00 2001 From: dogmatic69 Date: Tue, 19 Jun 2012 22:46:34 +0100 Subject: [PATCH] adding a plugin propery to models wwith tests for ticket #85 Merge pull request #696 --- lib/Cake/Model/Model.php | 13 ++++++++++++- lib/Cake/Test/Case/Model/ModelIntegrationTest.php | 8 ++++++++ lib/Cake/Utility/ClassRegistry.php | 1 + 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 515f2e5b3..b4db4a7af 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -235,6 +235,13 @@ class Model extends Object implements CakeEventListener { */ public $tablePrefix = null; +/** + * Plugin model belongs to. + * + * @var string + */ + public $plugin = null; + /** * Name of the model. * @@ -665,12 +672,16 @@ class Model extends Object implements CakeEventListener { extract(array_merge( array( 'id' => $this->id, 'table' => $this->useTable, 'ds' => $this->useDbConfig, - 'name' => $this->name, 'alias' => $this->alias + 'name' => $this->name, 'alias' => $this->alias, 'plugin' => $this->plugin ), $id )); } + if ($this->plugin === null) { + $this->plugin = (isset($plugin) ? $plugin : $this->plugin); + } + if ($this->name === null) { $this->name = (isset($name) ? $name : get_class($this)); } diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index a7063c0fd..4eec3151f 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -1667,6 +1667,14 @@ class ModelIntegrationTest extends BaseModelTest { $result = $TestModel->alias; $expected = 'AnotherTest'; $this->assertEquals($expected, $result); + + $TestModel = ClassRegistry::init('Test'); + $expected = null; + $this->assertEquals($expected, $TestModel->plugin); + + $TestModel = ClassRegistry::init('TestPlugin.TestPluginComment'); + $expected = 'TestPlugin'; + $this->assertEquals($expected, $TestModel->plugin); } /** diff --git a/lib/Cake/Utility/ClassRegistry.php b/lib/Cake/Utility/ClassRegistry.php index b74f8b486..30c84faf6 100644 --- a/lib/Cake/Utility/ClassRegistry.php +++ b/lib/Cake/Utility/ClassRegistry.php @@ -124,6 +124,7 @@ class ClassRegistry { list($plugin, $class) = pluginSplit($class); if ($plugin) { $pluginPath = $plugin . '.'; + $settings['plugin'] = $plugin; } if (empty($settings['alias'])) {