PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.5.0
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
← All changes | vendor/wpfluent/framework/src/WPFluent/Foundation/Application.php +98 -20 1.10.0 → 2.5.0 View file →
@@ -1,5 +1,14 @@
1 1 <?php
2 +/**
3 + * @package WPFluent
4 + * @author Sheikh Heera <[email protected]> (https://heera.it)
5 + * @author Sheikh Heera <[email protected]>
6 + * @author Sheikh Heera <[email protected]>
7 + * @link https://github.com/wpfluent/framework2x
8 + * @license MIT https://opensource.org/licenses/MIT
9 + * @license GPL-2.0-or-later https://www.gnu.org/licenses/gpl-2.0.html
10 + */
2 11
3 12 namespace FluentBooking\Framework\Foundation;
4 13
5 14 use InvalidArgumentException;
@@ -10,8 +19,33 @@
10 19 use FluentBooking\Framework\Container\Container;
11 20 use FluentBooking\Framework\Foundation\ComponentBinder;
12 21 use FluentBooking\Framework\Foundation\Concerns\FoundationTrait;
13 22
23 +/**
24 + * Application — service container with magic property access via __get.
25 + *
26 + * Properties below are bound in {@see ComponentBinder::bindComponents()} and
27 + * {@see Application::init()}/{@see Application::setAppLevelNamespace()}. Each
28 + * `@property` declaration teaches PHPStan about a runtime container binding so
29 + * `$app->view->render(...)` and similar access can be type-checked.
30 + *
31 + * @property \FluentBooking\Framework\Foundation\Config $config
32 + * @property \FluentBooking\Framework\View\View $view
33 + * @property \FluentBooking\Framework\Cache\Cache $cache
34 + * @property \FluentBooking\Framework\Http\Router $router
35 + * @property \FluentBooking\Framework\Http\Request\Request $request
36 + * @property \FluentBooking\Framework\Http\Response\Response $response
37 + * @property \FluentBooking\Framework\Validator\Validator $validator
38 + * @property \FluentBooking\Framework\Events\Dispatcher $events
39 + * @property \FluentBooking\Framework\Encryption\Encrypter $encrypter
40 + * @property \FluentBooking\Framework\Encryption\Encrypter $crypt
41 + * @property \FluentBooking\Framework\Database\DatabaseManager $db
42 + * @property \FluentBooking\Framework\Http\URL $url
43 + * @property \FluentBooking\Framework\Support\Mail $mail
44 + * @property \FluentBooking\Framework\Support\Pipeline $pipeline
45 + * @property string $__pluginfile__
46 + * @property string $__namespace__
47 + */
14 48 class Application extends Container
15 49 {
16 50 use FoundationTrait;
17 51
@@ -54,9 +88,9 @@
54 88 * Default namespace for policy handlers
55 89 *
56 90 * @var string
57 91 */
58 - protected $permissionNamespace = null;
92 + protected $policyNamespace = null;
59 93
60 94 /**
61 95 * Composer JSON
62 96 *
@@ -71,8 +105,15 @@
71 105 */
72 106 protected $onReady = [];
73 107
74 108 /**
109 + * Flag to check if components are bound.
110 + *
111 + * @var boolean
112 + */
113 + protected $componentsBound = false;
114 +
115 + /**
75 116 * Construct the application instance
76 117 *
77 118 * @param string $file The main plugin file's absolute path
78 119 * @return null
@@ -163,8 +204,9 @@
163 204 {
164 205 $this->bindAppInstance();
165 206 $this->bindPathsAndUrls();
166 207 $this->loadConfigIfExists();
208 + $this->registerMiddleware();
167 209 $this->registerTextdomain();
168 210 $this->bindCoreComponents();
169 211 $this->requireCommonFiles($this);
170 212 $this->addRestApiInitAction($this);
@@ -229,20 +271,50 @@
229 271 * @return null
230 272 */
231 273 protected function loadConfigIfExists()
232 274 {
233 - $data = [];
275 + $files = [];
234 276
235 277 if (is_dir($this['path.config'])) {
236 278 foreach (glob($this['path.config'] . '*.php') as $file) {
237 - $data[basename($file, '.php')] = require($file);
279 + // middleware.php lives under app/Http/ now; it ships closures
280 + // that don't belong in Config storage.
281 + if (basename($file) === 'middleware.php') {
282 + continue;
283 + }
284 + $files[basename($file, '.php')] = $file;
238 285 }
239 286 }
240 287
241 - $this->instance('config', new Config($data));
288 + $this->instance('config', new Config([], $files));
242 289 }
243 290
244 291 /**
292 + * Register the HTTP middleware stack as a lazy container binding.
293 + *
294 + * Resolves from `app/Http/middleware.php` (canonical). Falls back to
295 + * `config/middleware.php` so un-migrated plugins keep working.
296 + *
297 + * @return void
298 + */
299 + protected function registerMiddleware()
300 + {
301 + $this->singleton('http.middleware', function ($app) {
302 + $new = $app['path.http'] . 'middleware.php';
303 + if (is_file($new)) {
304 + return require $new;
305 + }
306 +
307 + $legacy = $app['path.config'] . 'middleware.php';
308 + if (is_file($legacy)) {
309 + return require $legacy;
310 + }
311 +
312 + return [];
313 + });
314 + }
315 +
316 + /**
245 317 * Resolve the given type from the container.
246 318 * This method is required for unit testing.
247 319 *
248 320 * @param string $abstract
@@ -296,9 +368,12 @@
296 368 * @return null
297 369 */
298 370 protected function bindCoreComponents()
299 371 {
300 - (new ComponentBinder($this))->bindComponents();
372 + if (!$this->componentsBound) {
373 + $this->componentsBound = true;
374 + (new ComponentBinder($this))->bindComponents();
375 + }
301 376 }
302 377
303 378 /**
304 379 * Load (include) the files where hooks are registered.
@@ -314,11 +389,11 @@
314 389 );
315 390
316 391 require_once $this->basePath . 'app/Hooks/actions.php';
317 392 require_once $this->basePath . 'app/Hooks/filters.php';
318 -
319 - if (file_exists($includes = $this->basePath . 'app/Hooks/includes.php')) {
320 - require_once $includes;
393 +
394 + if (file_exists($f = $this->basePath . 'app/Hooks/includes.php')) {
395 + require_once $f;
321 396 }
322 397 }
323 398
324 399 /**
@@ -324,11 +399,11 @@
324 399 /**
325 400 * Handler for rest_pre_serve_request filter.
326 401 *
327 402 * @param bool $served (default: false)
328 - * @param \WP_Rest_Response $result
329 - * @param \WP_Rest_Request $request
330 - * @param \WP_Rest_Server $server
403 + * @param \WP_REST_Response $result
404 + * @param \WP_REST_Request $request
405 + * @param \WP_REST_Server $server
331 406 * @return bool (false to intercept, otherwise true)
332 407 */
333 408 public function preServeRequest($served, $result, $request, $server)
334 409 {
@@ -339,8 +414,9 @@
339 414 if ($this->isRequestOfPlugin($route, $slug)) {
340 415 if ($this->isRequestForEndpoints($route)) {
341 416 status_header(200);
342 417 $result->set_status(200);
418 + // @phpstan-ignore-next-line
343 419 $result->set_data($this->endpoints);
344 420 } else {
345 421 $result->set_data(
346 422 $this->customizeNotFoundResponse(
@@ -406,10 +482,10 @@
406 482
407 483 /**
408 484 * Prepare a custom not found response.
409 485 *
410 - * @param \WP_Rest_Response $result
411 - * @param \WP_Rest_Request $request
486 + * @param \WP_REST_Response $result
487 + * @param \WP_REST_Request $request
412 488 *
413 489 * @return array
414 490 */
415 491 public function customizeNotFoundResponse($result, $request)
@@ -466,12 +542,13 @@
466 542 * Register rest routes.
467 543 *
468 544 * @param \FluentBooking\Framework\Http\Router $router
469 545 *
470 - * @return null
546 + * @return void
471 547 */
472 548 protected function registerRestRoutes($router)
473 549 {
550 + // @phpstan-ignore-next-line
474 551 $router->registerRoutes(
475 552 $this->requireRouteFile($router)
476 553 );
477 554 }
@@ -487,14 +564,14 @@
487 564 require_once $this['path.http'] . 'Routes/routes.php';
488 565 }
489 566
490 567 /**
491 - * Register plugin booted callbacks.
568 + * Register plugin ready (booted) callbacks.
492 569 *
493 570 * @param callable $callback
494 571 * @return void
495 572 */
496 - protected function ready(callable $callback)
573 + public function ready(callable $callback)
497 574 {
498 575 $this->onReady[] = $callback;
499 576 }
500 577
@@ -500,14 +577,15 @@
500 577
501 578 /**
502 579 * Execute plugin booted callbacks.
503 580 *
504 - * @param callable $callback
505 581 * @return void
506 582 */
507 583 protected function callPluginReadyCallbacks()
508 584 {
509 - while ($callback = array_shift($this->onReady)) {
510 - $callback($this);
511 - }
585 + $this->addAction('init', function() {
586 + while ($callback = array_pop($this->onReady)) {
587 + $callback($this);
588 + }
589 + });
512 590 }
513 591 }