/** * * @param CommandInterface $command * @return ResponseInterface * @throws \Exception */ public function execute(CommandInterface $command) { $this->commandStack->push($command); try { $command = $this->preCommand($command); $response = $this->doExecute($command); $response = $this->postCommand($command, $response); } catch (\Exception $exception) { $response = $this->exception($command, $exception); } return $this->terminate($command, $response); }
public function testCommandStack() { $stack = new CommandStack(); $command1 = $this->createCommand(); $command2 = $this->createCommand(); $command3 = $this->createCommand(); $this->assertEquals(null, $stack->getCurrentCommand()); $this->assertEquals(null, $stack->getMasterCommand()); $this->assertEquals(null, $stack->getParentCommand()); $this->assertEquals(null, $stack->pop()); $stack->push($command1); $this->assertEquals($command1, $stack->getCurrentCommand()); $this->assertEquals($command1, $stack->getMasterCommand()); $this->assertEquals(null, $stack->getParentCommand()); $stack->push($command2); $this->assertEquals($command2, $stack->getCurrentCommand()); $this->assertEquals($command1, $stack->getMasterCommand()); $this->assertEquals($command1, $stack->getParentCommand()); $stack->push($command3); $this->assertEquals($command3, $stack->getCurrentCommand()); $this->assertEquals($command1, $stack->getMasterCommand()); $this->assertEquals($command2, $stack->getParentCommand()); $this->assertEquals($command3, $stack->pop()); $this->assertEquals($command2, $stack->getCurrentCommand()); $this->assertEquals($command1, $stack->getMasterCommand()); $this->assertEquals($command1, $stack->getParentCommand()); $this->assertEquals($command2, $stack->pop()); $this->assertEquals($command1, $stack->getCurrentCommand()); $this->assertEquals($command1, $stack->getMasterCommand()); $this->assertEquals(null, $stack->getParentCommand()); $this->assertEquals($command1, $stack->pop()); $this->assertEquals(null, $stack->getCurrentCommand()); $this->assertEquals(null, $stack->getMasterCommand()); $this->assertEquals(null, $stack->getParentCommand()); $this->assertEquals(null, $stack->pop()); $this->assertEquals(null, $stack->getCurrentCommand()); $this->assertEquals(null, $stack->getMasterCommand()); $this->assertEquals(null, $stack->getParentCommand()); }