Skip to content

Latest commit

 

History

History
91 lines (59 loc) · 2.33 KB

File metadata and controls

91 lines (59 loc) · 2.33 KB

RecordIterator

  • it allows easilly to iterate through selected records by users
  • service: Imatic\Bundle\DataBundle\Data\Driver\DoctrineDBAL\Command\RecordIterator
  • methods
    • each
      • iterates through records
    • eachIdentifier
      • iterates through identifiers of records
  • each method takes RecordIteratorArgs as argument
  • argument to the methods of RecordIterator
  • has 3 arguments
    • $command
      • command of the handler
    • $queryObject
      • query object user selected records from
    • $callback
      • callable with 1 argument based on called method
        • each passes record
        • eachIdentifier passes identifier of the record
  • has 1 method
    • setLimit
      • overwrites default limit per page

Example of handler deactivating all selected users selected by user

<?php

use Imatic\Bundle\DataBundle\Data\Command\CommandInterface;
use Imatic\Bundle\DataBundle\Data\Command\CommandResult;
use Imatic\Bundle\DataBundle\Data\Command\HandlerInterface;
use Imatic\Bundle\DataBundle\Data\Driver\DoctrineDBAL\Command\Recorditerator;
use Imatic\Bundle\DataBundle\Data\Driver\DoctrineDBAL\Command\RecordIteratorArgs;

DeactivateUsersHandler implements HandlerInterface
{

    private $recordIterator;

    public function __construct(RecordIterator $recordIterator)
    {
        $this->recordIterator = $recordIterator;
    }

    public function handle(CommandInterface $command)
    {
        $recordIteratorArgs = new RecordIteratorArgs(
            $command,
            new UserListQuery(),
            function (array $user) {
                deactivate($user);

                return CommandResult::success();
            }
        );

        $this->recordIterator->execute($recordIteratorArgs);
    }
}