22
33namespace SwooleTW \Http \Server ;
44
5+ use Illuminate \Support \ServiceProvider ;
56use Illuminate \Container \Container ;
67use Illuminate \Contracts \Http \Kernel ;
78use Illuminate \Http \Request ;
@@ -34,6 +35,13 @@ class Application
3435 */
3536 protected $ kernel ;
3637
38+ /**
39+ * Preserved service providers to be reset.
40+ *
41+ * @var array
42+ */
43+ protected $ providers = [];
44+
3745 /**
3846 * Make an application.
3947 *
@@ -58,6 +66,7 @@ public function __construct($framework, $basePath = null)
5866 $ this ->setBasePath ($ basePath );
5967
6068 $ this ->bootstrap ();
69+ $ this ->initProviders ();
6170 }
6271
6372 /**
@@ -71,6 +80,38 @@ protected function bootstrap()
7180 }
7281 }
7382
83+ /**
84+ * Initialize customized service providers.
85+ */
86+ protected function initProviders ()
87+ {
88+ $ app = $ this ->getApplication ();
89+ $ providers = $ app ['config ' ]->get ('swoole_http.providers ' );
90+
91+ foreach ($ providers as $ provider ) {
92+ if (! $ provider instanceof ServiceProvider) {
93+ $ provider = new $ provider ($ app );
94+ }
95+ $ this ->providers [get_class ($ provider )] = $ provider ;
96+ }
97+ }
98+
99+ /**
100+ * Re-register and reboot service providers.
101+ */
102+ public function resetProviders ()
103+ {
104+ foreach ($ this ->providers as $ key => $ provider ) {
105+ if (method_exists ($ provider , 'register ' )) {
106+ $ provider ->register ();
107+ }
108+
109+ if (method_exists ($ provider , 'boot ' )) {
110+ $ this ->getApplication ()->call ([$ provider , 'boot ' ]);
111+ }
112+ }
113+ }
114+
74115 /**
75116 * Load application.
76117 *
0 commit comments