10
10
use Nette ;
11
11
use Nette \Application ;
12
12
use Nette \Application \Responses ;
13
+ use Nette \Application \Helpers ;
13
14
use Nette \Http ;
14
15
15
16
@@ -497,8 +498,7 @@ public function findLayoutTemplateFile()
497
498
*/
498
499
public function formatLayoutTemplateFiles ()
499
500
{
500
- $ name = $ this ->getName ();
501
- $ presenter = substr ($ name , strrpos (': ' . $ name , ': ' ));
501
+ list ($ module , $ presenter ) = Helpers::splitName ($ this ->getName ());
502
502
$ layout = $ this ->layout ? $ this ->layout : 'layout ' ;
503
503
$ dir = dirname ($ this ->getReflection ()->getFileName ());
504
504
$ dir = is_dir ("$ dir/templates " ) ? $ dir : dirname ($ dir );
@@ -509,7 +509,7 @@ public function formatLayoutTemplateFiles()
509
509
do {
510
510
$ list [] = "$ dir/templates/@ $ layout.latte " ;
511
511
$ dir = dirname ($ dir );
512
- } while ($ dir && ( $ name = substr ( $ name , 0 , strrpos ( $ name , ' : ' ) )));
512
+ } while ($ dir && $ module && ( list ( $ module ) = Helpers:: splitName ( $ module )));
513
513
return $ list ;
514
514
}
515
515
@@ -520,8 +520,7 @@ public function formatLayoutTemplateFiles()
520
520
*/
521
521
public function formatTemplateFiles ()
522
522
{
523
- $ name = $ this ->getName ();
524
- $ presenter = substr ($ name , strrpos (': ' . $ name , ': ' ));
523
+ list (, $ presenter ) = Helpers::splitName ($ this ->getName ());
525
524
$ dir = dirname ($ this ->getReflection ()->getFileName ());
526
525
$ dir = is_dir ("$ dir/templates " ) ? $ dir : dirname ($ dir );
527
526
return [
@@ -807,13 +806,11 @@ protected function createRequest($component, $destination, array $args, $mode)
807
806
808
807
// 4) signal or empty
809
808
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 , ': ' , '- ' ));
815
812
}
816
- if ($ signal == NULL ) { // intentionally ==
813
+ if ($ signal === '' ) {
817
814
throw new InvalidLinkException ('Signal must be non-empty string. ' );
818
815
}
819
816
$ destination = 'this ' ;
@@ -825,28 +822,21 @@ protected function createRequest($component, $destination, array $args, $mode)
825
822
826
823
// 5) presenter: action
827
824
$ 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 ;
831
828
$ presenter = $ this ->getName ();
832
829
$ presenterClass = get_class ($ this );
833
830
834
831
} 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 ) {
838
835
throw new InvalidLinkException ("Missing presenter name in ' $ destination'. " );
839
836
}
840
- $ presenter = substr ($ destination , 1 , $ a - 1 );
841
-
842
837
} 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 ;
850
840
}
851
841
if (!$ this ->presenterFactory ) {
852
842
throw new Nette \InvalidStateException ('Unable to create link to other presenter, service PresenterFactory has not been set. ' );
0 commit comments