-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
(Maybe in another repo)
It's better to use typed collection parameter (UserCollection) rather generic ObjectCollection
In Query classes, override defaultFormatterClass property :
protected $defaultFormatterClass = ModelCriteria::FORMAT_OBJECT;with our new formatter :
protected $defaultFormatterClass = UserFormatter::class;Create a collection class :
<?php
use Domain\Core\User\User;
use Propel\Runtime\Collection\ObjectCollection;
/**
* Class UserCollection
*/
class UserCollection extends ObjectCollection
{
/**
* UserCollection constructor.
*
* @param array $data
*/
public function __construct(array $data = [])
{
$this->setModel(User::class);
parent::__construct($data);
}
}Then create an Object Formatter like this :
<?php
use Domain\Core\User\Collection\UserCollection;
use Propel\Runtime\Formatter\ObjectFormatter;
class UserFormatter extends ObjectFormatter
{
public function getCollectionClassName()
{
return UserCollection::class;
}
}