Completed
Push — 4.0 ( 48d77f...d125c0 )
by Marc André
04:22 queued 02:35
created

Route::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 3
1
<?php
2
3
4
/**
5
 *
6
 * Copyright (c) 2010-2016 Nevraxe inc. & Marc André Audet <[email protected]>. All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without modification, are
9
 * permitted provided that the following conditions are met:
10
 *
11
 *   1. Redistributions of source code must retain the above copyright notice, this list of
12
 *       conditions and the following disclaimer.
13
 *
14
 *   2. Redistributions in binary form must reproduce the above copyright notice, this list
15
 *       of conditions and the following disclaimer in the documentation and/or other materials
16
 *       provided with the distribution.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 * DISCLAIMED. IN NO EVENT SHALL MARC ANDRÉ "MANHIM" AUDET BE LIABLE FOR ANY
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 */
30
31
32
namespace Cervo;
33
34
35
use Cervo\Exceptions\InvalidControllerException;
36
37
38
/**
39
 * Route manager for Cervo.
40
 *
41
 * @author Marc André Audet <[email protected]>
42
 */
43
class Route
44
{
45
    /**
46
     * The route's module
47
     * @var string
48
     */
49
    protected $module;
50
51
    /**
52
     * The route's controller
53
     * @var string
54
     */
55
    protected $controller;
56
57
    /**
58
     * The route's method
59
     * @var string
60
     */
61
    protected $method;
62
63
    /**
64
     * The parameters to pass
65
     * @var array
66
     */
67
    protected $parameters = [];
68
69
    /**
70
     * The arguments to pass
71
     * @var array
72
     */
73
    protected $arguments = [];
74
75
    /**
76
     * Set the method path.
77
     * Sanitize and split the method_path.
78
     *
79
     * @param string $method_path
80
     * @param array $parameters
81
     * @param array $arguments
82
     */
83
    public function __construct($method_path, $parameters = [], $arguments = [])
84
    {
85
        $controller_e = explode('/', $method_path);
86
        $c_controller_e = count($controller_e);
87
88
        if ($c_controller_e < 3) {
89
            throw new InvalidControllerException;
90
        }
91
92
        $this->module = $controller_e[0];
93
        $this->controller = implode('/', array_slice($controller_e, 1, $c_controller_e - 2));
94
        $this->method = $controller_e[$c_controller_e - 1];
95
        $this->parameters = $parameters;
96
        $this->arguments = $arguments;
97
    }
98
99
    public function getModule()
100
    {
101
        return $this->module;
102
    }
103
104
    public function getController()
105
    {
106
        return $this->controller;
107
    }
108
109
    public function getMethod()
110
    {
111
        return $this->method;
112
    }
113
114
    public function getParameters()
115
    {
116
        return $this->parameters;
117
    }
118
119
    public function getArguments()
120
    {
121
        return $this->arguments;
122
    }
123
}