@@ -107,19 +107,6 @@ static DWORD orig_cp = 0;
107
107
#define O_BINARY 0
108
108
#endif
109
109
110
- #define PHP_MODE_STANDARD 1
111
- #define PHP_MODE_HIGHLIGHT 2
112
- #define PHP_MODE_LINT 4
113
- #define PHP_MODE_STRIP 5
114
- #define PHP_MODE_CLI_DIRECT 6
115
- #define PHP_MODE_PROCESS_STDIN 7
116
- #define PHP_MODE_REFLECTION_FUNCTION 8
117
- #define PHP_MODE_REFLECTION_CLASS 9
118
- #define PHP_MODE_REFLECTION_EXTENSION 10
119
- #define PHP_MODE_REFLECTION_EXT_INFO 11
120
- #define PHP_MODE_REFLECTION_ZEND_EXTENSION 12
121
- #define PHP_MODE_SHOW_INI_CONFIG 13
122
-
123
110
static cli_shell_callbacks_t cli_shell_callbacks = { NULL , NULL , NULL };
124
111
PHP_CLI_API cli_shell_callbacks_t * php_cli_get_shell_callbacks (void )
125
112
{
@@ -602,7 +589,9 @@ static int do_cli(int argc, char **argv) /* {{{ */
602
589
{
603
590
int c ;
604
591
zend_file_handle file_handle ;
605
- int behavior = PHP_MODE_STANDARD ;
592
+ php_cli_server_context context = {
593
+ .mode = PHP_CLI_MODE_STANDARD
594
+ };
606
595
char * reflection_what = NULL ;
607
596
volatile int request_started = 0 ;
608
597
char * php_optarg = NULL , * orig_optarg = NULL ;
@@ -694,7 +683,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
694
683
break ;
695
684
}
696
685
if (!interactive ) {
697
- if (behavior != PHP_MODE_STANDARD ) {
686
+ if (context . mode != PHP_CLI_MODE_STANDARD ) {
698
687
param_error = param_mode_conflict ;
699
688
break ;
700
689
}
@@ -708,21 +697,21 @@ static int do_cli(int argc, char **argv) /* {{{ */
708
697
break ;
709
698
710
699
case 'F' :
711
- if (behavior == PHP_MODE_PROCESS_STDIN ) {
700
+ if (context . mode == PHP_CLI_MODE_PROCESS_STDIN ) {
712
701
if (exec_run || script_file ) {
713
702
param_error = "You can use -R or -F only once.\n" ;
714
703
break ;
715
704
}
716
- } else if (behavior != PHP_MODE_STANDARD ) {
705
+ } else if (context . mode != PHP_CLI_MODE_STANDARD ) {
717
706
param_error = param_mode_conflict ;
718
707
break ;
719
708
}
720
- behavior = PHP_MODE_PROCESS_STDIN ;
709
+ context . mode = PHP_CLI_MODE_PROCESS_STDIN ;
721
710
script_file = php_optarg ;
722
711
break ;
723
712
724
713
case 'f' : /* parse file */
725
- if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN ) {
714
+ if (context . mode == PHP_CLI_MODE_CLI_DIRECT || context . mode == PHP_CLI_MODE_PROCESS_STDIN ) {
726
715
param_error = param_mode_conflict ;
727
716
break ;
728
717
} else if (script_file ) {
@@ -733,10 +722,10 @@ static int do_cli(int argc, char **argv) /* {{{ */
733
722
break ;
734
723
735
724
case 'l' : /* syntax check mode */
736
- if (behavior != PHP_MODE_STANDARD ) {
725
+ if (context . mode != PHP_CLI_MODE_STANDARD ) {
737
726
break ;
738
727
}
739
- behavior = PHP_MODE_LINT ;
728
+ context . mode = PHP_CLI_MODE_LINT ;
740
729
/* We want to set the error exit status if at least one lint failed.
741
730
* If all were successful we set the exit status to 0.
742
731
* We already set EG(exit_status) here such that only failures set the exit status. */
@@ -748,75 +737,75 @@ static int do_cli(int argc, char **argv) /* {{{ */
748
737
break ;
749
738
750
739
case 'r' : /* run code from command line */
751
- if (behavior == PHP_MODE_CLI_DIRECT ) {
740
+ if (context . mode == PHP_CLI_MODE_CLI_DIRECT ) {
752
741
if (exec_direct || script_file ) {
753
742
param_error = "You can use -r only once.\n" ;
754
743
break ;
755
744
}
756
- } else if (behavior != PHP_MODE_STANDARD || interactive ) {
745
+ } else if (context . mode != PHP_CLI_MODE_STANDARD || interactive ) {
757
746
param_error = param_mode_conflict ;
758
747
break ;
759
748
}
760
- behavior = PHP_MODE_CLI_DIRECT ;
749
+ context . mode = PHP_CLI_MODE_CLI_DIRECT ;
761
750
exec_direct = php_optarg ;
762
751
break ;
763
752
764
753
case 'R' :
765
- if (behavior == PHP_MODE_PROCESS_STDIN ) {
754
+ if (context . mode == PHP_CLI_MODE_PROCESS_STDIN ) {
766
755
if (exec_run || script_file ) {
767
756
param_error = "You can use -R or -F only once.\n" ;
768
757
break ;
769
758
}
770
- } else if (behavior != PHP_MODE_STANDARD ) {
759
+ } else if (context . mode != PHP_CLI_MODE_STANDARD ) {
771
760
param_error = param_mode_conflict ;
772
761
break ;
773
762
}
774
- behavior = PHP_MODE_PROCESS_STDIN ;
763
+ context . mode = PHP_CLI_MODE_PROCESS_STDIN ;
775
764
exec_run = php_optarg ;
776
765
break ;
777
766
778
767
case 'B' :
779
- if (behavior == PHP_MODE_PROCESS_STDIN ) {
768
+ if (context . mode == PHP_CLI_MODE_PROCESS_STDIN ) {
780
769
if (exec_begin ) {
781
770
param_error = "You can use -B only once.\n" ;
782
771
break ;
783
772
}
784
- } else if (behavior != PHP_MODE_STANDARD || interactive ) {
773
+ } else if (context . mode != PHP_CLI_MODE_STANDARD || interactive ) {
785
774
param_error = param_mode_conflict ;
786
775
break ;
787
776
}
788
- behavior = PHP_MODE_PROCESS_STDIN ;
777
+ context . mode = PHP_CLI_MODE_PROCESS_STDIN ;
789
778
exec_begin = php_optarg ;
790
779
break ;
791
780
792
781
case 'E' :
793
- if (behavior == PHP_MODE_PROCESS_STDIN ) {
782
+ if (context . mode == PHP_CLI_MODE_PROCESS_STDIN ) {
794
783
if (exec_end ) {
795
784
param_error = "You can use -E only once.\n" ;
796
785
break ;
797
786
}
798
- } else if (behavior != PHP_MODE_STANDARD || interactive ) {
787
+ } else if (context . mode != PHP_CLI_MODE_STANDARD || interactive ) {
799
788
param_error = param_mode_conflict ;
800
789
break ;
801
790
}
802
- behavior = PHP_MODE_PROCESS_STDIN ;
791
+ context . mode = PHP_CLI_MODE_PROCESS_STDIN ;
803
792
exec_end = php_optarg ;
804
793
break ;
805
794
806
795
case 's' : /* generate highlighted HTML from source */
807
- if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN ) {
796
+ if (context . mode == PHP_CLI_MODE_CLI_DIRECT || context . mode == PHP_CLI_MODE_PROCESS_STDIN ) {
808
797
param_error = "Source highlighting only works for files.\n" ;
809
798
break ;
810
799
}
811
- behavior = PHP_MODE_HIGHLIGHT ;
800
+ context . mode = PHP_CLI_MODE_HIGHLIGHT ;
812
801
break ;
813
802
814
803
case 'w' :
815
- if (behavior == PHP_MODE_CLI_DIRECT || behavior == PHP_MODE_PROCESS_STDIN ) {
804
+ if (context . mode == PHP_CLI_MODE_CLI_DIRECT || context . mode == PHP_CLI_MODE_PROCESS_STDIN ) {
816
805
param_error = "Source stripping only works for files.\n" ;
817
806
break ;
818
807
}
819
- behavior = PHP_MODE_STRIP ;
808
+ context . mode = PHP_CLI_MODE_STRIP ;
820
809
break ;
821
810
822
811
case 'z' : /* load extension file */
@@ -826,27 +815,27 @@ static int do_cli(int argc, char **argv) /* {{{ */
826
815
hide_argv = true;
827
816
break ;
828
817
case 10 :
829
- behavior = PHP_MODE_REFLECTION_FUNCTION ;
818
+ context . mode = PHP_CLI_MODE_REFLECTION_FUNCTION ;
830
819
reflection_what = php_optarg ;
831
820
break ;
832
821
case 11 :
833
- behavior = PHP_MODE_REFLECTION_CLASS ;
822
+ context . mode = PHP_CLI_MODE_REFLECTION_CLASS ;
834
823
reflection_what = php_optarg ;
835
824
break ;
836
825
case 12 :
837
- behavior = PHP_MODE_REFLECTION_EXTENSION ;
826
+ context . mode = PHP_CLI_MODE_REFLECTION_EXTENSION ;
838
827
reflection_what = php_optarg ;
839
828
break ;
840
829
case 13 :
841
- behavior = PHP_MODE_REFLECTION_ZEND_EXTENSION ;
830
+ context . mode = PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION ;
842
831
reflection_what = php_optarg ;
843
832
break ;
844
833
case 14 :
845
- behavior = PHP_MODE_REFLECTION_EXT_INFO ;
834
+ context . mode = PHP_CLI_MODE_REFLECTION_EXT_INFO ;
846
835
reflection_what = php_optarg ;
847
836
break ;
848
837
case 15 :
849
- behavior = PHP_MODE_SHOW_INI_CONFIG ;
838
+ context . mode = PHP_CLI_MODE_SHOW_INI_CONFIG ;
850
839
break ;
851
840
case 16 :
852
841
num_repeats = atoi (php_optarg );
@@ -869,8 +858,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
869
858
is essential to mitigate buggy console info. */
870
859
interactive = php_win32_console_is_own () &&
871
860
!(script_file ||
872
- argc > php_optind && behavior != PHP_MODE_CLI_DIRECT &&
873
- behavior != PHP_MODE_PROCESS_STDIN &&
861
+ argc > php_optind && context . mode != PHP_CLI_MODE_CLI_DIRECT &&
862
+ context . mode != PHP_CLI_MODE_PROCESS_STDIN &&
874
863
strcmp (argv [php_optind - 1 ],"--" )
875
864
);
876
865
}
@@ -890,8 +879,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
890
879
/* only set script_file if not set already and not in direct mode and not at end of parameter list */
891
880
if (argc > php_optind
892
881
&& !script_file
893
- && behavior != PHP_MODE_CLI_DIRECT
894
- && behavior != PHP_MODE_PROCESS_STDIN
882
+ && context . mode != PHP_CLI_MODE_CLI_DIRECT
883
+ && context . mode != PHP_CLI_MODE_PROCESS_STDIN
895
884
&& strcmp (argv [php_optind - 1 ],"--" ))
896
885
{
897
886
script_file = argv [php_optind ];
@@ -910,13 +899,13 @@ static int do_cli(int argc, char **argv) /* {{{ */
910
899
php_self = script_file ;
911
900
}
912
901
} else {
913
- /* We could handle PHP_MODE_PROCESS_STDIN in a different manner */
902
+ /* We could handle PHP_CLI_MODE_PROCESS_STDIN in a different manner */
914
903
/* here but this would make things only more complicated. And it */
915
904
/* is consistent with the way -R works where the stdin file handle*/
916
905
/* is also accessible. */
917
906
php_self = "Standard input code" ;
918
- if (behavior < PHP_MODE_CLI_DIRECT
919
- && ( !interactive || PHP_MODE_STANDARD != PHP_MODE_STANDARD ) ) {
907
+ if (context . mode < PHP_CLI_MODE_CLI_DIRECT
908
+ && !interactive ) {
920
909
zend_stream_init_fp (& file_handle , stdin , php_self );
921
910
file_handle .primary_script = 1 ;
922
911
}
@@ -930,6 +919,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
930
919
SG (request_info ).path_translated = translated_path ? translated_path : php_self ;
931
920
argv [php_optind - 1 ] = php_self ;
932
921
SG (request_info ).argv = argv + php_optind - 1 ;
922
+ SG (server_context ) = & context ;
933
923
934
924
if (php_request_startup ()== FAILURE ) {
935
925
* arg_excp = arg_free ;
@@ -956,8 +946,8 @@ static int do_cli(int argc, char **argv) /* {{{ */
956
946
zend_is_auto_global (ZSTR_KNOWN (ZEND_STR_AUTOGLOBAL_SERVER ));
957
947
958
948
PG (during_request_startup ) = 0 ;
959
- switch (behavior ) {
960
- case PHP_MODE_STANDARD :
949
+ switch (context . mode ) {
950
+ case PHP_CLI_MODE_STANDARD :
961
951
cli_register_file_handles ();
962
952
963
953
if (interactive ) {
@@ -966,21 +956,21 @@ static int do_cli(int argc, char **argv) /* {{{ */
966
956
php_execute_script (& file_handle );
967
957
}
968
958
break ;
969
- case PHP_MODE_LINT :
959
+ case PHP_CLI_MODE_LINT :
970
960
if (php_lint_script (& file_handle ) == SUCCESS ) {
971
961
zend_printf ("No syntax errors detected in %s\n" , php_self );
972
962
} else {
973
963
zend_printf ("Errors parsing %s\n" , php_self );
974
964
EG (exit_status ) = 255 ;
975
965
}
976
966
break ;
977
- case PHP_MODE_STRIP :
967
+ case PHP_CLI_MODE_STRIP :
978
968
if (open_file_for_scanning (& file_handle )== SUCCESS ) {
979
969
zend_strip ();
980
970
}
981
971
goto out ;
982
972
break ;
983
- case PHP_MODE_HIGHLIGHT :
973
+ case PHP_CLI_MODE_HIGHLIGHT :
984
974
{
985
975
zend_syntax_highlighter_ini syntax_highlighter_ini ;
986
976
@@ -991,12 +981,12 @@ static int do_cli(int argc, char **argv) /* {{{ */
991
981
goto out ;
992
982
}
993
983
break ;
994
- case PHP_MODE_CLI_DIRECT :
984
+ case PHP_CLI_MODE_CLI_DIRECT :
995
985
cli_register_file_handles ();
996
986
zend_eval_string_ex (exec_direct , NULL , "Command line code" , 1 );
997
987
break ;
998
988
999
- case PHP_MODE_PROCESS_STDIN :
989
+ case PHP_CLI_MODE_PROCESS_STDIN :
1000
990
{
1001
991
char * input ;
1002
992
size_t len , index = 0 ;
@@ -1042,32 +1032,32 @@ static int do_cli(int argc, char **argv) /* {{{ */
1042
1032
break ;
1043
1033
}
1044
1034
1045
- case PHP_MODE_REFLECTION_FUNCTION :
1046
- case PHP_MODE_REFLECTION_CLASS :
1047
- case PHP_MODE_REFLECTION_EXTENSION :
1048
- case PHP_MODE_REFLECTION_ZEND_EXTENSION :
1035
+ case PHP_CLI_MODE_REFLECTION_FUNCTION :
1036
+ case PHP_CLI_MODE_REFLECTION_CLASS :
1037
+ case PHP_CLI_MODE_REFLECTION_EXTENSION :
1038
+ case PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION :
1049
1039
{
1050
1040
zend_class_entry * pce = NULL ;
1051
1041
zval arg , ref ;
1052
1042
zend_execute_data execute_data ;
1053
1043
1054
- switch (behavior ) {
1044
+ switch (context . mode ) {
1055
1045
default :
1056
1046
break ;
1057
- case PHP_MODE_REFLECTION_FUNCTION :
1047
+ case PHP_CLI_MODE_REFLECTION_FUNCTION :
1058
1048
if (strstr (reflection_what , "::" )) {
1059
1049
pce = reflection_method_ptr ;
1060
1050
} else {
1061
1051
pce = reflection_function_ptr ;
1062
1052
}
1063
1053
break ;
1064
- case PHP_MODE_REFLECTION_CLASS :
1054
+ case PHP_CLI_MODE_REFLECTION_CLASS :
1065
1055
pce = reflection_class_ptr ;
1066
1056
break ;
1067
- case PHP_MODE_REFLECTION_EXTENSION :
1057
+ case PHP_CLI_MODE_REFLECTION_EXTENSION :
1068
1058
pce = reflection_extension_ptr ;
1069
1059
break ;
1070
- case PHP_MODE_REFLECTION_ZEND_EXTENSION :
1060
+ case PHP_CLI_MODE_REFLECTION_ZEND_EXTENSION :
1071
1061
pce = reflection_zend_extension_ptr ;
1072
1062
break ;
1073
1063
}
@@ -1096,7 +1086,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
1096
1086
1097
1087
break ;
1098
1088
}
1099
- case PHP_MODE_REFLECTION_EXT_INFO :
1089
+ case PHP_CLI_MODE_REFLECTION_EXT_INFO :
1100
1090
{
1101
1091
size_t len = strlen (reflection_what );
1102
1092
char * lcname = zend_str_tolower_dup (reflection_what , len );
@@ -1117,7 +1107,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
1117
1107
break ;
1118
1108
}
1119
1109
1120
- case PHP_MODE_SHOW_INI_CONFIG :
1110
+ case PHP_CLI_MODE_SHOW_INI_CONFIG :
1121
1111
{
1122
1112
zend_printf ("Configuration File (php.ini) Path: %s\n" , PHP_CONFIG_FILE_PATH );
1123
1113
zend_printf ("Loaded Configuration File: %s\n" , php_ini_opened_path ? php_ini_opened_path : "(none)" );
@@ -1140,7 +1130,7 @@ static int do_cli(int argc, char **argv) /* {{{ */
1140
1130
free (translated_path );
1141
1131
translated_path = NULL ;
1142
1132
}
1143
- if (behavior == PHP_MODE_LINT && argc > php_optind && strcmp (argv [php_optind ],"--" )) {
1133
+ if (context . mode == PHP_CLI_MODE_LINT && argc > php_optind && strcmp (argv [php_optind ],"--" )) {
1144
1134
script_file = NULL ;
1145
1135
goto do_repeat ;
1146
1136
}
0 commit comments