Predis\Pipeline\Pipeline::execute PHP Method

execute() public method

Handles the actual execution of the whole pipeline.
public execute ( mixed $callable = null ) : array
$callable mixed Optional callback for execution.
return array
    public function execute($callable = null)
    {
        if ($callable && !is_callable($callable)) {
            throw new \InvalidArgumentException('The argument must be a callable object.');
        }
        $exception = null;
        $this->setRunning(true);
        try {
            if ($callable) {
                call_user_func($callable, $this);
            }
            $this->flushPipeline();
        } catch (\Exception $exception) {
            // NOOP
        }
        $this->setRunning(false);
        if ($exception) {
            throw $exception;
        }
        return $this->responses;
    }

Usage Example

Esempio n. 1
0
 /**
  * @group disconnected
  */
 public function testExecuteWithCallableArgumentHandlesExceptions()
 {
     $exception = null;
     $connection = $this->getMock('Predis\\Connection\\NodeConnectionInterface');
     $connection->expects($this->never())->method('writeRequest');
     $connection->expects($this->never())->method('readResponse');
     $pipeline = new Pipeline(new Client($connection));
     $exception = null;
     $responses = null;
     try {
         $responses = $pipeline->execute(function ($pipe) {
             $pipe->echo('one');
             $pipe->echo('two');
             throw new ClientException('TEST');
         });
     } catch (\Exception $exception) {
         // NOOP
     }
     $this->assertInstanceOf('Predis\\ClientException', $exception);
     $this->assertSame('TEST', $exception->getMessage());
     $this->assertNull($responses);
 }