Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions src/WpStarter/Wordpress/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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;
}
}
33 changes: 33 additions & 0 deletions src/WpStarter/Wordpress/Bootstrap/HasEarlyBootstrappers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace WpStarter\Wordpress\Bootstrap;

trait HasEarlyBootstrappers
{
protected $earlyBootstrappers = [
\WpStarter\Foundation\Bootstrap\LoadEnvironmentVariables::class,
\WpStarter\Foundation\Bootstrap\LoadConfiguration::class,
\WpStarter\Wordpress\Bootstrap\HandleExceptions::class,
\WpStarter\Foundation\Bootstrap\RegisterFacades::class,
];

function earlyBootstrap()
{
if(!$this->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;
}
}
17 changes: 3 additions & 14 deletions src/WpStarter/Wordpress/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
}
}
}
}
16 changes: 2 additions & 14 deletions src/WpStarter/Wordpress/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -164,12 +160,4 @@ protected function syncMiddlewareToRouter()
}

}


function earlyBootstrap()
{
foreach ($this->earlyBootstrapers as $bootstraper) {
$this->app->bootstrapOne($bootstraper);
}
}
}
20 changes: 13 additions & 7 deletions src/WpStarter/Wordpress/Setting/SettingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

Expand Down