@@ -356,6 +356,9 @@ protected function buildPath(array $parts, array $mergedParams, $isOptional, $ha
356356
357357 public function partialMatch (Request $ request , int $ pathOffset = 0 , array $ options = []): PartialRouteResult
358358 {
359+ if ($ pathOffset < 0 ) {
360+ throw new Exception \InvalidArgumentException ('Route path offset cannot be negative ' );
361+ }
359362 $ path = $ request ->getUri ()->getPath ();
360363
361364 $ regex = $ this ->regex ;
@@ -374,11 +377,7 @@ public function partialMatch(Request $request, int $pathOffset = 0, array $optio
374377 }
375378 }
376379
377- if ($ pathOffset !== null ) {
378- $ result = preg_match ('(\G ' . $ regex . ') ' , $ path , $ matches , 0 , $ pathOffset );
379- } else {
380- $ result = preg_match ('(^ ' . $ regex . '$) ' , $ path , $ matches );
381- }
380+ $ result = preg_match ('(\G ' . $ regex . ') ' , $ path , $ matches , 0 , $ pathOffset );
382381
383382 if (! $ result ) {
384383 return PartialRouteResult::fromRouteFailure ();
@@ -424,7 +423,7 @@ public function assemble(array $params = [], array $options = []) : UriInterface
424423 }
425424 $ uri = $ options ['uri ' ];
426425 if (! $ uri instanceof UriInterface) {
427- throw new Exception \DomainException (\sprintf (
426+ throw new Exception \InvalidArgumentException (\sprintf (
428427 'Route assemble option \'uri \' must be instance of %s, got %s ' ,
429428 UriInterface::class,
430429 (is_object ($ uri ) ? get_class ($ uri ) : gettype ($ uri ))
@@ -452,12 +451,11 @@ public function getLastAssembledParams() : array
452451 */
453452 protected function encode (string $ value )
454453 {
455- $ key = (string ) $ value ;
456- if (! isset (static ::$ cacheEncode [$ key ])) {
457- static ::$ cacheEncode [$ key ] = rawurlencode ($ value );
458- static ::$ cacheEncode [$ key ] = strtr (static ::$ cacheEncode [$ key ], static ::$ urlencodeCorrectionMap );
454+ if (! isset (static ::$ cacheEncode [$ value ])) {
455+ static ::$ cacheEncode [$ value ] = rawurlencode ($ value );
456+ static ::$ cacheEncode [$ value ] = strtr (static ::$ cacheEncode [$ value ], static ::$ urlencodeCorrectionMap );
459457 }
460- return static ::$ cacheEncode [$ key ];
458+ return static ::$ cacheEncode [$ value ];
461459 }
462460
463461 /**
@@ -466,7 +464,7 @@ protected function encode(string $value)
466464 * @param string $value
467465 * @return string
468466 */
469- protected function decode ($ value )
467+ protected function decode (string $ value )
470468 {
471469 return rawurldecode ($ value );
472470 }
0 commit comments