Skip to content

Commit

Permalink
Merge pull request #12 from ArcFramework/arc_cli_no_wordpress
Browse files Browse the repository at this point in the history
Allow Arc CLI to be booted without Wordpress
  • Loading branch information
AndrewFeeney authored May 31, 2017
2 parents 695bc99 + fac3139 commit a22bbfc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
30 changes: 10 additions & 20 deletions src/Arc/Admin/AdminMenus.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,24 @@ public function add()
return;
}

$pageName = $this->name ?? $this->app->pluginTitle();
$menuTitle = $this->title ?? $this->app->pluginTitle();
$capability = $this->capability ?? 'administrator';
$slug = $this->slug ?? $this->app->slug;

add_action('admin_menu', function () {
if ($this->type == 'menu') {
add_menu_page(
$this->name,
$this->title,
$this->capability,
$this->slug,
$this->getCallable(),
$this->icon,
$this->position
);
add_menu_page($pageName, $menuTitle, $capability, $slug, $this->icon, $this->position);
} elseif ($this->type == 'submenu') {
add_submenu_page(
$this->parent,
$this->name,
$this->title,
$this->capability,
$this->slug,
$this->getCallable()
);
add_submenu_page($this->parent, $pageName, $menuTitle, $capability, $slug, $this->getCallable());
} elseif ($this->type = 'options') {
add_options_page($this->name, $this->title, $this->capability, $this->slug, $this->getCallable());
add_options_page($pageName, $menuTitle, $capability, $slug, $this->getCallable());
}
});

foreach ($this->settings as $setting) {
add_action('admin_init', function () use ($setting) {
register_setting($this->slug, $setting);
add_action('admin_init', function () use ($slug, $setting) {
register_setting($slug, $setting);
});
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/Arc/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,12 @@ public function registerDeferredProvider($provider, $service = null)
*/
protected function bootProvider(ServiceProvider $provider)
{
if ($this->shouldBeBootedWithoutWordpress()) {
if (method_exists($provider, 'bootWithoutWordpress')) {
return $this->call([$provider, 'bootWithoutWordpress']);
}
}

if (method_exists($provider, 'boot')) {
return $this->call([$provider, 'boot']);
}
Expand Down Expand Up @@ -1046,4 +1052,13 @@ public function resourcePath($path = null)
{
return $this->basePath().DIRECTORY_SEPARATOR.'resources'.($path ? DIRECTORY_SEPARATOR.$path : $path);
}

public function shouldBeBootedWithoutWordpress()
{
if (!defined('BOOT_ARC_WITHOUT_WORDPRESS')) {
return false;
}

return BOOT_ARC_WITHOUT_WORDPRESS;
}
}
2 changes: 1 addition & 1 deletion src/Arc/Bootstrap/BindWordpressAdapters.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function bootstrap(Application $app)
{
$this->app = $app;

if (constant('BOOT_ARC_WITHOUT_WORDPRESS')) {
if (@constant('BOOT_ARC_WITHOUT_WORDPRESS')) {
return $this->bindNoWordpressImplementations();
}

Expand Down
4 changes: 4 additions & 0 deletions src/Arc/Config/WPOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public function get($key)
return $this->testConfig[$key];
}

if (!defined('get_option')) {
return;
}

return get_option($key);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Arc/Console/stubs/provider.stub
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace DummyNamespace;

use Arc\Providers\ServiceProvider;
use Illuminate\Support\ServiceProvider;

class DummyClass extends ServiceProvider
{
Expand Down
1 change: 1 addition & 0 deletions src/Arc/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Kernel implements KernelContract
\Arc\Bootstrap\HandleExceptions::class,
\Arc\Bootstrap\RegisterFacades::class,
\Arc\Bootstrap\RegisterProviders::class,
\Arc\Bootstrap\BindWordpressAdapters::class,
\Arc\Bootstrap\BootProviders::class,
];

Expand Down

0 comments on commit a22bbfc

Please sign in to comment.