Passed
Push — master ( 0eb352...3d191d )
by Ivan
02:24
created

AjaxcomTrait::refreshAjaxBlock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
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 Everlution\AjaxcomBundle\Controller;
6
7
use Everlution\AjaxcomBundle\DataObject\Callback;
8
use Everlution\AjaxcomBundle\Service\Ajaxcom;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * Class BaseController.
13
 *
14
 * @author Ivan Barlog <[email protected]>
15
 */
16
trait AjaxcomTrait
17
{
18
    public function render($view, array $parameters = array(), Response $response = null): Response
19
    {
20
        $request = $this->get('request_stack')->getMasterRequest();
21
22
        if ($request->server->get(Ajaxcom::AJAX_COM_HEADER, false)) {
23
            return $this->get('ajaxcom.handler')->handle($view, $parameters);
24
        }
25
26
        return parent::render($view, $parameters, $response);
27
    }
28
29
    protected function renderAjaxBlock(string $id): self
30
    {
31
        $this->get('ajaxcom.mutation.add_blocks')->add($id);
32
33
        return $this;
34
    }
35
36
    protected function refreshAjaxBlock(string $id): self
37
    {
38
        $this->get('ajaxcom.mutation.add_blocks')->refresh($id);
39
40
        return $this;
41
    }
42
43
    protected function removeAjaxBlock(string $selector): self
44
    {
45
        $this->get('ajaxcom.mutation.remove_blocks')->add($selector);
46
47
        return $this;
48
    }
49
50
    protected function addCallback(string $functionName, array $parameters = []): self
51
    {
52
        $this->get('ajaxcom.mutation.callbacks')->add(new Callback($functionName, $parameters));
53
54
        return $this;
55
    }
56
57
    protected function replaceClass(string $selector, string $class): self
58
    {
59
        $this->get('ajaxcom.mutation.replace_class')->add($selector, $class);
60
61
        return $this;
62
    }
63
64
    protected function doNotChangeUrl(): self
65
    {
66
        $this->get('ajaxcom.mutation.change_url')->doNotChangeUrl();
67
68
        return $this;
69
    }
70
71
    abstract protected function get($id);
72
}
73