Skip to content

Commit 64f08cd

Browse files
authored
Merge pull request #122 from alleyinteractive/mantle-bin
Feature: bin/mantle
2 parents a4a5067 + c2c4b5c commit 64f08cd

File tree

14 files changed

+138
-43
lines changed

14 files changed

+138
-43
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ vendor
88
composer.lock
99
bootstrap/cache
1010
.phpunit.result.cache
11+
.phpcs/*.json
1112

1213
# Ignore temporary OS files
1314
.DS_Store

.phpcs/.gitkeep

Whitespace-only changes.

app/console/class-kernel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77

88
namespace App\Console;
99

10+
use Mantle\Facade\Console;
1011
use Mantle\Framework\Console\Kernel as Console_Kernel;
1112

1213
/**
1314
* Application Console Kernel
15+
*
16+
* By default, the application will automatically register any command in this
17+
* directory as well as any command registered in 'routes/console.php'.
1418
*/
1519
class Kernel extends Console_Kernel {
1620
/**
@@ -29,5 +33,7 @@ class Kernel extends Console_Kernel {
2933
*/
3034
public function commands(): void {
3135
$this->load( __DIR__ );
36+
37+
require base_path( 'routes/console.php' ); // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomFunction
3238
}
3339
}

app/exceptions/class-handler.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ class Handler extends ExceptionHandler {
1818
/**
1919
* A list of the exception types that are not reported.
2020
*
21-
* @var array
21+
* @var string[]
2222
*/
23-
protected $dont_report = [];
23+
protected $dont_report = [
24+
// ...
25+
];
2426

2527
/**
2628
* Report or log an exception.

bin/clear-bootstrap.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

bin/mantle

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
define( 'MANTLE_ISOLATION_MODE', true );
5+
defined( 'MANTLE_BASE_DIR' ) || define( 'MANTLE_BASE_DIR', dirname( __DIR__ ) );
6+
7+
/*
8+
|--------------------------------------------------------------------------
9+
| Load Composer
10+
|--------------------------------------------------------------------------
11+
|
12+
| Check if Composer has been installed and attempt to load it. You can remove
13+
| this block of code if Composer is being loaded outside of the plugin.
14+
|
15+
*/
16+
17+
if ( file_exists( __DIR__ . '/../vendor/autoload.php' ) ) {
18+
require __DIR__ . '/../vendor/autoload.php';
19+
} elseif ( ! class_exists( Mantle\Contracts\Console\Kernel::class ) ) {
20+
echo 'You need to run `composer install` to use bin/mantle. If your `vendor/autoload.php` file is in a different location, you must modify `bin/mantle` to load it.' . PHP_EOL;
21+
exit( 1 );
22+
}
23+
24+
$app = require_once __DIR__ . '/../bootstrap/app.php';
25+
26+
/*
27+
|--------------------------------------------------------------------------
28+
| Run the Console Mantle Application
29+
|--------------------------------------------------------------------------
30+
|
31+
| Load the Mantle application and run the console application. With isolation
32+
| mode enabled, we shouldn't have a dependency on WordPress.
33+
|
34+
*/
35+
36+
$kernel = $app->make( Mantle\Contracts\Console\Kernel::class );
37+
38+
$status = $kernel->handle(
39+
$input = new Symfony\Component\Console\Input\ArgvInput,
40+
new Symfony\Component\Console\Output\ConsoleOutput(),
41+
);
42+
43+
/*
44+
|--------------------------------------------------------------------------
45+
| Shutdown The Application
46+
|--------------------------------------------------------------------------
47+
|
48+
| Once the application has finished running, we will fire off the shutdown
49+
| events so that any final work may be done by the application before it
50+
| is shut down gracefully.
51+
|
52+
*/
53+
54+
$kernel->terminate( $input, $status );
55+
56+
exit( $status );

bin/package-discover.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

composer.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"alleyinteractive/composer-wordpress-autoloader": "^1.0",
14-
"alleyinteractive/mantle-framework": "^0.7",
14+
"alleyinteractive/mantle-framework": "^0.9",
1515
"fakerphp/faker": "^1.9",
1616
"symfony/mime": "^5.1"
1717
},
@@ -43,10 +43,15 @@
4343
"minimum-stability": "dev",
4444
"prefer-stable": true,
4545
"scripts": {
46-
"pre-install-cmd": "./bin/clear-bootstrap.sh",
47-
"pre-update-cmd": "./bin/clear-bootstrap.sh",
46+
"post-install-cmd": [
47+
"bin/mantle cache:clear"
48+
],
49+
"post-update-cmd": [
50+
"bin/mantle cache:clear"
51+
],
4852
"post-autoload-dump": [
49-
"./bin/package-discover.sh"
53+
"bin/mantle package:discover",
54+
"bin/mantle model:discover"
5055
],
5156
"lint": "@phpcs",
5257
"lint:fix": "@phpcbf",

config/assets.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@
2626
|
2727
| This URL is used to properly generate the URL to built assets.
2828
*/
29-
'url' => env( 'ASSET_BUILD_URL', \plugin_dir_url( __DIR__ ) ),
29+
'url' => env(
30+
'ASSET_BUILD_URL',
31+
function_exists( 'plugin_dir_url' ) ? \plugin_dir_url( __DIR__ ) : '', // todo: replace with a framework helper method.
32+
),
3033
];

mantle.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,28 @@ function() {
6262
}
6363
}
6464

65-
/**
66-
* Load the Mantle Application
67-
*/
65+
/*
66+
|--------------------------------------------------------------------------
67+
| Load the Application
68+
|--------------------------------------------------------------------------
69+
|
70+
| Load the Mantle application from the bootstrap file.
71+
|
72+
*/
6873
$app = require_once __DIR__ . '/bootstrap/app.php';
6974

7075
/*
71-
* Run the application.
72-
*/
73-
// Load the Application's Kernel depending on the context it was called.
76+
|--------------------------------------------------------------------------
77+
| Run the Mantle Application
78+
|--------------------------------------------------------------------------
79+
|
80+
| Once we have the application, we can handle the incoming request and send it
81+
| the application's kernel (which depends on the context upon which it was
82+
| called). For the console, the kernel's `handle` method is not called intentionally.
83+
|
84+
*/
7485
if ( defined( 'WP_CLI' ) && \WP_CLI ) {
7586
$app_kernel = $app->make( Contracts\Console\Kernel::class );
76-
$app_kernel->handle();
7787
} else {
7888
// Boot up the HTTP Kernel.
7989
$app_kernel = $app->make( Contracts\Http\Kernel::class );

0 commit comments

Comments
 (0)