diff --git a/src/WpStarter/Wordpress/Application.php b/src/WpStarter/Wordpress/Application.php index 8e6c564..cb13a34 100644 --- a/src/WpStarter/Wordpress/Application.php +++ b/src/WpStarter/Wordpress/Application.php @@ -11,9 +11,13 @@ class Application extends \WpStarter\Foundation\Application * * @var string */ - const VERSION = '1.9.9'; - - protected $bootstrappedList = []; + const VERSION = '1.9.10'; + /** + * Indicates if the application has been early bootstrapped before. + * + * @var bool + */ + protected $hasBeenEarlyBootstrapped = false; protected function registerBaseServiceProviders() { @@ -30,22 +34,30 @@ public function registerCoreContainerAliases() $this->alias('app',self::class); } - function bootstrapWith(array $bootstrappers) + /** + * Run the given array of bootstrap classes. + * + * @param string[] $bootstrappers + * @return void + */ + public function earlyBootstrapWith(array $bootstrappers) { - $this->hasBeenBootstrapped = true; - + $this->hasBeenEarlyBootstrapped = true; foreach ($bootstrappers as $bootstrapper) { - $this->bootstrapOne($bootstrapper); - } - } + $this['events']->dispatch('bootstrapping: '.$bootstrapper, [$this]); - function bootstrapOne($bootstrapper) - { - if (!isset($this->bootstrappedList[$bootstrapper])) { - $this->bootstrappedList[$bootstrapper] = true; - $this['events']->dispatch('bootstrapping: ' . $bootstrapper, [$this]); $this->make($bootstrapper)->bootstrap($this); - $this['events']->dispatch('bootstrapped: ' . $bootstrapper, [$this]); + + $this['events']->dispatch('bootstrapped: '.$bootstrapper, [$this]); } } + /** + * Determine if the application has been early bootstrapped before. + * + * @return bool + */ + public function hasBeenEarlyBootstrapped() + { + return $this->hasBeenEarlyBootstrapped; + } } diff --git a/src/WpStarter/Wordpress/Bootstrap/HasEarlyBootstrappers.php b/src/WpStarter/Wordpress/Bootstrap/HasEarlyBootstrappers.php new file mode 100644 index 0000000..ef6d145 --- /dev/null +++ b/src/WpStarter/Wordpress/Bootstrap/HasEarlyBootstrappers.php @@ -0,0 +1,33 @@ +app->hasBeenEarlyBootstrapped()) { + $this->app->earlyBootstrapWith($this->earlyBootstrappers()); + } + } + protected function earlyBootstrappers() + { + return $this->earlyBootstrappers; + } + protected function bootstrappers() + { + $bootstrappers = parent::bootstrappers(); + if($this->app->hasBeenEarlyBootstrapped()) { + //Remove early bootstrapper from bootstrapper list + $bootstrappers=array_diff($bootstrappers, $this->earlyBootstrappers); + } + return $bootstrappers; + } +} diff --git a/src/WpStarter/Wordpress/Console/Kernel.php b/src/WpStarter/Wordpress/Console/Kernel.php index 2545d91..8f81f8e 100644 --- a/src/WpStarter/Wordpress/Console/Kernel.php +++ b/src/WpStarter/Wordpress/Console/Kernel.php @@ -3,15 +3,11 @@ namespace WpStarter\Wordpress\Console; use WpStarter\Foundation\Console\Kernel as ConsoleKernel; +use WpStarter\Wordpress\Bootstrap\HasEarlyBootstrappers; class Kernel extends ConsoleKernel { - protected $earlyBootstrapers = [ - \WpStarter\Foundation\Bootstrap\LoadEnvironmentVariables::class, - \WpStarter\Foundation\Bootstrap\LoadConfiguration::class, - \WpStarter\Wordpress\Bootstrap\HandleExceptions::class, - \WpStarter\Foundation\Bootstrap\RegisterFacades::class, - ]; + use HasEarlyBootstrappers; /** * The bootstrap classes for the application. * @@ -26,11 +22,4 @@ class Kernel extends ConsoleKernel \WpStarter\Foundation\Bootstrap\RegisterProviders::class, \WpStarter\Foundation\Bootstrap\BootProviders::class, ]; - - function earlyBootstrap() - { - foreach ($this->earlyBootstrapers as $bootstraper) { - $this->app->bootstrapOne($bootstraper); - } - } -} \ No newline at end of file +} diff --git a/src/WpStarter/Wordpress/Kernel.php b/src/WpStarter/Wordpress/Kernel.php index 89f0fc3..7531bd3 100644 --- a/src/WpStarter/Wordpress/Kernel.php +++ b/src/WpStarter/Wordpress/Kernel.php @@ -8,21 +8,17 @@ use WpStarter\Routing\Pipeline; use WpStarter\Routing\Router; use WpStarter\Support\Facades\Facade; +use WpStarter\Wordpress\Bootstrap\HasEarlyBootstrappers; use WpStarter\Wordpress\Routing\Router as ShortcodeRouter; class Kernel extends HttpKernel { + use HasEarlyBootstrappers; protected $wpHandleHook=['template_redirect',1]; /** * @var \WpStarter\Wordpress\Application */ protected $app; - protected $earlyBootstrapers = [ - \WpStarter\Foundation\Bootstrap\LoadEnvironmentVariables::class, - \WpStarter\Foundation\Bootstrap\LoadConfiguration::class, - \WpStarter\Wordpress\Bootstrap\HandleExceptions::class, - \WpStarter\Foundation\Bootstrap\RegisterFacades::class, - ]; /** * The bootstrap classes for the application. * @@ -164,12 +160,4 @@ protected function syncMiddlewareToRouter() } } - - - function earlyBootstrap() - { - foreach ($this->earlyBootstrapers as $bootstraper) { - $this->app->bootstrapOne($bootstraper); - } - } } diff --git a/src/WpStarter/Wordpress/Setting/SettingServiceProvider.php b/src/WpStarter/Wordpress/Setting/SettingServiceProvider.php index 5230b12..d98756c 100644 --- a/src/WpStarter/Wordpress/Setting/SettingServiceProvider.php +++ b/src/WpStarter/Wordpress/Setting/SettingServiceProvider.php @@ -19,15 +19,21 @@ function register() public function boot(){ if($this->autoRestartQueue) { - add_action('update_option_' . $this->getOptionKey(), function () { - $this->app['setting']->reload(); - Artisan::call('queue:restart'); - }); + add_action('update_option_' . $this->getOptionKey(), [$this,'reloadSettings']); } if($this->autoSave) { - add_action('shutdown', function () { - $this->app['setting']->save(); - }); + add_action('shutdown', [$this,'saveSettings']); + } + } + public function saveSettings(){ + if($this->app->bound('setting')) { + $this->app['setting']->save(); + } + } + public function reloadSettings(){ + if($this->app->bound('setting')) { + $this->app['setting']->reload(); + Artisan::call('queue:restart'); } }