You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use Doctrine\Common\Collections\ArrayCollection;
final class UserEmailCollection extends ArrayCollection
{
public function __construct(UserEmail ...$arr)
{
parent::__construct($arr);
}
But when we do any function on that collection inside model, entity
class User {
public function disableExistingEmails(): void
{
$this->emails->map(static function (UserEmail $relatedEmail) use ($isFallbackEmailToDisable) {...})
we get such error
...Collection\UserEmailCollection::__construct(): Argument #1 must be of type
App\Domain\UserPack\Email\Model\UserEmail, array given, called in
/var/www/.../vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php on line 99
fixing this issue by creating and extending new abstract collection which overrides ArrayCollection functions e.g.
namespace App\Domain\Core\Collections;
use Closure;
use Doctrine\Common\Collections\ArrayCollection;
use function array_map;
abstract class AbstractModelCollection extends ArrayCollection
{
public function map(Closure $func)
{
return new static(
...
array_map(
callback: $func,
array : $this->toArray()
)
);
}
}
"doctrine/common": "^3.3.0",
I wonder if there is other way without overriding and extra bridge abstraction between domain collections and doctrine to fix the error.
Might be a feature request to add splat operator and typed Collection params maybe with interface e.g. CollectionItemInterface
Whatever answer / response, thanks and have a great day / night hehe! ;)
The text was updated successfully, but these errors were encountered:
We have typed collections
But when we do any function on that collection inside model, entity
we get such error
fixing this issue by creating and extending new abstract collection which overrides ArrayCollection functions e.g.
"doctrine/common": "^3.3.0",
I wonder if there is other way without overriding and extra bridge abstraction between domain collections and doctrine to fix the error.
Might be a feature request to add splat operator and typed Collection params maybe with interface e.g. CollectionItemInterface
Whatever answer / response, thanks and have a great day / night hehe! ;)
The text was updated successfully, but these errors were encountered: