소스 검색

[php] fixed `Sys.environment()` to also return variables set by `Sys.putEnv()`

Alexander Kuzmenko 8 년 전
부모
커밋
b57b85aafa
4개의 변경된 파일12개의 추가작업 그리고 17개의 파일을 삭제
  1. 1 0
      extra/CHANGES.txt
  2. 9 2
      std/php/_std/Sys.hx
  3. 0 13
      tests/sys/compile-php7.hxml
  4. 2 2
      tests/sys/src/TestSys.hx

+ 1 - 0
extra/CHANGES.txt

@@ -12,6 +12,7 @@
 
 	js : fixed saving setter to `tmp` var before invocation (#6672)
 	php : don't fail on generating import aliases for classes with the similar names (#6680)
+	php : fixed `Sys.environment()` to also return variables set by `Sys.putEnv()`
 
 2017-10-08: 4.0.0-preview.2
 

+ 9 - 2
std/php/_std/Sys.hx

@@ -25,6 +25,8 @@ import sys.io.FileOutput;
 import sys.io.FileInput;
 
 @:coreApi class Sys {
+	/** Environment variables set by `Sys.putEnv()` */
+	static var customEnvVars = new NativeAssocArray<String>();
 
 	public static inline function print( v : Dynamic ) : Void {
 		Global.echo(Std.string(v));
@@ -48,7 +50,8 @@ import sys.io.FileInput;
 		return value == false ? null : value;
 	}
 
-	public static inline function putEnv( s : String, v : String ) : Void {
+	public static function putEnv( s : String, v : String ) : Void {
+		customEnvVars[s] = '$v'; //in case of `null` it should become `"null"`
 		Global.putenv('$s=$v');
 	}
 
@@ -117,7 +120,11 @@ import sys.io.FileInput;
 	}
 
 	public static function environment() : Map<String,String> {
-		return php.Lib.hashOfAssociativeArray(SuperGlobal._SERVER);
+		var env = SuperGlobal._SERVER;
+		Syntax.foreach(customEnvVars, function(name:String, value:String) {
+			env[name] = value;
+		});
+		return php.Lib.hashOfAssociativeArray(env);
 	}
 
 	public static function stdin() : haxe.io.Input {

+ 0 - 13
tests/sys/compile-php7.hxml

@@ -1,13 +0,0 @@
-compile-each.hxml
--main Main
--php bin/php/Main
-
---next
-compile-each.hxml
--main TestArguments
--php bin/php/TestArguments
-
---next
-compile-each.hxml
--main ExitCode
--php bin/php/ExitCode

+ 2 - 2
tests/sys/src/TestSys.hx

@@ -6,13 +6,13 @@ class TestSys extends TestCommandBase {
 	}
 
 	function testEnv() {
-		#if !(java || php || lua)
+		#if !(java || lua)
 		Sys.putEnv("foo", "value");
 		Assert.equals("value", Sys.getEnv("foo"));
 		#end
 		Assert.equals(null, Sys.getEnv("doesn't exist"));
 
-		#if !(java || php || lua)
+		#if !(java || lua)
 		var env = Sys.environment();
 		Assert.equals("value", env.get("foo"));
 		#end