Create and implement CollectionInterface as contract of all collections (e.g. based on the BaseCollection class)

This commit is contained in:
Meritoo
2021-03-29 19:02:28 +02:00
parent e47eaae8b2
commit 4f8c355d1b
8 changed files with 93 additions and 33 deletions

View File

@@ -10,7 +10,7 @@ namespace Meritoo\Common\Utilities;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\Persistence\Proxy;
use Meritoo\Common\Collection\BaseCollection;
use Meritoo\Common\Contract\Collection\CollectionInterface;
use Meritoo\Common\Exception\Reflection\CannotResolveClassNameException;
use Meritoo\Common\Exception\Reflection\MissingChildClassesException;
use Meritoo\Common\Exception\Reflection\NotExistingPropertyException;
@@ -207,11 +207,11 @@ class Reflection
* Returns values of given property for given objects.
* Looks for proper getter for the property.
*
* @param array|BaseCollection|object $objects The objects that should contain given property. It may be also one
* object.
* @param string $property Name of the property that contains a value
* @param bool $force (optional) If is set to true, try to retrieve value even if the
* object does not have property. Otherwise - not.
* @param array|CollectionInterface|object $objects The objects that should contain given property. It may be also
* one object.
* @param string $property Name of the property that contains a value
* @param bool $force (optional) If is set to true, try to retrieve value even if
* the object does not have property. Otherwise - not.
* @return array
*/
public static function getPropertyValues($objects, string $property, bool $force = false): array
@@ -224,7 +224,7 @@ class Reflection
return [];
}
if ($objects instanceof BaseCollection) {
if ($objects instanceof CollectionInterface) {
$objects = $objects->toArray();
}