Browse Source

Rename WidgetRegistry to WidgetLocator

Refs #11697
Raúl Arellano 8 years ago
parent
commit
bcca84e996

+ 20 - 19
src/View/Helper/FormHelper.php

@@ -24,7 +24,7 @@ use Cake\View\Form\ContextInterface;
 use Cake\View\Helper;
 use Cake\View\StringTemplateTrait;
 use Cake\View\View;
-use Cake\View\Widget\WidgetRegistry;
+use Cake\View\Widget\WidgetLocator;
 use DateTime;
 use RuntimeException;
 use Traversable;
@@ -217,11 +217,11 @@ class FormHelper extends Helper
     protected $_unlockedFields = [];
 
     /**
-     * Registry for input widgets.
+     * Locator for input widgets.
      *
-     * @var \Cake\View\Widget\WidgetRegistry
+     * @var \Cake\View\Widget\WidgetLocator
      */
-    protected $_registry;
+    protected $_locator;
 
     /**
      * Context for the current form.
@@ -260,11 +260,11 @@ class FormHelper extends Helper
      */
     public function __construct(View $View, array $config = [])
     {
-        $registry = null;
+        $locator = null;
         $widgets = $this->_defaultWidgets;
-        if (isset($config['registry'])) {
-            $registry = $config['registry'];
-            unset($config['registry']);
+        if (isset($config['locator'])) {
+            $locator = $config['locator'];
+            unset($config['locator']);
         }
         if (isset($config['widgets'])) {
             if (is_string($config['widgets'])) {
@@ -276,29 +276,30 @@ class FormHelper extends Helper
 
         parent::__construct($View, $config);
 
-        $this->widgetRegistry($registry, $widgets);
+        $this->widgetLocator($locator, $widgets);
         $this->_idPrefix = $this->getConfig('idPrefix');
     }
 
     /**
      * Set the widget registry the helper will use.
      *
-     * @param \Cake\View\Widget\WidgetRegistry|null $instance The registry instance to set.
+     * @param \Cake\View\Widget\WidgetLocator|null $instance The locator instance to set.
      * @param array $widgets An array of widgets
-     * @return \Cake\View\Widget\WidgetRegistry
+     * @return \Cake\View\Widget\WidgetLocator
+     * @since 3.6.0
      */
-    public function widgetRegistry(WidgetRegistry $instance = null, $widgets = [])
+    public function widgetLocator(WidgetLocator $instance = null, $widgets = [])
     {
         if ($instance === null) {
-            if ($this->_registry === null) {
-                $this->_registry = new WidgetRegistry($this->templater(), $this->_View, $widgets);
+            if ($this->_locator === null) {
+                $this->_locator = new WidgetLocator($this->templater(), $this->_View, $widgets);
             }
 
-            return $this->_registry;
+            return $this->_locator;
         }
-        $this->_registry = $instance;
+        $this->_locator = $instance;
 
-        return $this->_registry;
+        return $this->_locator;
     }
 
     /**
@@ -2771,7 +2772,7 @@ class FormHelper extends Helper
      */
     public function addWidget($name, $spec)
     {
-        $this->_registry->add([$name => $spec]);
+        $this->_locator->add([$name => $spec]);
     }
 
     /**
@@ -2793,7 +2794,7 @@ class FormHelper extends Helper
             $secure = $data['secure'];
             unset($data['secure']);
         }
-        $widget = $this->_registry->get($name);
+        $widget = $this->_locator->get($name);
         $out = $widget->render($data, $this->context());
         if (isset($data['name']) && $secure !== null && $secure !== self::SECURE_SKIP) {
             foreach ($widget->secureFields($data) as $field) {

+ 2 - 2
src/View/Widget/WidgetRegistry.php

@@ -9,7 +9,7 @@
  *
  * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  * @link          https://cakephp.org CakePHP(tm) Project
- * @since         3.0.0
+ * @since         3.6.0
  * @license       https://opensource.org/licenses/mit-license.php MIT License
  */
 namespace Cake\View\Widget;
@@ -36,7 +36,7 @@ use RuntimeException;
  *
  * Widgets can ask for the current view by using the `_view` widget.
  */
-class WidgetRegistry
+class WidgetLocator
 {
 
     /**

+ 5 - 5
tests/TestCase/View/Helper/FormHelperTest.php

@@ -228,21 +228,21 @@ class FormHelperTest extends TestCase
             ]
         ];
         $helper = new FormHelper($this->View, $config);
-        $registry = $helper->widgetRegistry();
-        $this->assertInstanceOf('Cake\View\Widget\LabelWidget', $registry->get('datetime'));
+        $locator = $helper->widgetLocator();
+        $this->assertInstanceOf('Cake\View\Widget\LabelWidget', $locator->get('datetime'));
     }
 
     /**
      * Test that when specifying custom widgets config file and it should be
-     * added to widgets array. WidgetRegistry will load widgets in constructor.
+     * added to widgets array. WidgetLocator will load widgets in constructor.
      *
      * @return void
      */
     public function testConstructWithWidgetsConfig()
     {
         $helper = new FormHelper($this->View, ['widgets' => ['test_widgets']]);
-        $registry = $helper->widgetRegistry();
-        $this->assertInstanceOf('Cake\View\Widget\LabelWidget', $registry->get('text'));
+        $locator = $helper->widgetLocator();
+        $this->assertInstanceOf('Cake\View\Widget\LabelWidget', $locator->get('text'));
     }
 
     /**

+ 17 - 17
tests/TestCase/View/Widget/WidgetRegistryTest.php

@@ -18,12 +18,12 @@ use Cake\Core\Plugin;
 use Cake\TestSuite\TestCase;
 use Cake\View\StringTemplate;
 use Cake\View\View;
-use Cake\View\Widget\WidgetRegistry;
+use Cake\View\Widget\WidgetLocator;
 
 /**
- * WidgetRegistry test case
+ * WidgetLocator test case
  */
-class WidgetRegistryTestCase extends TestCase
+class WidgetLocatorTestCase extends TestCase
 {
 
     /**
@@ -49,7 +49,7 @@ class WidgetRegistryTestCase extends TestCase
             'text' => ['Cake\View\Widget\BasicWidget'],
             'label' => ['Label'],
         ];
-        $inputs = new WidgetRegistry($this->templates, $this->view, $widgets);
+        $inputs = new WidgetLocator($this->templates, $this->view, $widgets);
         $result = $inputs->get('text');
         $this->assertInstanceOf('Cake\View\Widget\BasicWidget', $result);
 
@@ -58,13 +58,13 @@ class WidgetRegistryTestCase extends TestCase
     }
 
     /**
-     * Test getting view instance from registry.
+     * Test getting view instance from locator.
      *
      * @return void
      */
     public function testGetViewInstance()
     {
-        $inputs = new WidgetRegistry($this->templates, $this->view, []);
+        $inputs = new WidgetLocator($this->templates, $this->view, []);
 
         $result = $inputs->get('_view');
         $this->assertInstanceOf('Cake\View\View', $result);
@@ -81,7 +81,7 @@ class WidgetRegistryTestCase extends TestCase
             'text' => ['Cake\View\Widget\BasicWidget'],
             'test_widgets',
         ];
-        $inputs = new WidgetRegistry($this->templates, $this->view, $widgets);
+        $inputs = new WidgetLocator($this->templates, $this->view, $widgets);
         $this->assertInstanceOf('Cake\View\Widget\LabelWidget', $inputs->get('text'));
     }
 
@@ -97,7 +97,7 @@ class WidgetRegistryTestCase extends TestCase
             'text' => ['Cake\View\Widget\BasicWidget'],
             'TestPlugin.test_widgets',
         ];
-        $inputs = new WidgetRegistry($this->templates, $this->view, $widgets);
+        $inputs = new WidgetLocator($this->templates, $this->view, $widgets);
         $this->assertInstanceOf('Cake\View\Widget\LabelWidget', $inputs->get('text'));
     }
 
@@ -108,7 +108,7 @@ class WidgetRegistryTestCase extends TestCase
      */
     public function testAdd()
     {
-        $inputs = new WidgetRegistry($this->templates, $this->view);
+        $inputs = new WidgetLocator($this->templates, $this->view);
         $result = $inputs->add([
             'text' => ['Cake\View\Widget\BasicWidget'],
         ]);
@@ -116,7 +116,7 @@ class WidgetRegistryTestCase extends TestCase
         $result = $inputs->get('text');
         $this->assertInstanceOf('Cake\View\Widget\WidgetInterface', $result);
 
-        $inputs = new WidgetRegistry($this->templates, $this->view);
+        $inputs = new WidgetLocator($this->templates, $this->view);
         $result = $inputs->add([
             'hidden' => 'Cake\View\Widget\BasicWidget',
         ]);
@@ -134,7 +134,7 @@ class WidgetRegistryTestCase extends TestCase
     {
         $this->expectException(\RuntimeException::class);
         $this->expectExceptionMessage('Widget objects must implement Cake\View\Widget\WidgetInterface');
-        $inputs = new WidgetRegistry($this->templates, $this->view);
+        $inputs = new WidgetLocator($this->templates, $this->view);
         $inputs->add([
             'text' => new \StdClass()
         ]);
@@ -147,7 +147,7 @@ class WidgetRegistryTestCase extends TestCase
      */
     public function testGet()
     {
-        $inputs = new WidgetRegistry($this->templates, $this->view);
+        $inputs = new WidgetLocator($this->templates, $this->view);
         $inputs->add([
             'text' => ['Cake\View\Widget\BasicWidget'],
         ]);
@@ -163,7 +163,7 @@ class WidgetRegistryTestCase extends TestCase
      */
     public function testGetFallback()
     {
-        $inputs = new WidgetRegistry($this->templates, $this->view);
+        $inputs = new WidgetLocator($this->templates, $this->view);
         $inputs->add([
             '_default' => ['Cake\View\Widget\BasicWidget'],
         ]);
@@ -183,7 +183,7 @@ class WidgetRegistryTestCase extends TestCase
     {
         $this->expectException(\RuntimeException::class);
         $this->expectExceptionMessage('Unknown widget "foo"');
-        $inputs = new WidgetRegistry($this->templates, $this->view);
+        $inputs = new WidgetLocator($this->templates, $this->view);
         $inputs->clear();
         $inputs->get('foo');
     }
@@ -195,7 +195,7 @@ class WidgetRegistryTestCase extends TestCase
      */
     public function testGetResolveDependency()
     {
-        $inputs = new WidgetRegistry($this->templates, $this->view);
+        $inputs = new WidgetLocator($this->templates, $this->view);
         $inputs->clear();
         $inputs->add([
             'label' => ['Cake\View\Widget\LabelWidget'],
@@ -214,7 +214,7 @@ class WidgetRegistryTestCase extends TestCase
     {
         $this->expectException(\RuntimeException::class);
         $this->expectExceptionMessage('Unable to locate widget class "TestApp\View\DerpWidget"');
-        $inputs = new WidgetRegistry($this->templates, $this->view);
+        $inputs = new WidgetLocator($this->templates, $this->view);
         $inputs->add(['test' => ['TestApp\View\DerpWidget']]);
         $inputs->get('test');
     }
@@ -228,7 +228,7 @@ class WidgetRegistryTestCase extends TestCase
     {
         $this->expectException(\RuntimeException::class);
         $this->expectExceptionMessage('Unknown widget "label"');
-        $inputs = new WidgetRegistry($this->templates, $this->view);
+        $inputs = new WidgetLocator($this->templates, $this->view);
         $inputs->clear();
         $inputs->add(['multicheckbox' => ['Cake\View\Widget\MultiCheckboxWidget', 'label']]);
         $inputs->get('multicheckbox');