@@ -19,6 +19,11 @@ class Sandbox
1919     */ 
2020    protected  $ snapshot ;
2121
22+     /** 
23+      * @var \Illuminate\Config\Repository 
24+      */ 
25+     protected  $ config ;
26+ 
2227    /** 
2328     * @var boolean 
2429     */ 
@@ -41,6 +46,7 @@ public static function make(Application $application)
4146    public  function  __construct (Application   $ application )
4247    {
4348        $ this  ->setApplication ($ application );
49+         $ this  ->setInitialConfig ($ application );
4450    }
4551
4652    /** 
@@ -53,6 +59,16 @@ public function setApplication(Application $application)
5359        $ this  ->application  = $ application ;
5460    }
5561
62+     /** 
63+      * Set config snapshot. 
64+      * 
65+      * @param \SwooleTW\Http\Server\Application 
66+      */ 
67+     protected  function  setInitialConfig (Application   $ application )
68+     {
69+         $ this  ->config  = clone  $ application ->getApplication ()['config ' ];
70+     }
71+ 
5672    /** 
5773     * Get an application snapshot 
5874     * 
@@ -75,20 +91,19 @@ public function getApplication()
7591     */ 
7692    protected  function  resetLaravelApp ($ application )
7793    {
78-         if  ($ this  ->isFramework ('laravel ' )) {
79-             $ application ->bootstrapWith ([
80-                 'Illuminate\Foundation\Bootstrap\LoadConfiguration ' 
81-             ]);
82-         } elseif  ($ this  ->isFramework ('lumen ' )) {
83-             $ reflector  = new  \ReflectionMethod (LumenApplication::class, 'registerConfigBindings ' );
84-             $ reflector ->setAccessible (true );
85-             $ reflector ->invoke ($ application );
86-         }
87- 
94+         $ this  ->resetConfigInstance ($ application );
8895        $ this  ->rebindRouterContainer ($ application );
8996        $ this  ->rebindViewContainer ($ application );
9097    }
9198
99+     /** 
100+      * Reset laravel/lumen's config to initial values. 
101+      */ 
102+     protected  function  resetConfigInstance ($ application )
103+     {
104+         $ application ->instance ('config ' , clone  $ this  ->config );
105+     }
106+ 
92107    /** 
93108     * Rebind laravel's container in router. 
94109     */ 
@@ -98,6 +113,14 @@ protected function rebindRouterContainer($application)
98113            $ router  = $ application ->make ('router ' );
99114            $ closure  = function  () use  ($ application ) {
100115                $ this  ->container  = $ application ;
116+                 if  (! isset ($ application ['request ' ])) {
117+                     return ;
118+                 }
119+                 $ route  = $ this  ->routes ->match ($ application ['request ' ]);
120+                 // clear resolved controller 
121+                 if  (property_exists ($ route , 'container ' )) {
122+                     $ route ->controller  = null ;
123+                 }
101124            };
102125
103126            $ resetRouter  = $ closure ->bindTo ($ router , $ router );
0 commit comments