@@ -179,7 +179,7 @@ public function setOption($name, $value)
179
179
*
180
180
* @param string $name An option name
181
181
*
182
- * @return mixed The option value
182
+ * @return mixed The option value or null when not given
183
183
*/
184
184
public function getOption ($ name )
185
185
{
@@ -236,7 +236,7 @@ public function addDefaults(array $defaults)
236
236
*
237
237
* @param string $name A variable name
238
238
*
239
- * @return mixed The default value
239
+ * @return mixed The default value or null when not given
240
240
*/
241
241
public function getDefault ($ name )
242
242
{
@@ -323,7 +323,7 @@ public function addRequirements(array $requirements)
323
323
*
324
324
* @param string $key The key
325
325
*
326
- * @return string The regex
326
+ * @return string|null The regex or null when not given
327
327
*/
328
328
public function getRequirement ($ key )
329
329
{
@@ -352,6 +352,8 @@ public function setRequirement($key, $regex)
352
352
* Compiles the route.
353
353
*
354
354
* @return CompiledRoute A CompiledRoute instance
355
+ *
356
+ * @see RouteCompiler which is responsible for the compilation process
355
357
*/
356
358
public function compile ()
357
359
{
@@ -371,21 +373,21 @@ public function compile()
371
373
private function sanitizeRequirement ($ key , $ regex )
372
374
{
373
375
if (!is_string ($ regex )) {
374
- throw new \InvalidArgumentException (sprintf ('Routing requirement for "%s" must be a string ' , $ key ));
375
- }
376
-
377
- if ('' === $ regex ) {
378
- throw new \InvalidArgumentException (sprintf ('Routing requirement for "%s" cannot be empty ' , $ key ));
376
+ throw new \InvalidArgumentException (sprintf ('Routing requirement for "%s" must be a string. ' , $ key ));
379
377
}
380
378
381
- if ('^ ' === $ regex [0 ]) {
382
- $ regex = substr ($ regex , 1 );
379
+ if ('' !== $ regex && ' ^ ' === $ regex [0 ]) {
380
+ $ regex = ( string ) substr ($ regex , 1 ); // returns false for a single character
383
381
}
384
382
385
383
if ('$ ' === substr ($ regex , -1 )) {
386
384
$ regex = substr ($ regex , 0 , -1 );
387
385
}
388
386
387
+ if ('' === $ regex ) {
388
+ throw new \InvalidArgumentException (sprintf ('Routing requirement for "%s" cannot be empty. ' , $ key ));
389
+ }
390
+
389
391
return $ regex ;
390
392
}
391
393
}
0 commit comments