Browse Source

Remove Helper::$theme/$plugin.

They can be got/set from view instance instead.
ADmad 7 years ago
parent
commit
754559d4f5

+ 43 - 16
src/View/Helper.php

@@ -65,13 +65,6 @@ class Helper implements EventListenerInterface
     protected $_helperMap = [];
     protected $_helperMap = [];
 
 
     /**
     /**
-     * The current theme name if any.
-     *
-     * @var string
-     */
-    public $theme;
-
-    /**
      * Request object
      * Request object
      *
      *
      * @var \Cake\Http\ServerRequest
      * @var \Cake\Http\ServerRequest
@@ -79,13 +72,6 @@ class Helper implements EventListenerInterface
     public $request;
     public $request;
 
 
     /**
     /**
-     * Plugin path
-     *
-     * @var string
-     */
-    public $plugin;
-
-    /**
      * Holds the fields ['field_name' => ['type' => 'string', 'length' => 100]],
      * Holds the fields ['field_name' => ['type' => 'string', 'length' => 100]],
      * primaryKey and validates ['field_name']
      * primaryKey and validates ['field_name']
      *
      *
@@ -153,6 +139,49 @@ class Helper implements EventListenerInterface
 
 
             return $this->{$name};
             return $this->{$name};
         }
         }
+
+        $removed = [
+            'theme' => 'getTheme',
+            'plugin' => 'getPlugin',
+        ];
+        if (isset($removed[$name])) {
+            $method = $removed[$name];
+            deprecationWarning(sprintf(
+                'Helper::$%s is deprecated. Use $view->%s() instead.',
+                $name,
+                $method
+            ));
+
+            return $this->_View->{$method}();
+        }
+    }
+
+    /**
+     * Magic setter for removed properties.
+     *
+     * @param string $name Property name.
+     * @param mixed $value Value to set.
+     * @return void
+     */
+    public function __set($name, $value)
+    {
+        $removed = [
+            'template' => 'setTemplate',
+            'plugin' => 'setPlugin',
+        ];
+        if (isset($removed[$name])) {
+            $method = $removed[$name];
+            deprecationWarning(sprintf(
+                'Helper::$%s is deprecated. Use $view->%s() instead.',
+                $name,
+                $method
+            ));
+            $this->_View->{$method}($value);
+
+            return;
+        }
+
+        $this->{$name} = $value;
     }
     }
 
 
     /**
     /**
@@ -273,8 +302,6 @@ class Helper implements EventListenerInterface
     {
     {
         return [
         return [
             'helpers' => $this->helpers,
             'helpers' => $this->helpers,
-            'theme' => $this->theme,
-            'plugin' => $this->plugin,
             'fieldset' => $this->fieldset,
             'fieldset' => $this->fieldset,
             'tags' => $this->tags,
             'tags' => $this->tags,
             'implementedEvents' => $this->implementedEvents(),
             'implementedEvents' => $this->implementedEvents(),

+ 1 - 1
src/View/Helper/FormHelper.php

@@ -544,7 +544,7 @@ class FormHelper extends Helper
         }
         }
 
 
         $actionDefaults = [
         $actionDefaults = [
-            'plugin' => $this->plugin,
+            'plugin' => $this->_View->getPlugin(),
             'controller' => $this->request->getParam('controller'),
             'controller' => $this->request->getParam('controller'),
             'action' => $this->request->getParam('action'),
             'action' => $this->request->getParam('action'),
         ];
         ];

+ 0 - 3
src/View/HelperRegistry.php

@@ -145,9 +145,6 @@ class HelperRegistry extends ObjectRegistry implements EventDispatcherInterface
     {
     {
         $instance = new $class($this->_View, $settings);
         $instance = new $class($this->_View, $settings);
 
 
-        $instance->theme = $this->_View->getTheme();
-        $instance->plugin = $this->_View->getRequest()->getParam('Plugin');
-
         $enable = isset($settings['enabled']) ? $settings['enabled'] : true;
         $enable = isset($settings['enabled']) ? $settings['enabled'] : true;
         if ($enable) {
         if ($enable) {
             $this->getEventManager()->on($instance);
             $this->getEventManager()->on($instance);

+ 0 - 2
tests/TestCase/View/HelperTest.php

@@ -174,8 +174,6 @@ class HelperTest extends TestCase
                 'Html',
                 'Html',
                 'TestPlugin.OtherHelper'
                 'TestPlugin.OtherHelper'
             ],
             ],
-            'theme' => null,
-            'plugin' => null,
             'fieldset' => [],
             'fieldset' => [],
             'tags' => [],
             'tags' => [],
             'implementedEvents' => [
             'implementedEvents' => [