Skip to content

Commit

Permalink
adding a plugin propery to models wwith tests for ticket cakephp#85
Browse files Browse the repository at this point in the history
  • Loading branch information
dogmatic69 committed Sep 12, 2012
1 parent b227ff4 commit 780003f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/Cake/Model/Model.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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));
}
Expand Down
8 changes: 8 additions & 0 deletions lib/Cake/Test/Case/Model/ModelIntegrationTest.php
Expand Up @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions lib/Cake/Utility/ClassRegistry.php
Expand Up @@ -118,6 +118,7 @@ public static function init($class, $strict = false) {
list($plugin, $class) = pluginSplit($class);
if ($plugin) {
$pluginPath = $plugin . '.';
$settings['plugin'] = $plugin;
}

if (empty($settings['alias'])) {
Expand Down

0 comments on commit 780003f

Please sign in to comment.