Passed
Push — master ( 3e4ca6...647507 )
by Ivan
05:43
created

AjaxcomTrait::prependAjaxBlock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
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 replaceBlockContent(string $selector, string $blockId): self
30
    {
31
        $this->get('ajaxcom.mutation.replace_content')->add($selector, $blockId);
32
33
        return $this;
34
    }
35
36
    protected function renderAjaxBlock(string $id): self
37
    {
38
        $this->get('ajaxcom.mutation.add_blocks')->add($id);
39
40
        return $this;
41
    }
42
43
    protected function refreshAjaxBlock(string $id): self
44
    {
45
        $this->get('ajaxcom.mutation.add_blocks')->refresh($id);
46
47
        return $this;
48
    }
49
50
    protected function removeAjaxBlock(string $selector): self
51
    {
52
        $this->get('ajaxcom.mutation.remove_blocks')->add($selector);
53
54
        return $this;
55
    }
56
57
    protected function addCallback(string $functionName, array $parameters = []): self
58
    {
59
        $this->get('ajaxcom.mutation.callbacks')->add(new Callback($functionName, $parameters));
60
61
        return $this;
62
    }
63
64
    protected function replaceClass(string $selector, string $class): self
65
    {
66
        $this->get('ajaxcom.mutation.replace_class')->add($selector, $class);
67
68
        return $this;
69
    }
70
71
    protected function doNotChangeUrl(): self
72
    {
73
        $this->get('ajaxcom.mutation.change_url')->doNotChangeUrl();
74
75
        return $this;
76
    }
77
78
    protected function appendAjaxBlock(string $id): self
79
    {
80
        $this->get('ajaxcom.mutation.append_blocks')->add($id);
81
82
        return $this;
83
    }
84
85
    protected function prependAjaxBlock(string $id): self
86
    {
87
        $this->get('ajaxcom.mutation.prepend_blocks')->add($id);
88
89
        return $this;
90
    }
91
92
    abstract protected function get($id);
93
}
94