Browse Source

Backport 4.next changes to 3.next

mscherer 5 years ago
parent
commit
8c7d5bd964

+ 4 - 2
src/Cache/CacheRegistry.php

@@ -51,7 +51,7 @@ class CacheRegistry extends ObjectRegistry
      * Part of the template method for Cake\Core\ObjectRegistry::load()
      *
      * @param string $class The classname that is missing.
-     * @param string $plugin The plugin the cache is missing in.
+     * @param string|null $plugin The plugin the cache is missing in.
      * @return void
      * @throws \BadMethodCallException
      */
@@ -106,10 +106,12 @@ class CacheRegistry extends ObjectRegistry
      * Remove a single adapter from the registry.
      *
      * @param string $name The adapter name.
-     * @return void
+     * @return $this
      */
     public function unload($name)
     {
         unset($this->_loaded[$name]);
+
+        return $this;
     }
 }

+ 1 - 1
src/Console/HelperRegistry.php

@@ -72,7 +72,7 @@ class HelperRegistry extends ObjectRegistry
      * and Cake\Core\ObjectRegistry::unload()
      *
      * @param string $class The classname that is missing.
-     * @param string $plugin The plugin the helper is missing in.
+     * @param string|null $plugin The plugin the helper is missing in.
      * @return void
      * @throws \Cake\Console\Exception\MissingHelperException
      */

+ 1 - 1
src/Console/TaskRegistry.php

@@ -63,7 +63,7 @@ class TaskRegistry extends ObjectRegistry
      * and Cake\Core\ObjectRegistry::unload()
      *
      * @param string $class The classname that is missing.
-     * @param string $plugin The plugin the task is missing in.
+     * @param string|null $plugin The plugin the task is missing in.
      * @return void
      * @throws \Cake\Console\Exception\MissingTaskException
      */

+ 1 - 1
src/Controller/ComponentRegistry.php

@@ -94,7 +94,7 @@ class ComponentRegistry extends ObjectRegistry implements EventDispatcherInterfa
      * and Cake\Core\ObjectRegistry::unload()
      *
      * @param string $class The classname that is missing.
-     * @param string $plugin The plugin the component is missing in.
+     * @param string|null $plugin The plugin the component is missing in.
      * @return void
      * @throws \Cake\Controller\Exception\MissingComponentException
      */

+ 1 - 1
src/Core/ObjectRegistry.php

@@ -163,7 +163,7 @@ abstract class ObjectRegistry implements Countable, IteratorAggregate
      * Throw an exception when the requested object name is missing.
      *
      * @param string $class The class that is missing.
-     * @param string $plugin The plugin $class is missing from.
+     * @param string|null $plugin The plugin $class is missing from.
      * @return void
      * @throws \Exception
      */

+ 4 - 2
src/Datasource/ConnectionRegistry.php

@@ -48,7 +48,7 @@ class ConnectionRegistry extends ObjectRegistry
      * Part of the template method for Cake\Core\ObjectRegistry::load()
      *
      * @param string $class The classname that is missing.
-     * @param string $plugin The plugin the datasource is missing in.
+     * @param string|null $plugin The plugin the datasource is missing in.
      * @return void
      * @throws \Cake\Datasource\Exception\MissingDatasourceException
      */
@@ -92,10 +92,12 @@ class ConnectionRegistry extends ObjectRegistry
      * Remove a single adapter from the registry.
      *
      * @param string $name The adapter name.
-     * @return void
+     * @return $this
      */
     public function unload($name)
     {
         unset($this->_loaded[$name]);
+
+        return $this;
     }
 }

+ 1 - 0
src/Datasource/EntityInterface.php

@@ -44,6 +44,7 @@ use JsonSerializable;
  * @method array getVisible()
  * @method $this setNew($new)
  * @property mixed $id Alias for commonly used primary key.
