Skip to content
This repository
Browse code

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

Merge pull request #696
  • Loading branch information...
commit 6d4f4b57d76cd733ed0ecc39f4b97f343a14642e 1 parent 268e589
Carl Sutton authored June 19, 2012 markstory committed September 20, 2012
13  lib/Cake/Model/Model.php
@@ -236,6 +236,13 @@ class Model extends Object implements CakeEventListener {
236 236
 	public $tablePrefix = null;
237 237
 
238 238
 /**
  239
+ * Plugin model belongs to.
  240
+ *
  241
+ * @var string
  242
+ */
  243
+	public $plugin = null;
  244
+
  245
+/**
239 246
  * Name of the model.
240 247
  *
241 248
  * @var string
@@ -665,12 +672,16 @@ public function __construct($id = false, $table = null, $ds = null) {
665 672
 			extract(array_merge(
666 673
 				array(
667 674
 					'id' => $this->id, 'table' => $this->useTable, 'ds' => $this->useDbConfig,
668  
-					'name' => $this->name, 'alias' => $this->alias
  675
+					'name' => $this->name, 'alias' => $this->alias, 'plugin' => $this->plugin
669 676
 				),
670 677
 				$id
671 678
 			));
672 679
 		}
673 680
 
  681
+		if ($this->plugin === null) {
  682
+			$this->plugin = (isset($plugin) ? $plugin : $this->plugin);
  683
+		}
  684
+
674 685
 		if ($this->name === null) {
675 686
 			$this->name = (isset($name) ? $name : get_class($this));
676 687
 		}
8  lib/Cake/Test/Case/Model/ModelIntegrationTest.php
@@ -1667,6 +1667,14 @@ public function testIdentity() {
1667 1667
 		$result = $TestModel->alias;
1668 1668
 		$expected = 'AnotherTest';
1669 1669
 		$this->assertEquals($expected, $result);
  1670
+
  1671
+		$TestModel = ClassRegistry::init('Test');
  1672
+		$expected = null;
  1673
+		$this->assertEquals($expected, $TestModel->plugin);
  1674
+
  1675
+		$TestModel = ClassRegistry::init('TestPlugin.TestPluginComment');
  1676
+		$expected = 'TestPlugin';
  1677
+		$this->assertEquals($expected, $TestModel->plugin);
1670 1678
 	}
1671 1679
 
1672 1680
 /**
1  lib/Cake/Utility/ClassRegistry.php
@@ -124,6 +124,7 @@ public static function init($class, $strict = false) {
124 124
 				list($plugin, $class) = pluginSplit($class);
125 125
 				if ($plugin) {
126 126
 					$pluginPath = $plugin . '.';
  127
+					$settings['plugin'] = $plugin;
127 128
 				}
128 129
 
129 130
 				if (empty($settings['alias'])) {

0 notes on commit 6d4f4b5

Please sign in to comment.
Something went wrong with that request. Please try again.