Пример #1
0
    /**
     * {@inheritDoc}
     */
    public function execute($request, $catchReply = false)
    {
        $action = null;
        try {
            $this->extensions->onPreExecute($request);

            if (false == $action = $this->findActionSupported($request)) {
                throw RequestNotSupportedException::create($request);
            }

            $this->extensions->onExecute($request, $action);

            $action->execute($request);

            $this->extensions->onPostExecute($request, $action);
        } catch (ReplyInterface $reply) {
            $reply =
                $this->extensions->onReply($reply, $request, $action) ?:
                $reply
            ;

            if ($catchReply) {
                return $reply;
            }

            throw $reply;
        } catch (\Exception $e) {
            $this->extensions->onException($e, $request, $action ?: null);

            throw $e;
        }

        return;
    }
Пример #2
0
 /**
  * {@inheritDoc}
  */
 public function execute($request, $catchInteractive = false)
 {
     $action = null;
     try {
         $this->extensions->onPreExecute($request);
         if (false == ($action = $this->findActionSupported($request))) {
             throw RequestNotSupportedException::create($request);
         }
         $this->extensions->onExecute($request, $action);
         $action->execute($request);
         $this->extensions->onPostExecute($request, $action);
     } catch (InteractiveRequestInterface $interactiveRequest) {
         $interactiveRequest = $this->extensions->onInteractiveRequest($interactiveRequest, $request, $action) ?: $interactiveRequest;
         if ($catchInteractive) {
             return $interactiveRequest;
         }
         throw $interactiveRequest;
     } catch (\Exception $e) {
         $this->extensions->onException($e, $request, $action ?: null);
         throw $e;
     }
     return null;
 }
Пример #3
0
 /**
  * {@inheritDoc}
  */
 public function execute($request, $catchReply = false)
 {
     $context = new Context($this, $request, $this->stack);
     array_push($this->stack, $context);
     try {
         $this->extensions->onPreExecute($context);
         if (false == $context->getAction()) {
             if (false == ($action = $this->findActionSupported($context->getRequest()))) {
                 throw RequestNotSupportedException::create($context->getRequest());
             }
             $context->setAction($action);
         }
         $this->extensions->onExecute($context);
         $context->getAction()->execute($request);
         $this->extensions->onPostExecute($context);
         array_pop($this->stack);
     } catch (ReplyInterface $reply) {
         $context->setReply($reply);
         $this->extensions->onPostExecute($context);
         array_pop($this->stack);
         if ($catchReply && $context->getReply()) {
             return $context->getReply();
         }
         if ($context->getReply()) {
             throw $context->getReply();
         }
     } catch (\Exception $e) {
         $context->setException($e);
         $this->extensions->onPostExecute($context);
         array_pop($this->stack);
         if ($context->getException()) {
             throw $context->getException();
         }
     }
     return;
 }
Пример #4
0
 protected function onPostExecuteWithException(Context $context)
 {
     array_pop($this->stack);
     $exception = $context->getException();
     try {
         $this->extensions->onPostExecute($context);
     } catch (\Exception $e) {
         // logic is similar to one in Symfony's ExceptionListener::onKernelException
         $wrapper = $e;
         while ($prev = $wrapper->getPrevious()) {
             if ($exception === ($wrapper = $prev)) {
                 throw $e;
             }
         }
         $prev = new \ReflectionProperty('Exception', 'previous');
         $prev->setAccessible(true);
         $prev->setValue($wrapper, $exception);
         throw $e;
     }
     if ($context->getException()) {
         throw $context->getException();
     }
 }
Пример #5
0
 /**
  * @test
  */
 public function shouldCallOnExceptionForAllExtensionsInCollection()
 {
     $expectedException = new \Exception();
     $expectedRequest = new \stdClass();
     $expectedAction = $this->getMock('Payum\\Core\\Action\\ActionInterface');
     $extensionFirst = $this->createExtensionMock();
     $extensionFirst->expects($this->once())->method('onException')->with($this->identicalTo($expectedException), $this->identicalTo($expectedRequest), $this->identicalTo($expectedAction));
     $extensionSecond = $this->createExtensionMock();
     $extensionSecond->expects($this->once())->method('onException')->with($this->identicalTo($expectedException), $this->identicalTo($expectedRequest), $this->identicalTo($expectedAction));
     $collection = new ExtensionCollection();
     $collection->addExtension($extensionFirst);
     $collection->addExtension($extensionSecond);
     $result = $collection->onException($expectedException, $expectedRequest, $expectedAction);
     $this->assertNull($result);
 }
Пример #6
0
 /**
  * @test
  */
 public function shouldCallOnPostExecuteForAllExtensionsInCollection()
 {
     $expectedContext = $this->createContextMock();
     $extensionFirst = $this->createExtensionMock();
     $extensionFirst->expects($this->once())->method('onPostExecute')->with($this->identicalTo($expectedContext));
     $extensionSecond = $this->createExtensionMock();
     $extensionSecond->expects($this->once())->method('onPostExecute')->with($expectedContext);
     $collection = new ExtensionCollection();
     $collection->addExtension($extensionFirst);
     $collection->addExtension($extensionSecond);
     $result = $collection->onPostExecute($expectedContext);
     $this->assertNull($result);
 }