+ * @method bool[] getAccessible()
  */
 interface EntityInterface extends ArrayAccess, JsonSerializable
 {

+ 17 - 6
src/Datasource/EntityTrait.php

@@ -69,7 +69,7 @@ trait EntityTrait
      * Holds a list of the properties that were modified or added after this object
      * was originally created.
      *
-     * @var array
+     * @var bool[]
      */
     protected $_dirty = [];
 
@@ -359,7 +359,7 @@ trait EntityTrait
      * When checking multiple properties. All properties must not be null
      * in order for true to be returned.
      *
-     * @param string|array $property The property or properties to check.
+     * @param string|string[] $property The property or properties to check.
      * @return bool
      */
     public function has($property)
@@ -728,7 +728,7 @@ trait EntityTrait
      * Returns an array with the requested properties
      * stored in this entity, indexed by property name
      *
-     * @param array $properties list of properties to be returned
+     * @param string[] $properties list of properties to be returned
      * @param bool $onlyDirty Return the requested property only if it is dirty
      * @return array
      */
@@ -751,7 +751,7 @@ trait EntityTrait
      * Properties that are unchanged from their original value will be included in the
      * return of this method.
      *
-     * @param array $properties List of properties to be returned
+     * @param string[] $properties List of properties to be returned
      * @return array
      */
     public function extractOriginal(array $properties)
@@ -771,7 +771,7 @@ trait EntityTrait
      * This method will only return properties that have been modified since
      * the entity was built. Unchanged properties will be omitted.
      *
-     * @param array $properties List of properties to be returned
+     * @param string[] $properties List of properties to be returned
      * @return array
      */
     public function extractOriginalChanged(array $properties)
@@ -1374,7 +1374,7 @@ trait EntityTrait
      * $entity->setAccess('*', false); // Mark all properties as protected
      * ```
      *
-     * @param string|array $property single or list of properties to change its accessibility
+     * @param string|string[] $property single or list of properties to change its accessibility
      * @param bool $set true marks the property as accessible, false will
      * mark it as protected.
      * @return $this
@@ -1398,6 +1398,17 @@ trait EntityTrait
     }
 
     /**
+     * Returns the raw accessible configuration for this entity.
+     * The `*` wildcard refers to all fields.
+     *
+     * @return bool[]
+     */
+    public function getAccessible()
+    {
+        return $this->_accessible;
+    }
+
+    /**
      * Checks if a property is accessible
      *
      * ### Example:

+ 4 - 2
src/Log/LogEngineRegistry.php

@@ -47,7 +47,7 @@ class LogEngineRegistry extends ObjectRegistry
      * Part of the template method for Cake\Core\ObjectRegistry::load()
      *
      * @param string $class The classname that is missing.
-     * @param string $plugin The plugin the logger is missing in.
+     * @param string|null $plugin The plugin the logger is missing in.
      * @return void
      * @throws \RuntimeException
      */
@@ -94,10 +94,12 @@ class LogEngineRegistry extends ObjectRegistry
      * Remove a single logger from the registry.
      *
      * @param string $name The logger name.
-     * @return void
+     * @return $this
      */
     public function unload($name)
     {
         unset($this->_loaded[$name]);
+
+        return $this;
     }
 }

+ 1 - 1
src/ORM/BehaviorRegistry.php

@@ -119,7 +119,7 @@ class BehaviorRegistry extends ObjectRegistry implements EventDispatcherInterfac
      * and Cake\Core\ObjectRegistry::unload()
      *
      * @param string $class The classname that is missing.
-     * @param string $plugin The plugin the behavior is missing in.
+     * @param string|null $plugin The plugin the behavior is missing in.
      * @return void
      * @throws \Cake\ORM\Exception\MissingBehaviorException
      */

+ 1 - 1
src/View/HelperRegistry.php

@@ -117,7 +117,7 @@ class HelperRegistry extends ObjectRegistry implements EventDispatcherInterface
      * and Cake\Core\ObjectRegistry::unload()
      *
      * @param string $class The classname that is missing.
-     * @param string $plugin The plugin the helper is missing in.
+     * @param string|null $plugin The plugin the helper is missing in.
      * @return void
      * @throws \Cake\View\Exception\MissingHelperException
      */

+ 42 - 0
tests/TestCase/ORM/EntityTest.php

@@ -161,6 +161,7 @@ class EntityTest extends TestCase
      */
     public function testSetOneParamWithSetter()
     {
+        /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */
         $entity = $this->getMockBuilder('\Cake\ORM\Entity')
             ->setMethods(['_setName'])
             ->getMock();
@@ -182,6 +183,7 @@ class EntityTest extends TestCase
      */
     public function testMultipleWithSetter()
     {
+        /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */
         $entity = $this->getMockBuilder('\Cake\ORM\Entity')
             ->setMethods(['_setName', '_setStuff'])
             ->getMock();
@@ -212,6 +214,7 @@ class EntityTest extends TestCase
      */
     public function testBypassSetters()
     {
+        /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */
         $entity = $this->getMockBuilder('\Cake\ORM\Entity')
             ->setMethods(['_setName', '_setStuff'])
             ->getMock();
@@ -290,6 +293,7 @@ class EntityTest extends TestCase
      */
     public function testGetCustomGetters()
     {
+        /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */
         $entity = $this->getMockBuilder('\Cake\ORM\Entity')
             ->setMethods(['_getName'])
             ->getMock();
@@ -311,6 +315,7 @@ class EntityTest extends TestCase
      */
     public function testGetCustomGettersAfterSet()
     {
+        /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */
         $entity = $this->getMockBuilder('\Cake\ORM\Entity')
             ->setMethods(['_getName'])
             ->getMock();
@@ -335,6 +340,7 @@ class EntityTest extends TestCase
      */
     public function testGetCacheClearedByUnset()
     {
+        /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */
         $entity = $this->getMockBuilder('\Cake\ORM\Entity')
             ->setMethods(['_getName'])
             ->getMock();
@@ -356,6 +362,7 @@ class EntityTest extends TestCase
      */
     public function testGetCamelCasedProperties()
     {
+        /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */
         $entity = $this->getMockBuilder('\Cake\ORM\Entity')
             ->setMethods(['_getListIdName'])
             ->getMock();
@@ -1123,6 +1130,7 @@ class EntityTest extends TestCase
      */
     public function testToArrayVirtualProperties()
     {
+        /** @var \Cake\ORM\Entity|\PHPUnit\Framework\MockObject\MockObject $entity */
         $entity = $this->getMockBuilder('\Cake\ORM\Entity')
             ->setMethods(['_getName'])
             ->getMock();
@@ -1146,6 +1154,21 @@ class EntityTest extends TestCase
     }
 
     /**
+     * Tests the getVisible() method
+     *
+     * @return void
+     */
+    public function testGetVisible()
+    {
+        $entity = new Entity();
+        $entity->foo = 'foo';
+        $entity->bar = 'bar';
+
+        $expected = $entity->getVisible();
+        $this->assertSame(['foo', 'bar'], $expected);
+    }
+
+    /**
      * Tests setting virtual properties with merging.
      *
      * @return void
@@ -1170,6 +1193,25 @@ class EntityTest extends TestCase
     }
 
     /**
+     * Tests getAccessible() method
+     *
+     * @return void
+     */
+    public function testGetAccessible()
+    {
+        $entity = new Entity();
+        $entity->setAccess('*', false);
+        $entity->setAccess('bar', true);
+
+        $accessible = $entity->getAccessible();
+        $expected = [
+            '*' => false,
+            'bar' => true,
+        ];
+        $this->assertSame($expected, $accessible);
+    }
+
+    /**
      * Tests the errors method
      *
      * @group deprecated