1010use Nette ;
1111use Nette \Application ;
1212use Nette \Application \Responses ;
13+ use Nette \Application \Helpers ;
1314use Nette \Http ;
1415
1516
@@ -497,8 +498,7 @@ public function findLayoutTemplateFile()
497498 */
498499 public function formatLayoutTemplateFiles ()
499500 {
500- $ name = $ this ->getName ();
501- $ presenter = substr ($ name , strrpos (': ' . $ name , ': ' ));
501+ list ($ module , $ presenter ) = Helpers::splitName ($ this ->getName ());
502502 $ layout = $ this ->layout ? $ this ->layout : 'layout ' ;
503503 $ dir = dirname ($ this ->getReflection ()->getFileName ());
504504 $ dir = is_dir ("$ dir/templates " ) ? $ dir : dirname ($ dir );
@@ -509,7 +509,7 @@ public function formatLayoutTemplateFiles()
509509 do {
510510 $ list [] = "$ dir/templates/@ $ layout.latte " ;
511511 $ dir = dirname ($ dir );
512- } while ($ dir && ( $ name = substr ( $ name , 0 , strrpos ( $ name , ' : ' ) )));
512+ } while ($ dir && $ module && ( list ( $ module ) = Helpers:: splitName ( $ module )));
513513 return $ list ;
514514 }
515515
@@ -520,8 +520,7 @@ public function formatLayoutTemplateFiles()
520520 */
521521 public function formatTemplateFiles ()
522522 {
523- $ name = $ this ->getName ();
524- $ presenter = substr ($ name , strrpos (': ' . $ name , ': ' ));
523+ list (, $ presenter ) = Helpers::splitName ($ this ->getName ());
525524 $ dir = dirname ($ this ->getReflection ()->getFileName ());
526525 $ dir = is_dir ("$ dir/templates " ) ? $ dir : dirname ($ dir );
527526 return [
@@ -807,13 +806,11 @@ protected function createRequest($component, $destination, array $args, $mode)
807806
808807 // 4) signal or empty
809808 if (!$ component instanceof self || substr ($ destination , -1 ) === '! ' ) {
810- $ signal = rtrim ($ destination , '! ' );
811- $ a = strrpos ($ signal , ': ' );
812- if ($ a !== FALSE ) {
813- $ component = $ component ->getComponent (strtr (substr ($ signal , 0 , $ a ), ': ' , '- ' ));
814- $ signal = (string ) substr ($ signal , $ a + 1 );
809+ list ($ cname , $ signal ) = Helpers::splitName (rtrim ($ destination , '! ' ));
810+ if ($ cname !== '' ) {
811+ $ component = $ component ->getComponent (strtr ($ cname , ': ' , '- ' ));
815812 }
816- if ($ signal == NULL ) { // intentionally ==
813+ if ($ signal === '' ) {
817814 throw new InvalidLinkException ('Signal must be non-empty string. ' );
818815 }
819816 $ destination = 'this ' ;
@@ -825,28 +822,21 @@ protected function createRequest($component, $destination, array $args, $mode)
825822
826823 // 5) presenter: action
827824 $ current = FALSE ;
828- $ a = strrpos ($ destination, ' : ' );
829- if ($ a === FALSE ) {
830- $ action = $ destination === 'this ' ? $ this ->action : $ destination ;
825+ list ( $ presenter , $ action ) = Helpers:: splitName ($ destination );
826+ if ($ presenter === '' ) {
827+ $ action = $ destination === 'this ' ? $ this ->action : $ action ;
831828 $ presenter = $ this ->getName ();
832829 $ presenterClass = get_class ($ this );
833830
834831 } else {
835- $ action = ( string ) substr ( $ destination , $ a + 1 );
836- if ( $ destination [ 0 ] === ' : ' ) { // absolute
837- if ($ a < 2 ) {
832+ if ( $ presenter [ 0 ] === ' : ' ) { // absolute
833+ $ presenter = substr ( $ presenter , 1 );
834+ if (! $ presenter ) {
838835 throw new InvalidLinkException ("Missing presenter name in ' $ destination'. " );
839836 }
840- $ presenter = substr ($ destination , 1 , $ a - 1 );
841-
842837 } else { // relative
843- $ presenter = $ this ->getName ();
844- $ b = strrpos ($ presenter , ': ' );
845- if ($ b === FALSE ) { // no module
846- $ presenter = substr ($ destination , 0 , $ a );
847- } else { // with module
848- $ presenter = substr ($ presenter , 0 , $ b + 1 ) . substr ($ destination , 0 , $ a );
849- }
838+ list ($ module , , $ sep ) = Helpers::splitName ($ this ->getName ());
839+ $ presenter = $ module . $ sep . $ presenter ;
850840 }
851841 if (!$ this ->presenterFactory ) {
852842 throw new Nette \InvalidStateException ('Unable to create link to other presenter, service PresenterFactory has not been set. ' );
0 commit comments