src/Store/Mutators.php
<?php
/**
* This file is part of Hydrator package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Rds\Hydrator\Store;
use Rds\Hydrator\Mapper\MutatorInterface;
use Rds\Hydrator\Mapper\Payload\PayloadInterface;
/**
* Class Mutators
*
* @method MutatorInterface[] getIterator()
*/
final class Mutators extends Store
{
/**
* @param MutatorInterface $mutator
* @return Accessors|$this
*/
public function add($mutator): StoreInterface
{
\assert($mutator instanceof MutatorInterface);
return parent::add($mutator);
}
/**
* @param object $instance
* @param PayloadInterface $payload
* @return void
*/
public function apply(object $instance, PayloadInterface $payload): void
{
foreach ($this->getIterator() as $reader) {
$reader->write($instance, $payload);
}
}
}