Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding a plugin propery to models wwith tests for ticket #85

Merge pull request #696
  • Loading branch information...
commit 6d4f4b57d76cd733ed0ecc39f4b97f343a14642e 1 parent 268e589
@dogmatic69 dogmatic69 authored markstory committed
View
13 lib/Cake/Model/Model.php
@@ -236,6 +236,13 @@ class Model extends Object implements CakeEventListener {
public $tablePrefix = null;
/**
+ * Plugin model belongs to.
+ *
+ * @var string
+ */
+ public $plugin = null;
+
+/**
* Name of the model.
*
* @var string
@@ -665,12 +672,16 @@ public function __construct($id = false, $table = null, $ds = null) {
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));
}
View
8 lib/Cake/Test/Case/Model/ModelIntegrationTest.php
@@ -1667,6 +1667,14 @@ public function testIdentity() {
$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);
}
/**
View
1  lib/Cake/Utility/ClassRegistry.php
@@ -124,6 +124,7 @@ public static function init($class, $strict = false) {
list($plugin, $class) = pluginSplit($class);
if ($plugin) {
$pluginPath = $plugin . '.';
+ $settings['plugin'] = $plugin;
}
if (empty($settings['alias'])) {
Please sign in to comment.
Something went wrong with that request. Please try again.