Mark V
1: <?php
2: namespace MOC\V\Component\Router\Component\Parameter\Repository;
3:
4: use MOC\V\Component\Router\Component\Exception\ComponentException;
5: use MOC\V\Component\Router\Component\IParameterInterface;
6: use MOC\V\Component\Router\Component\Parameter\Parameter;
7:
8: /**
9: * Class RouteParameter
10: *
11: * @package MOC\V\Component\Router\Component\Parameter\Repository
12: */
13: class RouteParameter extends Parameter implements IParameterInterface
14: {
15:
16: /** @var null|string $Path */
17: private $Path = null;
18: /** @var null|string $Controller */
19: private $Controller = null;
20: /** @var array $ParameterDefault */
21: private $ParameterDefault = array();
22: /** @var array $ParameterPattern */
23: private $ParameterPattern = array();
24:
25: /**
26: * @param string $Path
27: * @param string $Controller
28: */
29: public function __construct($Path, $Controller)
30: {
31:
32: $this->setPath($Path);
33: $this->setController($Controller);
34: }
35:
36: /**
37: * @param null|string $Path
38: */
39: private function setPath($Path)
40: {
41:
42: $this->Path = $Path;
43: }
44:
45: /**
46: * @param null|string $Controller
47: *
48: * @throws ComponentException
49: */
50: private function setController($Controller)
51: {
52:
53: if (false === strpos($Controller, '::')) {
54: throw new ComponentException($Controller);
55: }
56: $this->Controller = $Controller;
57: }
58:
59: /**
60: * @return string
61: */
62: public function getClass()
63: {
64:
65: $List = explode('::', $this->getController(), 2);
66: return current($List);
67: }
68:
69: /**
70: * @return null|string
71: */
72: public function getController()
73: {
74:
75: return $this->Controller;
76: }
77:
78: /**
79: * @return string
80: */
81: public function getMethod()
82: {
83:
84: $List = explode('::', $this->getController(), 2);
85: return end($List);
86: }
87:
88: /**
89: * @param null|string $Name
90: *
91: * @return array|mixed
92: */
93: public function getParameterDefault($Name = null)
94: {
95:
96: if (null === $Name) {
97: return (array)$this->ParameterDefault;
98: } else {
99: return $this->ParameterDefault[$Name];
100: }
101: }
102:
103: /**
104: * @param string $Name
105: * @param mixed $Value
106: *
107: * @return RouteParameter
108: */
109: public function setParameterDefault($Name, $Value)
110: {
111:
112: $this->ParameterDefault[$Name] = $Value;
113: return $this;
114: }
115:
116: /**
117: * @return array
118: */
119: public function getParameterPattern()
120: {
121:
122: return $this->ParameterPattern;
123: }
124:
125: /**
126: * @param string $Name
127: * @param string $Pattern
128: */
129: public function setParameterPattern($Name, $Pattern)
130: {
131:
132: $this->ParameterPattern[$Name] = $Pattern;
133: }
134:
135: /**
136: * @return null|string
137: */
138: public function getPath()
139: {
140:
141: return $this->Path;
142: }
143:
144: }
145: