@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | use WPB\Application; |
17 | 17 | |
18 | 18 | $app = ( new Application( |
19 | - array( |
|
20 | - 'paths' => array( |
|
21 | - 'root' => WPB_APP_ROOT, |
|
22 | - ), |
|
23 | - ) |
|
19 | + array( |
|
20 | + 'paths' => array( |
|
21 | + 'root' => WPB_APP_ROOT, |
|
22 | + ), |
|
23 | + ) |
|
24 | 24 | ) ); |
25 | 25 | |
26 | 26 | global $wpb_app; |
@@ -28,27 +28,27 @@ discard block |
||
28 | 28 | $wpb_app = $container = $app->get_instance(); |
29 | 29 | |
30 | 30 | $container->singleton( |
31 | - Illuminate\Contracts\Http\Kernel::class, |
|
32 | - \WPB\App\Http\Kernel::class |
|
31 | + Illuminate\Contracts\Http\Kernel::class, |
|
32 | + \WPB\App\Http\Kernel::class |
|
33 | 33 | ); |
34 | 34 | $container->singleton( |
35 | - \Illuminate\Contracts\Debug\ExceptionHandler::class, |
|
36 | - \WPB\App\Exceptions\Handler::class |
|
35 | + \Illuminate\Contracts\Debug\ExceptionHandler::class, |
|
36 | + \WPB\App\Exceptions\Handler::class |
|
37 | 37 | ); |
38 | 38 | |
39 | 39 | if ( \WPB\Support\Facades\Route::exists( \Illuminate\Http\Request::capture() ) ) { |
40 | - try { |
|
40 | + try { |
|
41 | 41 | |
42 | - $kernel = $container->make( \Illuminate\Contracts\Http\Kernel::class ); |
|
42 | + $kernel = $container->make( \Illuminate\Contracts\Http\Kernel::class ); |
|
43 | 43 | |
44 | - $response = $kernel->handle( \Illuminate\Http\Request::capture() ); |
|
44 | + $response = $kernel->handle( \Illuminate\Http\Request::capture() ); |
|
45 | 45 | |
46 | - $response->send(); |
|
46 | + $response->send(); |
|
47 | 47 | |
48 | - } catch ( \Exception $ex ) { |
|
49 | - if ( ! \WPB\Support\Facades\Route::current() ) { |
|
50 | - return true; |
|
51 | - } |
|
52 | - throw new \Exception( $ex, 1 ); |
|
53 | - } |
|
48 | + } catch ( \Exception $ex ) { |
|
49 | + if ( ! \WPB\Support\Facades\Route::current() ) { |
|
50 | + return true; |
|
51 | + } |
|
52 | + throw new \Exception( $ex, 1 ); |
|
53 | + } |
|
54 | 54 | } |
@@ -31,60 +31,60 @@ discard block |
||
31 | 31 | use Illuminate\Contracts\Broadcasting\Factory as BroadcastFactory; |
32 | 32 | |
33 | 33 | if ( ! function_exists( 'wpb_csrf_token' ) ) { |
34 | - /** |
|
35 | - * Generate wp nonce. |
|
36 | - * |
|
37 | - * @param string|null $action This is the nonce action name. |
|
38 | - * |
|
39 | - * @return null|string |
|
40 | - */ |
|
41 | - function wpb_csrf_token( $action = 'wpb_nonce' ) { |
|
42 | - return wp_create_nonce( $action ); |
|
43 | - } |
|
34 | + /** |
|
35 | + * Generate wp nonce. |
|
36 | + * |
|
37 | + * @param string|null $action This is the nonce action name. |
|
38 | + * |
|
39 | + * @return null|string |
|
40 | + */ |
|
41 | + function wpb_csrf_token( $action = 'wpb_nonce' ) { |
|
42 | + return wp_create_nonce( $action ); |
|
43 | + } |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | if ( ! function_exists( 'wpb_config' ) ) { |
47 | - /** |
|
48 | - * Get / set the specified configuration value. |
|
49 | - * |
|
50 | - * If an array is passed as the key, we will assume you want to set an array of values. |
|
51 | - * |
|
52 | - * @param array|string|null $key This is the key for config array. |
|
53 | - * @param mixed $default This is the default config value. |
|
54 | - * |
|
55 | - * @return mixed|\Illuminate\Config\Repository |
|
56 | - */ |
|
57 | - function wpb_config( $key = null, $default = null ) { |
|
58 | - if ( is_null( $key ) ) { |
|
59 | - return app( 'config' ); |
|
60 | - } |
|
61 | - |
|
62 | - if ( is_array( $key ) ) { |
|
63 | - return app( 'config' )->set( $key ); |
|
64 | - } |
|
65 | - |
|
66 | - return app( 'config' )->get( $key, $default ); |
|
67 | - } |
|
47 | + /** |
|
48 | + * Get / set the specified configuration value. |
|
49 | + * |
|
50 | + * If an array is passed as the key, we will assume you want to set an array of values. |
|
51 | + * |
|
52 | + * @param array|string|null $key This is the key for config array. |
|
53 | + * @param mixed $default This is the default config value. |
|
54 | + * |
|
55 | + * @return mixed|\Illuminate\Config\Repository |
|
56 | + */ |
|
57 | + function wpb_config( $key = null, $default = null ) { |
|
58 | + if ( is_null( $key ) ) { |
|
59 | + return app( 'config' ); |
|
60 | + } |
|
61 | + |
|
62 | + if ( is_array( $key ) ) { |
|
63 | + return app( 'config' )->set( $key ); |
|
64 | + } |
|
65 | + |
|
66 | + return app( 'config' )->get( $key, $default ); |
|
67 | + } |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | if ( ! function_exists( 'wpb_view' ) ) { |
71 | - /** |
|
72 | - * Render blade view. |
|
73 | - * |
|
74 | - * @param string $view This is the filename. |
|
75 | - * @param array $data This is the view data. |
|
76 | - * @param array $merge_data This is the merge data for view. |
|
77 | - * |
|
78 | - * @throws \Exception This will throw an exception if view class doesn't exists. |
|
79 | - * @return null|string |
|
80 | - */ |
|
81 | - function wpb_view( $view, $data = array(), $merge_data = array() ) { |
|
82 | - if ( ! class_exists( \CodexShaper\Blade\View::class ) ) { |
|
83 | - throw new \Exception( 'View not resolved. Please install View' ); |
|
84 | - } |
|
85 | - |
|
86 | - return ( new \CodexShaper\Blade\View( array( __DIR__ . '/../resources/views' ), __DIR__ . '/../storage/cache' ) )->make( $view, $data = array(), $merge_data = array() ); |
|
87 | - } |
|
71 | + /** |
|
72 | + * Render blade view. |
|
73 | + * |
|
74 | + * @param string $view This is the filename. |
|
75 | + * @param array $data This is the view data. |
|
76 | + * @param array $merge_data This is the merge data for view. |
|
77 | + * |
|
78 | + * @throws \Exception This will throw an exception if view class doesn't exists. |
|
79 | + * @return null|string |
|
80 | + */ |
|
81 | + function wpb_view( $view, $data = array(), $merge_data = array() ) { |
|
82 | + if ( ! class_exists( \CodexShaper\Blade\View::class ) ) { |
|
83 | + throw new \Exception( 'View not resolved. Please install View' ); |
|
84 | + } |
|
85 | + |
|
86 | + return ( new \CodexShaper\Blade\View( array( __DIR__ . '/../resources/views' ), __DIR__ . '/../storage/cache' ) )->make( $view, $data = array(), $merge_data = array() ); |
|
87 | + } |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | if (! function_exists('wpb_abort')) { |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | function wpb_app($abstract = null, array $parameters = []) |
180 | 180 | { |
181 | - global $wpb_app; |
|
181 | + global $wpb_app; |
|
182 | 182 | |
183 | 183 | if (is_null($abstract)) { |
184 | 184 | return $wpb_app; |
@@ -30,256 +30,256 @@ |
||
30 | 30 | */ |
31 | 31 | class Application { |
32 | 32 | |
33 | - /** |
|
34 | - * The app container. |
|
35 | - * |
|
36 | - * @since 1.0.0 |
|
37 | - * @access protected |
|
38 | - * @var \Illuminate\Contracts\Container\Container $app The app container. |
|
39 | - */ |
|
40 | - protected $app = null; |
|
41 | - |
|
42 | - /** |
|
43 | - * The config. |
|
44 | - * |
|
45 | - * @since 1.0.0 |
|
46 | - * @access protected |
|
47 | - * @var \WPB\Support\Facades\Config $config The config. |
|
48 | - */ |
|
49 | - protected $config; |
|
50 | - |
|
51 | - /** |
|
52 | - * The database manager. |
|
53 | - * |
|
54 | - * @since 1.0.0 |
|
55 | - * @access protected |
|
56 | - * @var \CodexShaper\Database\Database $db The database manager. |
|
57 | - */ |
|
58 | - protected $db; |
|
59 | - |
|
60 | - /** |
|
61 | - * The default options. |
|
62 | - * |
|
63 | - * @since 1.0.0 |
|
64 | - * @access protected |
|
65 | - * @var array $options The default options. |
|
66 | - */ |
|
67 | - protected $options; |
|
68 | - |
|
69 | - /** |
|
70 | - * This string unique root path. |
|
71 | - * |
|
72 | - * @since 1.0.0 |
|
73 | - * @access protected |
|
74 | - * @var string $root This string unique root path. |
|
75 | - */ |
|
76 | - protected $root; |
|
77 | - |
|
78 | - /** |
|
79 | - * The application factory. |
|
80 | - * |
|
81 | - * @since 1.0.0 |
|
82 | - * @param array $options The site options. |
|
83 | - * @param \Illuminate\Contracts\Container\Container as ContainerInterface $container The app container. |
|
84 | - * |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public function __construct( $options = array(), ContainerInterface $container = null ) { |
|
88 | - $this->options = $options; |
|
89 | - |
|
90 | - $this->app = $container; |
|
91 | - |
|
92 | - if ( is_null( $this->app ) ) { |
|
93 | - $this->app = new Container(); |
|
94 | - Facade::setFacadeApplication( $this->app ); |
|
95 | - $this->app->instance( ContainerInterface::class, $this->app ); |
|
96 | - } |
|
97 | - |
|
98 | - $this->app['app'] = $this->app; |
|
99 | - |
|
100 | - $this->root = __DIR__ . '/../../../../'; |
|
101 | - |
|
102 | - if ( ! empty( $this->options ) && isset( $this->options['paths']['root'] ) ) { |
|
103 | - $this->root = rtrim( $this->options['paths']['root'], '/' ) . '/'; |
|
104 | - } |
|
105 | - |
|
106 | - if ( ! isset( $this->app['root'] ) ) { |
|
107 | - $this->app['root'] = $this->root; |
|
108 | - } |
|
109 | - |
|
110 | - $this->config = new Config( $this->options ); |
|
111 | - |
|
112 | - $this->setup_env(); |
|
113 | - $this->register_config(); |
|
114 | - $this->setup_database(); |
|
115 | - $this->register_providers(); |
|
116 | - $this->register_request(); |
|
117 | - $this->register_instances(); |
|
118 | - $this->load_routes( $this->app['router'] ); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Get the app container. |
|
123 | - * |
|
124 | - * @since 1.0.0 |
|
125 | - * |
|
126 | - * @return \Illuminate\Container\Container |
|
127 | - */ |
|
128 | - public function get_instance() { |
|
129 | - if ( ! $this->app ) { |
|
130 | - new self(); |
|
131 | - } |
|
132 | - |
|
133 | - return $this->app; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Setup the env. |
|
138 | - * |
|
139 | - * @since 1.0.0 |
|
140 | - * |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - protected function setup_env() { |
|
144 | - $this->app['env'] = $this->config->get( 'app.env' ); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Register config. |
|
149 | - * |
|
150 | - * @since 1.0.0 |
|
151 | - * |
|
152 | - * @return void |
|
153 | - */ |
|
154 | - protected function register_config() { |
|
155 | - $this->app->bind( |
|
156 | - 'config', |
|
157 | - function () { |
|
158 | - return array( |
|
159 | - 'app' => $this->config->get( 'app' ), |
|
160 | - 'view.paths' => $this->config->get( 'view.paths' ), |
|
161 | - 'view.compiled' => $this->config->get( 'view.compiled' ), |
|
162 | - ); |
|
163 | - }, |
|
164 | - true |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Setup the database. |
|
170 | - * |
|
171 | - * @since 1.0.0 |
|
172 | - * |
|
173 | - * @return void |
|
174 | - */ |
|
175 | - protected function setup_database() { |
|
176 | - global $wpdb; |
|
177 | - |
|
178 | - $this->db = new Database( |
|
179 | - array( |
|
180 | - 'driver' => 'mysql', |
|
181 | - 'host' => $wpdb->dbhost, |
|
182 | - 'database' => $wpdb->dbname, |
|
183 | - 'username' => $wpdb->dbuser, |
|
184 | - 'password' => $wpdb->dbpassword, |
|
185 | - 'prefix' => $wpdb->prefix, |
|
186 | - 'charset' => $wpdb->charset, |
|
187 | - 'collation' => $wpdb->collate, |
|
188 | - ) |
|
189 | - ); |
|
190 | - |
|
191 | - $this->db->run(); |
|
192 | - |
|
193 | - $this->app->singleton( |
|
194 | - 'db', |
|
195 | - function () { |
|
196 | - return $this->db; |
|
197 | - } |
|
198 | - ); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Register providers. |
|
203 | - * |
|
204 | - * @since 1.0.0 |
|
205 | - * |
|
206 | - * @return void |
|
207 | - */ |
|
208 | - protected function register_providers() { |
|
209 | - $providers = $this->config->get( 'app.providers' ); |
|
210 | - |
|
211 | - if ( $providers && count( $providers ) > 0 ) { |
|
212 | - foreach ( $providers as $provider ) { |
|
213 | - with( new $provider( $this->app ) )->register(); |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Register request. |
|
220 | - * |
|
221 | - * @since 1.0.0 |
|
222 | - * |
|
223 | - * @return void |
|
224 | - */ |
|
225 | - protected function register_request() { |
|
226 | - $this->app->bind( |
|
227 | - 'request', |
|
228 | - function ( $app ) { |
|
229 | - $request = Request::capture(); |
|
230 | - $wp_user = wp_get_current_user(); |
|
231 | - if ( $wp_user ) { |
|
232 | - $user = User::find( $wp_user->ID ); |
|
233 | - $request->merge( array( 'user' => $user ) ); |
|
234 | - $request->setUserResolver( |
|
235 | - function () use ( $user ) { |
|
236 | - return $user; |
|
237 | - } |
|
238 | - ); |
|
239 | - } |
|
240 | - |
|
241 | - return $request; |
|
242 | - } |
|
243 | - ); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Register router. |
|
248 | - * |
|
249 | - * @since 1.0.0 |
|
250 | - * |
|
251 | - * @return void |
|
252 | - */ |
|
253 | - protected function register_instances() { |
|
254 | - $this->app->instance( \Illuminate\Http\Request::class, $this->app['request'] ); |
|
255 | - $this->app->instance( \Illuminate\Routing\Router::class, $this->app['router'] ); |
|
256 | - $this->app->instance( \WPB\Router::class, $this->app['router'] ); |
|
257 | - $this->app->instance( \Illuminate\Contracts\View\Factory::class, $this->app['view'] ); |
|
258 | - $this->app->instance( \Illuminate\Contracts\Routing\UrlGenerator::class, $this->app['url'] ); |
|
259 | - $this->app->alias( 'Route', \WPB\Support\Facades\Route::class ); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Get the config value. |
|
264 | - * |
|
265 | - * @since 1.0.0 |
|
266 | - * @param \Illuminate\Routing\Router $router The app router. |
|
267 | - * @param string $dir The custom routes directory. |
|
268 | - * |
|
269 | - * @return void |
|
270 | - */ |
|
271 | - public function load_routes( $router, $dir = null ) { |
|
272 | - if ( ! $dir ) { |
|
273 | - $dir = __DIR__ . '/../routes/'; |
|
274 | - } |
|
275 | - |
|
276 | - require $dir . 'web.php'; |
|
277 | - |
|
278 | - $router->group( |
|
279 | - array( 'prefix' => 'api' ), |
|
280 | - function () use ( $dir, $router ) { |
|
281 | - require $dir . 'api.php'; |
|
282 | - } |
|
283 | - ); |
|
284 | - } |
|
33 | + /** |
|
34 | + * The app container. |
|
35 | + * |
|
36 | + * @since 1.0.0 |
|
37 | + * @access protected |
|
38 | + * @var \Illuminate\Contracts\Container\Container $app The app container. |
|
39 | + */ |
|
40 | + protected $app = null; |
|
41 | + |
|
42 | + /** |
|
43 | + * The config. |
|
44 | + * |
|
45 | + * @since 1.0.0 |
|
46 | + * @access protected |
|
47 | + * @var \WPB\Support\Facades\Config $config The config. |
|
48 | + */ |
|
49 | + protected $config; |
|
50 | + |
|
51 | + /** |
|
52 | + * The database manager. |
|
53 | + * |
|
54 | + * @since 1.0.0 |
|
55 | + * @access protected |
|
56 | + * @var \CodexShaper\Database\Database $db The database manager. |
|
57 | + */ |
|
58 | + protected $db; |
|
59 | + |
|
60 | + /** |
|
61 | + * The default options. |
|
62 | + * |
|
63 | + * @since 1.0.0 |
|
64 | + * @access protected |
|
65 | + * @var array $options The default options. |
|
66 | + */ |
|
67 | + protected $options; |
|
68 | + |
|
69 | + /** |
|
70 | + * This string unique root path. |
|
71 | + * |
|
72 | + * @since 1.0.0 |
|
73 | + * @access protected |
|
74 | + * @var string $root This string unique root path. |
|
75 | + */ |
|
76 | + protected $root; |
|
77 | + |
|
78 | + /** |
|
79 | + * The application factory. |
|
80 | + * |
|
81 | + * @since 1.0.0 |
|
82 | + * @param array $options The site options. |
|
83 | + * @param \Illuminate\Contracts\Container\Container as ContainerInterface $container The app container. |
|
84 | + * |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public function __construct( $options = array(), ContainerInterface $container = null ) { |
|
88 | + $this->options = $options; |
|
89 | + |
|
90 | + $this->app = $container; |
|
91 | + |
|
92 | + if ( is_null( $this->app ) ) { |
|
93 | + $this->app = new Container(); |
|
94 | + Facade::setFacadeApplication( $this->app ); |
|
95 | + $this->app->instance( ContainerInterface::class, $this->app ); |
|
96 | + } |
|
97 | + |
|
98 | + $this->app['app'] = $this->app; |
|
99 | + |
|
100 | + $this->root = __DIR__ . '/../../../../'; |
|
101 | + |
|
102 | + if ( ! empty( $this->options ) && isset( $this->options['paths']['root'] ) ) { |
|
103 | + $this->root = rtrim( $this->options['paths']['root'], '/' ) . '/'; |
|
104 | + } |
|
105 | + |
|
106 | + if ( ! isset( $this->app['root'] ) ) { |
|
107 | + $this->app['root'] = $this->root; |
|
108 | + } |
|
109 | + |
|
110 | + $this->config = new Config( $this->options ); |
|
111 | + |
|
112 | + $this->setup_env(); |
|
113 | + $this->register_config(); |
|
114 | + $this->setup_database(); |
|
115 | + $this->register_providers(); |
|
116 | + $this->register_request(); |
|
117 | + $this->register_instances(); |
|
118 | + $this->load_routes( $this->app['router'] ); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Get the app container. |
|
123 | + * |
|
124 | + * @since 1.0.0 |
|
125 | + * |
|
126 | + * @return \Illuminate\Container\Container |
|
127 | + */ |
|
128 | + public function get_instance() { |
|
129 | + if ( ! $this->app ) { |
|
130 | + new self(); |
|
131 | + } |
|
132 | + |
|
133 | + return $this->app; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Setup the env. |
|
138 | + * |
|
139 | + * @since 1.0.0 |
|
140 | + * |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + protected function setup_env() { |
|
144 | + $this->app['env'] = $this->config->get( 'app.env' ); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Register config. |
|
149 | + * |
|
150 | + * @since 1.0.0 |
|
151 | + * |
|
152 | + * @return void |
|
153 | + */ |
|
154 | + protected function register_config() { |
|
155 | + $this->app->bind( |
|
156 | + 'config', |
|
157 | + function () { |
|
158 | + return array( |
|
159 | + 'app' => $this->config->get( 'app' ), |
|
160 | + 'view.paths' => $this->config->get( 'view.paths' ), |
|
161 | + 'view.compiled' => $this->config->get( 'view.compiled' ), |
|
162 | + ); |
|
163 | + }, |
|
164 | + true |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Setup the database. |
|
170 | + * |
|
171 | + * @since 1.0.0 |
|
172 | + * |
|
173 | + * @return void |
|
174 | + */ |
|
175 | + protected function setup_database() { |
|
176 | + global $wpdb; |
|
177 | + |
|
178 | + $this->db = new Database( |
|
179 | + array( |
|
180 | + 'driver' => 'mysql', |
|
181 | + 'host' => $wpdb->dbhost, |
|
182 | + 'database' => $wpdb->dbname, |
|
183 | + 'username' => $wpdb->dbuser, |
|
184 | + 'password' => $wpdb->dbpassword, |
|
185 | + 'prefix' => $wpdb->prefix, |
|
186 | + 'charset' => $wpdb->charset, |
|
187 | + 'collation' => $wpdb->collate, |
|
188 | + ) |
|
189 | + ); |
|
190 | + |
|
191 | + $this->db->run(); |
|
192 | + |
|
193 | + $this->app->singleton( |
|
194 | + 'db', |
|
195 | + function () { |
|
196 | + return $this->db; |
|
197 | + } |
|
198 | + ); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Register providers. |
|
203 | + * |
|
204 | + * @since 1.0.0 |
|
205 | + * |
|
206 | + * @return void |
|
207 | + */ |
|
208 | + protected function register_providers() { |
|
209 | + $providers = $this->config->get( 'app.providers' ); |
|
210 | + |
|
211 | + if ( $providers && count( $providers ) > 0 ) { |
|
212 | + foreach ( $providers as $provider ) { |
|
213 | + with( new $provider( $this->app ) )->register(); |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Register request. |
|
220 | + * |
|
221 | + * @since 1.0.0 |
|
222 | + * |
|
223 | + * @return void |
|
224 | + */ |
|
225 | + protected function register_request() { |
|
226 | + $this->app->bind( |
|
227 | + 'request', |
|
228 | + function ( $app ) { |
|
229 | + $request = Request::capture(); |
|
230 | + $wp_user = wp_get_current_user(); |
|
231 | + if ( $wp_user ) { |
|
232 | + $user = User::find( $wp_user->ID ); |
|
233 | + $request->merge( array( 'user' => $user ) ); |
|
234 | + $request->setUserResolver( |
|
235 | + function () use ( $user ) { |
|
236 | + return $user; |
|
237 | + } |
|
238 | + ); |
|
239 | + } |
|
240 | + |
|
241 | + return $request; |
|
242 | + } |
|
243 | + ); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Register router. |
|
248 | + * |
|
249 | + * @since 1.0.0 |
|
250 | + * |
|
251 | + * @return void |
|
252 | + */ |
|
253 | + protected function register_instances() { |
|
254 | + $this->app->instance( \Illuminate\Http\Request::class, $this->app['request'] ); |
|
255 | + $this->app->instance( \Illuminate\Routing\Router::class, $this->app['router'] ); |
|
256 | + $this->app->instance( \WPB\Router::class, $this->app['router'] ); |
|
257 | + $this->app->instance( \Illuminate\Contracts\View\Factory::class, $this->app['view'] ); |
|
258 | + $this->app->instance( \Illuminate\Contracts\Routing\UrlGenerator::class, $this->app['url'] ); |
|
259 | + $this->app->alias( 'Route', \WPB\Support\Facades\Route::class ); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Get the config value. |
|
264 | + * |
|
265 | + * @since 1.0.0 |
|
266 | + * @param \Illuminate\Routing\Router $router The app router. |
|
267 | + * @param string $dir The custom routes directory. |
|
268 | + * |
|
269 | + * @return void |
|
270 | + */ |
|
271 | + public function load_routes( $router, $dir = null ) { |
|
272 | + if ( ! $dir ) { |
|
273 | + $dir = __DIR__ . '/../routes/'; |
|
274 | + } |
|
275 | + |
|
276 | + require $dir . 'web.php'; |
|
277 | + |
|
278 | + $router->group( |
|
279 | + array( 'prefix' => 'api' ), |
|
280 | + function () use ( $dir, $router ) { |
|
281 | + require $dir . 'api.php'; |
|
282 | + } |
|
283 | + ); |
|
284 | + } |
|
285 | 285 | } |
@@ -27,177 +27,177 @@ |
||
27 | 27 | */ |
28 | 28 | class ComposerScripts { |
29 | 29 | |
30 | - /** |
|
31 | - * Handle the post-install Composer event. |
|
32 | - * |
|
33 | - * @param \Composer\Script\Event $event The composer event. |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public static function post_install( Event $event ) { |
|
37 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * Handle the post-update Composer event. |
|
42 | - * |
|
43 | - * @param \Composer\Script\Event $event The composer event. |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - public static function post_update( Event $event ) { |
|
47 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Handle the post-autoload-dump Composer event. |
|
52 | - * |
|
53 | - * @param \Composer\Script\Event $event The composer event. |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public static function post_autoload_dump( Event $event ) { |
|
57 | - require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
58 | - |
|
59 | - $dir = $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/../'; |
|
60 | - $root = dirname( $event->getComposer()->getConfig()->get( 'vendor-dir' ) ); |
|
61 | - |
|
62 | - $vendor_name = strtolower( basename( $root ) ); |
|
63 | - $partials = explode( '-', $vendor_name ); |
|
64 | - $camel_case_partials = array(); |
|
65 | - foreach ( $partials as $partial ) { |
|
66 | - $camel_case_partials[] = ucfirst( strtolower( $partial ) ); |
|
67 | - } |
|
68 | - $camel_case = implode( '_', $camel_case_partials ); |
|
69 | - $snake_case = implode( '_', $partials ); |
|
70 | - |
|
71 | - $files = array( |
|
72 | - '/admin/class-wpb-admin.php', |
|
73 | - '/admin/class-wpb-admin-menu.php', |
|
74 | - '/admin/class-wpb-admin-submenu.php', |
|
75 | - '/admin/partials/wpb-admin-display.php', |
|
76 | - '/admin/css/wpb-admin.css', |
|
77 | - '/admin/js/wpb-admin.js', |
|
78 | - '/app/Exceptions/Handler.php', |
|
79 | - '/app/Http/Controllers/ProductController.php', |
|
80 | - '/app/Http/Middleware/AuthMiddleware.php', |
|
81 | - '/app/Http/Middleware/VerifyCsrfToken.php', |
|
82 | - '/app/Http/Kernel.php', |
|
83 | - '/app/User.php', |
|
84 | - '/app/Post.php', |
|
85 | - '/bootstrap/app.php', |
|
86 | - '/config/app.php', |
|
87 | - '/config/database.php', |
|
88 | - '/config/view.php', |
|
89 | - '/database/migrations/class-create-customers-table.php', |
|
90 | - '/database/seeds/class-customers-table.php', |
|
91 | - '/includes/class-wpb-activator.php', |
|
92 | - '/includes/class-wpb-deactivator.php', |
|
93 | - '/includes/class-wpb-i18n.php', |
|
94 | - '/includes/class-wpb-loader.php', |
|
95 | - '/includes/class-wpb.php', |
|
96 | - '/public/class-wpb-public.php', |
|
97 | - '/public/partials/wpb-public-display.php', |
|
98 | - '/public/css/wpb-public.css', |
|
99 | - '/public/js/wpb-public.js', |
|
100 | - '/resources/js/admin/main.js', |
|
101 | - '/resources/js/admin/router/index.js', |
|
102 | - '/resources/js/frontend/main.js', |
|
103 | - '/resources/js/spa/main.js', |
|
104 | - '/routes/web.php', |
|
105 | - '/routes/api.php', |
|
106 | - '/src/Contracts/Http/Kernel.php', |
|
107 | - '/src/Contracts/ExceptionHandler.php', |
|
108 | - '/src/Database/Eloquent/Scopes/PostAuthorScope.php', |
|
109 | - '/src/Database/Eloquent/Scopes/PostStatusScope.php', |
|
110 | - '/src/Database/Eloquent/Scopes/PostTypeScope.php', |
|
111 | - '/src/Database/DB.php', |
|
112 | - '/src/Exceptions/Handler.php', |
|
113 | - '/src/Http/Events/RequestHandled.php', |
|
114 | - '/src/Http/Kernel.php', |
|
115 | - '/src/helpers.php', |
|
116 | - '/src/Support/Facades/Config.php', |
|
117 | - '/src/Support/Facades/Route.php', |
|
118 | - '/src/Application.php', |
|
119 | - '/tests/Application.php', |
|
120 | - '/wpb.php', |
|
121 | - ); |
|
122 | - |
|
123 | - foreach ( $files as $file ) { |
|
124 | - $file = $root . $file; |
|
125 | - if ( file_exists( $file ) ) { |
|
126 | - |
|
127 | - $filesystem = new Filesystem(); |
|
128 | - |
|
129 | - $contents = $filesystem->get( $file ); |
|
130 | - $contents = str_replace( 'wpb_', $snake_case . '_', $contents ); |
|
131 | - $contents = str_replace( 'wpb', $vendor_name, $contents ); |
|
132 | - $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
133 | - $contents = str_replace( 'WPB_FILE', strtoupper( $camel_case ) . '_FILE', $contents ); |
|
134 | - $contents = str_replace( 'WPB_PATH', strtoupper( $camel_case ) . '_PATH', $contents ); |
|
135 | - $contents = str_replace( 'WPB_INCLUDES', strtoupper( $camel_case ) . '_INCLUDES', $contents ); |
|
136 | - $contents = str_replace( 'WPB_URL', strtoupper( $camel_case ) . '_URL', $contents ); |
|
137 | - $contents = str_replace( 'WPB_ASSETS', strtoupper( $camel_case ) . '_ASSETS', $contents ); |
|
138 | - $contents = str_replace( 'WPB_VERSION', strtoupper( $camel_case ) . '_VERSION', $contents ); |
|
139 | - $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
140 | - $filesystem->put( |
|
141 | - $file, |
|
142 | - $contents |
|
143 | - ); |
|
144 | - |
|
145 | - $dir = dirname( $file ); |
|
146 | - $file_name = basename( $file ); |
|
147 | - $new_file_name = str_replace( 'wpb', $vendor_name, $file_name ); |
|
148 | - |
|
149 | - if ( $file_name !== $new_file_name ) { |
|
150 | - rename( $file, $dir . '/' . $new_file_name ); |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - static::update_composer( $filesystem, $root, $camel_case ); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Replace bootstrap file. |
|
160 | - * |
|
161 | - * @since 1.0.0 |
|
162 | - * @access public |
|
163 | - * |
|
164 | - * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
165 | - * @param string $root The string is unique root path for each plugin. |
|
166 | - * @param string $camel_case This string is camel case of project name. |
|
167 | - * |
|
168 | - * @return void |
|
169 | - */ |
|
170 | - protected static function update_bootstrap( $filesystem, $root, $camel_case ) { |
|
171 | - $file = $root . '/bootstrap/app.php'; |
|
172 | - if ( file_exists( $file ) ) { |
|
173 | - $contents = $filesystem->get( $file ); |
|
174 | - $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
175 | - $filesystem->put( |
|
176 | - $file, |
|
177 | - $contents |
|
178 | - ); |
|
179 | - |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Update composer. |
|
185 | - * |
|
186 | - * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
187 | - * @param string $root The app root. |
|
188 | - * @param string $camel_case The composer event. |
|
189 | - * |
|
190 | - * @return void |
|
191 | - */ |
|
192 | - protected static function update_composer( $filesystem, $root, $camel_case ) { |
|
193 | - $file = $root . '/composer.json'; |
|
194 | - if ( file_exists( $file ) ) { |
|
195 | - $contents = $filesystem->get( $file ); |
|
196 | - $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
197 | - $filesystem->put( |
|
198 | - $file, |
|
199 | - $contents |
|
200 | - ); |
|
201 | - } |
|
202 | - } |
|
30 | + /** |
|
31 | + * Handle the post-install Composer event. |
|
32 | + * |
|
33 | + * @param \Composer\Script\Event $event The composer event. |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public static function post_install( Event $event ) { |
|
37 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * Handle the post-update Composer event. |
|
42 | + * |
|
43 | + * @param \Composer\Script\Event $event The composer event. |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + public static function post_update( Event $event ) { |
|
47 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Handle the post-autoload-dump Composer event. |
|
52 | + * |
|
53 | + * @param \Composer\Script\Event $event The composer event. |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public static function post_autoload_dump( Event $event ) { |
|
57 | + require_once $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/autoload.php'; |
|
58 | + |
|
59 | + $dir = $event->getComposer()->getConfig()->get( 'vendor-dir' ) . '/../'; |
|
60 | + $root = dirname( $event->getComposer()->getConfig()->get( 'vendor-dir' ) ); |
|
61 | + |
|
62 | + $vendor_name = strtolower( basename( $root ) ); |
|
63 | + $partials = explode( '-', $vendor_name ); |
|
64 | + $camel_case_partials = array(); |
|
65 | + foreach ( $partials as $partial ) { |
|
66 | + $camel_case_partials[] = ucfirst( strtolower( $partial ) ); |
|
67 | + } |
|
68 | + $camel_case = implode( '_', $camel_case_partials ); |
|
69 | + $snake_case = implode( '_', $partials ); |
|
70 | + |
|
71 | + $files = array( |
|
72 | + '/admin/class-wpb-admin.php', |
|
73 | + '/admin/class-wpb-admin-menu.php', |
|
74 | + '/admin/class-wpb-admin-submenu.php', |
|
75 | + '/admin/partials/wpb-admin-display.php', |
|
76 | + '/admin/css/wpb-admin.css', |
|
77 | + '/admin/js/wpb-admin.js', |
|
78 | + '/app/Exceptions/Handler.php', |
|
79 | + '/app/Http/Controllers/ProductController.php', |
|
80 | + '/app/Http/Middleware/AuthMiddleware.php', |
|
81 | + '/app/Http/Middleware/VerifyCsrfToken.php', |
|
82 | + '/app/Http/Kernel.php', |
|
83 | + '/app/User.php', |
|
84 | + '/app/Post.php', |
|
85 | + '/bootstrap/app.php', |
|
86 | + '/config/app.php', |
|
87 | + '/config/database.php', |
|
88 | + '/config/view.php', |
|
89 | + '/database/migrations/class-create-customers-table.php', |
|
90 | + '/database/seeds/class-customers-table.php', |
|
91 | + '/includes/class-wpb-activator.php', |
|
92 | + '/includes/class-wpb-deactivator.php', |
|
93 | + '/includes/class-wpb-i18n.php', |
|
94 | + '/includes/class-wpb-loader.php', |
|
95 | + '/includes/class-wpb.php', |
|
96 | + '/public/class-wpb-public.php', |
|
97 | + '/public/partials/wpb-public-display.php', |
|
98 | + '/public/css/wpb-public.css', |
|
99 | + '/public/js/wpb-public.js', |
|
100 | + '/resources/js/admin/main.js', |
|
101 | + '/resources/js/admin/router/index.js', |
|
102 | + '/resources/js/frontend/main.js', |
|
103 | + '/resources/js/spa/main.js', |
|
104 | + '/routes/web.php', |
|
105 | + '/routes/api.php', |
|
106 | + '/src/Contracts/Http/Kernel.php', |
|
107 | + '/src/Contracts/ExceptionHandler.php', |
|
108 | + '/src/Database/Eloquent/Scopes/PostAuthorScope.php', |
|
109 | + '/src/Database/Eloquent/Scopes/PostStatusScope.php', |
|
110 | + '/src/Database/Eloquent/Scopes/PostTypeScope.php', |
|
111 | + '/src/Database/DB.php', |
|
112 | + '/src/Exceptions/Handler.php', |
|
113 | + '/src/Http/Events/RequestHandled.php', |
|
114 | + '/src/Http/Kernel.php', |
|
115 | + '/src/helpers.php', |
|
116 | + '/src/Support/Facades/Config.php', |
|
117 | + '/src/Support/Facades/Route.php', |
|
118 | + '/src/Application.php', |
|
119 | + '/tests/Application.php', |
|
120 | + '/wpb.php', |
|
121 | + ); |
|
122 | + |
|
123 | + foreach ( $files as $file ) { |
|
124 | + $file = $root . $file; |
|
125 | + if ( file_exists( $file ) ) { |
|
126 | + |
|
127 | + $filesystem = new Filesystem(); |
|
128 | + |
|
129 | + $contents = $filesystem->get( $file ); |
|
130 | + $contents = str_replace( 'wpb_', $snake_case . '_', $contents ); |
|
131 | + $contents = str_replace( 'wpb', $vendor_name, $contents ); |
|
132 | + $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
133 | + $contents = str_replace( 'WPB_FILE', strtoupper( $camel_case ) . '_FILE', $contents ); |
|
134 | + $contents = str_replace( 'WPB_PATH', strtoupper( $camel_case ) . '_PATH', $contents ); |
|
135 | + $contents = str_replace( 'WPB_INCLUDES', strtoupper( $camel_case ) . '_INCLUDES', $contents ); |
|
136 | + $contents = str_replace( 'WPB_URL', strtoupper( $camel_case ) . '_URL', $contents ); |
|
137 | + $contents = str_replace( 'WPB_ASSETS', strtoupper( $camel_case ) . '_ASSETS', $contents ); |
|
138 | + $contents = str_replace( 'WPB_VERSION', strtoupper( $camel_case ) . '_VERSION', $contents ); |
|
139 | + $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
140 | + $filesystem->put( |
|
141 | + $file, |
|
142 | + $contents |
|
143 | + ); |
|
144 | + |
|
145 | + $dir = dirname( $file ); |
|
146 | + $file_name = basename( $file ); |
|
147 | + $new_file_name = str_replace( 'wpb', $vendor_name, $file_name ); |
|
148 | + |
|
149 | + if ( $file_name !== $new_file_name ) { |
|
150 | + rename( $file, $dir . '/' . $new_file_name ); |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + static::update_composer( $filesystem, $root, $camel_case ); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Replace bootstrap file. |
|
160 | + * |
|
161 | + * @since 1.0.0 |
|
162 | + * @access public |
|
163 | + * |
|
164 | + * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
165 | + * @param string $root The string is unique root path for each plugin. |
|
166 | + * @param string $camel_case This string is camel case of project name. |
|
167 | + * |
|
168 | + * @return void |
|
169 | + */ |
|
170 | + protected static function update_bootstrap( $filesystem, $root, $camel_case ) { |
|
171 | + $file = $root . '/bootstrap/app.php'; |
|
172 | + if ( file_exists( $file ) ) { |
|
173 | + $contents = $filesystem->get( $file ); |
|
174 | + $contents = str_replace( 'WPB_APP_ROOT', strtoupper( $camel_case ) . '_APP_ROOT', $contents ); |
|
175 | + $filesystem->put( |
|
176 | + $file, |
|
177 | + $contents |
|
178 | + ); |
|
179 | + |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Update composer. |
|
185 | + * |
|
186 | + * @param Illuminate\Filesystem\Filesystem $filesystem The illuminate filesystem. |
|
187 | + * @param string $root The app root. |
|
188 | + * @param string $camel_case The composer event. |
|
189 | + * |
|
190 | + * @return void |
|
191 | + */ |
|
192 | + protected static function update_composer( $filesystem, $root, $camel_case ) { |
|
193 | + $file = $root . '/composer.json'; |
|
194 | + if ( file_exists( $file ) ) { |
|
195 | + $contents = $filesystem->get( $file ); |
|
196 | + $contents = str_replace( 'WPB', $camel_case, $contents ); |
|
197 | + $filesystem->put( |
|
198 | + $file, |
|
199 | + $contents |
|
200 | + ); |
|
201 | + } |
|
202 | + } |
|
203 | 203 | } |