@@ -725,17 +725,11 @@ protected function createRequest(Component $component, string $destination, arra
725725
726726 $ this ->lastCreatedRequest = $ this ->lastCreatedRequestFlag = NULL ;
727727
728- // PARSE DESTINATION
729- if (!preg_match ('~^ (?<absolute>//)?+ (?<path>[^!?#]++) (?<signal>!)?+ (?<query>\?[^#]*)?+ (?<fragment>\#.*)?+ $~x ' , $ destination , $ parts )) {
730- throw new InvalidLinkException ("Invalid destination ' $ destination'. " );
731- }
732-
728+ $ parts = $ this ->parseDestination ($ destination );
733729 $ path = $ parts ['path ' ];
734- if (!empty ($ parts ['query ' ])) {
735- parse_str (substr ($ parts ['query ' ], 1 ), $ args );
736- }
730+ $ args = $ parts ['args ' ] ?? $ args ;
737731
738- if (!$ component instanceof self || ! empty ( $ parts ['signal ' ]) ) {
732+ if (!$ component instanceof self || $ parts ['signal ' ]) {
739733 [$ cname , $ signal ] = Helpers::splitName ($ path );
740734 if ($ cname !== '' ) {
741735 $ component = $ component ->getComponent (strtr ($ cname , ': ' , '- ' ));
@@ -881,7 +875,30 @@ protected function createRequest(Component $component, string $destination, arra
881875
882876 return $ mode === 'forward ' || $ mode === 'test '
883877 ? NULL
884- : $ this ->requestToUrl ($ this ->lastCreatedRequest , $ mode === 'link ' && !$ parts ['absolute ' ]) . ($ parts ['fragment ' ] ?? '' );
878+ : $ this ->requestToUrl ($ this ->lastCreatedRequest , $ mode === 'link ' && !$ parts ['absolute ' ]) . $ parts ['fragment ' ];
879+ }
880+
881+
882+ /**
883+ * Parse destination in format "[//] [[[module:]presenter:]action | signal! | this] [?query] [#fragment]"
884+ * @throws InvalidLinkException
885+ * @internal
886+ */
887+ public static function parseDestination (string $ destination ): array
888+ {
889+ if (!preg_match ('~^ (?<absolute>//)?+ (?<path>[^!?#]++) (?<signal>!)?+ (?<query>\?[^#]*)?+ (?<fragment>\#.*)?+ $~x ' , $ destination , $ matches )) {
890+ throw new InvalidLinkException ("Invalid destination ' $ destination'. " );
891+ }
892+ if (!empty ($ matches ['query ' ])) {
893+ parse_str (substr ($ matches ['query ' ], 1 ), $ args );
894+ }
895+ return [
896+ 'absolute ' => (bool ) $ matches ['absolute ' ],
897+ 'path ' => $ matches ['path ' ],
898+ 'signal ' => !empty ($ matches ['signal ' ]),
899+ 'args ' => $ args ?? NULL ,
900+ 'fragment ' => $ matches ['fragment ' ] ?? '' ,
901+ ];
885902 }
886903
887904
0 commit comments