|
8 | 8 | *
|
9 | 9 | * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
10 | 10 | * @link http://cakephp.org CakePHP(tm) Project
|
11 |
| - * @package Cake.Controller |
12 | 11 | * @since CakePHP(tm) v 0.2.9
|
13 | 12 | * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
14 | 13 | */
|
15 | 14 |
|
16 | 15 | namespace Cake\Controller;
|
| 16 | + |
17 | 17 | use Cake\Core\App;
|
18 | 18 | use Cake\Core\Configure;
|
19 | 19 | use Cake\Core\Object;
|
|
27 | 27 | use Cake\Routing\Router;
|
28 | 28 | use Cake\Utility\ClassRegistry;
|
29 | 29 | use Cake\Utility\Inflector;
|
| 30 | +use Cake\Utility\MergeVariablesTrait; |
30 | 31 | use Cake\View\View;
|
31 | 32 |
|
32 | 33 | /**
|
|
63 | 64 | */
|
64 | 65 | class Controller extends Object implements EventListener {
|
65 | 66 |
|
| 67 | + use MergeVariablesTrait; |
| 68 | + |
66 | 69 | /**
|
67 | 70 | * The name of this controller. Controller names are plural, named after the model they manipulate.
|
68 | 71 | *
|
@@ -298,15 +301,6 @@ class Controller extends Object implements EventListener {
|
298 | 301 | */
|
299 | 302 | public $validationErrors = null;
|
300 | 303 |
|
301 |
| -/** |
302 |
| - * The class name of the parent class you wish to merge with. |
303 |
| - * Typically this is AppController, but you may wish to merge vars with a different |
304 |
| - * parent class. |
305 |
| - * |
306 |
| - * @var string |
307 |
| - */ |
308 |
| - protected $_mergeParent = null; |
309 |
| - |
310 | 304 | /**
|
311 | 305 | * Instance of the Cake\Event\EventManager this controller is using
|
312 | 306 | * to dispatch inner events.
|
@@ -539,71 +533,32 @@ protected function _getScaffold(Request $request) {
|
539 | 533 | * @return void
|
540 | 534 | */
|
541 | 535 | protected function _mergeControllerVars() {
|
542 |
| - $pluginController = $pluginDot = null; |
543 |
| - $mergeParent = is_subclass_of($this, $this->_mergeParent); |
544 |
| - $pluginVars = array(); |
545 |
| - $appVars = array(); |
546 |
| - |
| 536 | + $pluginDot = null; |
547 | 537 | if (!empty($this->plugin)) {
|
548 |
| - $pluginController = Plugin::getNamespace($this->plugin) . '\Controller\Controller'; |
549 |
| - if (!is_subclass_of($this, $pluginController)) { |
550 |
| - $pluginController = null; |
551 |
| - } |
552 | 538 | $pluginDot = $this->plugin . '.';
|
553 | 539 | }
|
554 |
| - |
555 |
| - if ($pluginController) { |
556 |
| - $merge = array('components', 'helpers'); |
557 |
| - $this->_mergeVars($merge, $pluginController); |
558 |
| - } |
559 |
| - |
560 |
| - if ($mergeParent || !empty($pluginController)) { |
561 |
| - $appVars = get_class_vars($this->_mergeParent); |
562 |
| - $merge = array('components', 'helpers'); |
563 |
| - $this->_mergeVars($merge, $this->_mergeParent, true); |
564 |
| - } |
565 |
| - |
566 | 540 | if ($this->uses === null) {
|
567 | 541 | $this->uses = false;
|
568 | 542 | }
|
| 543 | + if ($this->uses === false) { |
| 544 | + $this->uses = []; |
| 545 | + $this->modelClass = ''; |
| 546 | + } |
569 | 547 | if ($this->uses === true) {
|
570 | 548 | $this->uses = array($pluginDot . $this->modelClass);
|
571 | 549 | }
|
572 |
| - if (isset($appVars['uses']) && $appVars['uses'] === $this->uses) { |
| 550 | + $oldUses = $this->uses; |
| 551 | + $this->_mergeVars( |
| 552 | + ['components', 'helpers', 'uses'], |
| 553 | + [ |
| 554 | + 'associative' => ['components', 'helpers'], |
| 555 | + 'reverse' => ['uses'] |
| 556 | + ] |
| 557 | + ); |
| 558 | + if ($this->uses === $oldUses) { |
573 | 559 | array_unshift($this->uses, $pluginDot . $this->modelClass);
|
574 | 560 | }
|
575 |
| - if ($pluginController) { |
576 |
| - $pluginVars = get_class_vars($pluginController); |
577 |
| - } |
578 |
| - if ($this->uses !== false) { |
579 |
| - $this->_mergeUses($pluginVars); |
580 |
| - $this->_mergeUses($appVars); |
581 |
| - } else { |
582 |
| - $this->uses = array(); |
583 |
| - $this->modelClass = ''; |
584 |
| - } |
585 |
| - } |
586 |
| - |
587 |
| -/** |
588 |
| - * Helper method for merging the $uses property together. |
589 |
| - * |
590 |
| - * Merges the elements not already in $this->uses into |
591 |
| - * $this->uses. |
592 |
| - * |
593 |
| - * @param array $merge The data to merge in. |
594 |
| - * @return void |
595 |
| - */ |
596 |
| - protected function _mergeUses($merge) { |
597 |
| - if (!isset($merge['uses'])) { |
598 |
| - return; |
599 |
| - } |
600 |
| - if ($merge['uses'] === true) { |
601 |
| - return; |
602 |
| - } |
603 |
| - $this->uses = array_merge( |
604 |
| - $this->uses, |
605 |
| - array_diff($merge['uses'], $this->uses) |
606 |
| - ); |
| 561 | + $this->uses = array_unique($this->uses); |
607 | 562 | }
|
608 | 563 |
|
609 | 564 | /**
|
|
0 commit comments