From e49bf332c4dec2675679f68f1abdde5aedf41e4e Mon Sep 17 00:00:00 2001
From: xiaohengjin <xiaohengjin@youzan.com>
Date: Mon, 17 Jul 2017 19:21:51 +0800
Subject: [PATCH] put path and runmode to env

---
 src/Foundation/Core/Env.php     |  2 --
 src/Foundation/Core/Path.php    | 21 +++++++++++++++++++++
 src/Foundation/Core/RunMode.php | 11 ++++++-----
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/src/Foundation/Core/Env.php b/src/Foundation/Core/Env.php
index 6a011a6b..14b6a969 100644
--- a/src/Foundation/Core/Env.php
+++ b/src/Foundation/Core/Env.php
@@ -35,6 +35,4 @@ public static function set($key, $value)
         self::$data[$key] = $value;
     }
 
-
-
 }
\ No newline at end of file
diff --git a/src/Foundation/Core/Path.php b/src/Foundation/Core/Path.php
index bf7b502a..d5b146c6 100644
--- a/src/Foundation/Core/Path.php
+++ b/src/Foundation/Core/Path.php
@@ -62,6 +62,7 @@ public static function init($rootPath)
         self::setRootPath($rootPath);
         self::setOtherPathes();
         self::setInConfig();
+        self::setInEnv();
     }
 
     public static function getRootPath()
@@ -197,4 +198,24 @@ private static function setInConfig()
         Config::set(self::MQ_WORKER_PATH_CONFIG_KEY, self::$mqWorkerConfigPath);
         Config::set(self::MODULE_CONFIG_PATH_CONFIG_KEY, self::$moduleConfigPath);
     }
+
+    private static function setInEnv()
+    {
+        putenv("path.root=".self::$rootPath);
+        putenv("path.config=".self::$configPath);
+        putenv("path.zan=".self::$zanConfigPath);
+        putenv("path.sql=".self::$sqlPath);
+        putenv("path.log=".self::$logPath);
+        putenv("path.cache=".self::$cachePath);
+        putenv("path.kv=".self::$kvPath);
+        putenv("path.model=".self::$modelPath);
+        putenv("path.table=".self::$tablePath);
+        putenv("path.routing=".self::$routingPath);
+        putenv("path.middleware=".self::$middlewarePath);
+        putenv("path.iron=".self::$ironConfigPath);
+        putenv("path.app=".self::$appConfigPath);
+        putenv("path.cron=".self::$cronConfigPath);
+        putenv("path.mqworker=".self::$mqWorkerConfigPath);
+        putenv("path.module=".self::$moduleConfigPath);
+    }
 }
\ No newline at end of file
diff --git a/src/Foundation/Core/RunMode.php b/src/Foundation/Core/RunMode.php
index 4eb16b57..30f1745e 100644
--- a/src/Foundation/Core/RunMode.php
+++ b/src/Foundation/Core/RunMode.php
@@ -27,6 +27,7 @@ public static function get()
     public static function set($runMode)
     {
         self::$runMode = $runMode;
+        putenv("runMode = $runMode");
     }
 
     public static function detect()
@@ -37,29 +38,29 @@ public static function detect()
 
         $envInput = getenv('KDT_RUN_MODE');
         if ($envInput !== false) {
-            self::$runMode = $envInput;
+            self::set($envInput);
             return;
         }
 
         $iniInput = get_cfg_var('kdt.RUN_MODE');
         if ($iniInput !== false) {
-            self::$runMode = $iniInput;
+            self::set($iniInput);
             return;
         }
 
         $envInput = getenv('ZANPHP_RUN_MODE');
         if ($envInput !== false) {
-            self::$runMode = $envInput;
+            self::set($envInput);
             return;
         }
 
         $iniInput = get_cfg_var('zanphp.RUN_MODE');
         if ($iniInput !== false) {
-            self::$runMode = $iniInput;
+            self::set($iniInput);
             return;
         }
 
-        self::$runMode = 'online';
+        self::set('online');
     }
 
     public static function isOnline()