Passed
Push — master ( c86bca...390f5e )
by Romain
03:39
created

UriBuilder::injectUriBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Backend\Module\Uri;
18
19
use CuyZ\Notiz\Backend\Module\ModuleManager;
20
use CuyZ\Notiz\Core\Support\NotizConstants;
21
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder as ExbaseUriBuilder;
22
23
class UriBuilder
24
{
25
    /**
26
     * @var string
27
     */
28
    protected $controller;
29
30
    /**
31
     * @var string
32
     */
33
    protected $action;
34
35
    /**
36
     * @var array
37
     */
38
    protected $arguments = [];
39
40
    /**
41
     * @var ModuleManager
42
     */
43
    protected $moduleManager;
44
45
    /**
46
     * @var ExbaseUriBuilder
47
     */
48
    protected $uriBuilder;
49
50
    /**
51
     * @param ModuleManager $moduleManager
52
     */
53
    public function __construct(ModuleManager $moduleManager)
54
    {
55
        $this->moduleManager = $moduleManager;
56
    }
57
58
    /**
59
     * @param $controller
60
     * @return $this
61
     */
62
    public function forController($controller)
63
    {
64
        $this->controller = $controller;
65
66
        return $this;
67
    }
68
69
    /**
70
     * @param $action
71
     * @return $this
72
     */
73
    public function forAction($action)
74
    {
75
        $this->action = $action;
76
77
        return $this;
78
    }
79
80
    /**
81
     * @param array $arguments
82
     * @return $this
83
     */
84
    public function withArguments(array $arguments)
85
    {
86
        $this->arguments = $arguments;
87
88
        return $this;
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    public function build()
95
    {
96
        $module = $this->moduleManager->getModuleName();
97
        $controller = $this->controller ?: $this->moduleManager->getDefaultControllerName();
98
99
        return $this->uriBuilder
100
            ->reset()
101
            ->setArguments(['M' => $module])
102
            ->uriFor(
103
                $this->action,
104
                $this->arguments,
105
                $controller,
106
                NotizConstants::EXTENSION_KEY,
107
                $module
108
            );
109
    }
110
111
    /**
112
     * @param ExbaseUriBuilder $uriBuilder
113
     */
114
    public function injectUriBuilder(ExbaseUriBuilder $uriBuilder)
115
    {
116
        $this->uriBuilder = $uriBuilder;
117
    }
118
}
119