1 | <?php |
||
10 | class ControllerContainer |
||
11 | { |
||
12 | 4 | public function __construct($className) |
|
16 | /** |
||
17 | * 添加路由 |
||
18 | * @param Route $route |
||
19 | * @param string $actionName class method |
||
20 | * @return void |
||
21 | */ |
||
22 | 4 | public function addRoute($actionName, Route $route) |
|
27 | /** |
||
28 | * 获取路由列表 |
||
29 | * @return Route[] |
||
30 | */ |
||
31 | 2 | public function getRoutes() |
|
35 | |||
36 | /** |
||
37 | * 获取路由列表 |
||
38 | * @param Route[] $routes |
||
39 | */ |
||
40 | public function setRoutes($routes) |
||
44 | /** |
||
45 | * 获取指定名称的路由 |
||
46 | * @param $actionName |
||
47 | * @return Route|false |
||
48 | */ |
||
49 | 7 | public function getRoute($actionName) |
|
56 | |||
57 | 1 | static public function dispatch( |
|
67 | |||
68 | // /** |
||
69 | // * 应用路由, 使路由生效 |
||
70 | // * @param RouteCollector $r |
||
71 | // * @return RouteCollector |
||
72 | // */ |
||
73 | // public function build(RouteCollector $r) |
||
74 | // { |
||
75 | // foreach ($this->routes as $actionName=>$route){ |
||
76 | // $r->addRoute( |
||
77 | // $route->getMethod(), |
||
78 | // $route->getUri(), |
||
79 | // new SerializableFunc(self::class.'::dispatch', $this->className, $actionName, $route) |
||
80 | // ); |
||
81 | // } |
||
82 | // return $r; |
||
83 | // } |
||
84 | |||
85 | /** |
||
86 | * @return string |
||
87 | */ |
||
88 | 4 | public function getClassName() |
|
92 | |||
93 | /** |
||
94 | * 获取uri前缀 |
||
95 | * @return string |
||
96 | */ |
||
97 | 4 | public function getUriPrefix() |
|
98 | { |
||
99 | 4 | return $this->prefix; |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * 设置uri前缀 |
||
104 | * @param string $prefix |
||
105 | */ |
||
106 | 4 | public function setUriPrefix($prefix) |
|
107 | { |
||
108 | 4 | $this->prefix = $prefix; |
|
109 | 4 | } |
|
110 | |||
111 | /** |
||
112 | * @return string |
||
113 | */ |
||
114 | public function getFileName() |
||
118 | |||
119 | /** |
||
120 | * @param string $fileName |
||
121 | */ |
||
122 | 4 | public function setFileName($fileName) |
|
126 | |||
127 | /** |
||
128 | * @param string $description |
||
129 | */ |
||
130 | 4 | public function setDescription($description) |
|
134 | |||
135 | /** |
||
136 | * @return string |
||
137 | */ |
||
138 | 1 | public function getDescription() |
|
142 | |||
143 | /** |
||
144 | * @return string |
||
145 | */ |
||
146 | 1 | public function getSummary() |
|
150 | |||
151 | /** |
||
152 | * @param string $summary |
||
153 | */ |
||
154 | 4 | public function setSummary($summary) |
|
158 | |||
159 | /** |
||
160 | * @var string |
||
161 | * the prefix path for all routes of the controller |
||
162 | */ |
||
163 | private $prefix; |
||
164 | |||
165 | /** |
||
166 | * @var string |
||
167 | */ |
||
168 | private $className; |
||
169 | |||
170 | /** |
||
171 | * @var Route[] |
||
172 | */ |
||
173 | private $routes=[]; |
||
174 | |||
175 | /** |
||
176 | * @var string |
||
177 | */ |
||
178 | private $description=''; |
||
179 | /** |
||
180 | * @var string |
||
181 | */ |
||
182 | private $summary=''; |
||
183 | |||
184 | /** |
||
185 | * @var string |
||
186 | */ |
||
187 | private $fileName; |
||
188 | } |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.