@@ -873,9 +873,8 @@ protected function createRequest($component, $destination, array $args, $mode)
873
873
if (!$ reflection ->hasCallableMethod ($ method )) {
874
874
throw new InvalidLinkException ("Unknown signal ' $ signal', missing handler {$ reflection ->getName ()}:: $ method() " );
875
875
}
876
- if ($ args ) { // convert indexed parameters to named
877
- self ::argsToParams (get_class ($ component ), $ method , $ args );
878
- }
876
+ // convert indexed parameters to named
877
+ self ::argsToParams (get_class ($ component ), $ method , $ args );
879
878
}
880
879
881
880
// counterpart of IStatePersistent
@@ -901,28 +900,27 @@ protected function createRequest($component, $destination, array $args, $mode)
901
900
$ current = ($ action === '* ' || strcasecmp ($ action , $ this ->action ) === 0 ) && $ presenterClass === get_class ($ this );
902
901
903
902
$ reflection = new PresenterComponentReflection ($ presenterClass );
904
- if ($ args || $ destination === 'this ' ) {
905
- // counterpart of run() & tryCall()
906
- $ method = $ presenterClass ::formatActionMethod ($ action );
903
+
904
+ // counterpart of run() & tryCall()
905
+ $ method = $ presenterClass ::formatActionMethod ($ action );
906
+ if (!$ reflection ->hasCallableMethod ($ method )) {
907
+ $ method = $ presenterClass ::formatRenderMethod ($ action );
907
908
if (!$ reflection ->hasCallableMethod ($ method )) {
908
- $ method = $ presenterClass ::formatRenderMethod ($ action );
909
- if (!$ reflection ->hasCallableMethod ($ method )) {
910
- $ method = NULL ;
911
- }
909
+ $ method = NULL ;
912
910
}
911
+ }
913
912
914
- // convert indexed parameters to named
915
- if ($ method === NULL ) {
916
- if (array_key_exists (0 , $ args )) {
917
- throw new InvalidLinkException ("Unable to pass parameters to action ' $ presenter: $ action', missing corresponding method. " );
918
- }
913
+ // convert indexed parameters to named
914
+ if ($ method === NULL ) {
915
+ if (array_key_exists (0 , $ args )) {
916
+ throw new InvalidLinkException ("Unable to pass parameters to action ' $ presenter: $ action', missing corresponding method. " );
917
+ }
919
918
920
- } elseif ($ destination === 'this ' ) {
921
- self ::argsToParams ($ presenterClass , $ method , $ args , $ this ->params );
919
+ } elseif ($ destination === 'this ' ) {
920
+ self ::argsToParams ($ presenterClass , $ method , $ args , $ this ->params );
922
921
923
- } else {
924
- self ::argsToParams ($ presenterClass , $ method , $ args );
925
- }
922
+ } else {
923
+ self ::argsToParams ($ presenterClass , $ method , $ args );
926
924
}
927
925
928
926
// counterpart of IStatePersistent
@@ -1015,7 +1013,9 @@ public static function argsToParams($class, $method, & $args, $supplemental = []
1015
1013
$ i = 0 ;
1016
1014
$ rm = new \ReflectionMethod ($ class , $ method );
1017
1015
foreach ($ rm ->getParameters () as $ param ) {
1016
+ list ($ type , $ isClass ) = PresenterComponentReflection::getParameterType ($ param );
1018
1017
$ name = $ param ->getName ();
1018
+
1019
1019
if (array_key_exists ($ i , $ args )) {
1020
1020
$ args [$ name ] = $ args [$ i ];
1021
1021
unset($ args [$ i ]);
@@ -1026,16 +1026,15 @@ public static function argsToParams($class, $method, & $args, $supplemental = []
1026
1026
1027
1027
} elseif (array_key_exists ($ name , $ supplemental )) {
1028
1028
$ args [$ name ] = $ supplemental [$ name ];
1029
-
1030
- } else {
1031
- continue ;
1032
1029
}
1033
1030
1034
- if ($ args [$ name ] === NULL ) {
1035
- continue ;
1031
+ if (!isset ($ args [$ name ])) {
1032
+ if ($ param ->isDefaultValueAvailable () || $ type === 'NULL ' || $ type === 'array ' || $ isClass ) {
1033
+ continue ;
1034
+ }
1035
+ throw new InvalidLinkException ("Missing parameter \$$ name required by $ class:: {$ rm ->getName ()}() " );
1036
1036
}
1037
1037
1038
- list ($ type , $ isClass ) = PresenterComponentReflection::getParameterType ($ param );
1039
1038
if (!PresenterComponentReflection::convertType ($ args [$ name ], $ type , $ isClass )) {
1040
1039
throw new InvalidLinkException (sprintf (
1041
1040
'Argument $%s passed to %s() must be %s, %s given. ' ,
@@ -1046,22 +1045,14 @@ public static function argsToParams($class, $method, & $args, $supplemental = []
1046
1045
));
1047
1046
}
1048
1047
1049
- if ($ param ->isDefaultValueAvailable ()) {
1050
- $ def = $ param ->getDefaultValue ();
1051
- } else {
1052
- $ def = NULL ;
1053
- if (!$ isClass ) {
1054
- settype ($ def , $ type );
1055
- }
1056
- }
1048
+ $ def = $ param ->isDefaultValueAvailable () ? $ param ->getDefaultValue () : NULL ;
1057
1049
if ($ args [$ name ] === $ def || ($ def === NULL && $ args [$ name ] === '' )) {
1058
1050
$ args [$ name ] = NULL ; // value transmit is unnecessary
1059
1051
}
1060
1052
}
1061
1053
1062
1054
if (array_key_exists ($ i , $ args )) {
1063
- $ method = $ rm ->getName ();
1064
- throw new InvalidLinkException ("Passed more parameters than method $ class:: $ method() expects. " );
1055
+ throw new InvalidLinkException ("Passed more parameters than method $ class:: {$ rm ->getName ()}() expects. " );
1065
1056
}
1066
1057
}
1067
1058
0 commit comments