Completed
Push — master ( 6f8c44...823f1c )
by Rafał
17:27 queued 08:20
created

ExceptionExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PH\Bundle\PayumBundle\Extension;
6
7
use Payum\Core\Bridge\Symfony\Reply\HttpResponse;
8
use Payum\Core\Extension\Context;
9
use Payum\Core\Extension\ExtensionInterface;
10
use Payum\Core\Request\RenderTemplate;
11
use Symfony\Component\HttpFoundation\Response;
12
13
final class ExceptionExtension implements ExtensionInterface
14
{
15
    private $templateName;
16
17
    public function __construct(string $templateName)
18
    {
19
        $this->templateName = $templateName;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function onPreExecute(Context $context)
26
    {
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function onExecute(Context $context)
33
    {
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function onPostExecute(Context $context)
40
    {
41
        if (null === $context->getException()) {
42
            return;
43
        }
44
45
        $renderTemplate = new RenderTemplate($this->templateName);
46
        $context->getGateway()->execute($renderTemplate);
47
48
        throw new HttpResponse(new Response($renderTemplate->getResult(), 200));
49
    }
50
}
51