Skip to content

Commit

Permalink
Merge pull request #122 from alleyinteractive/mantle-bin
Browse files Browse the repository at this point in the history
Feature: bin/mantle
  • Loading branch information
srtfisher authored Nov 16, 2022
2 parents a4a5067 + c2c4b5c commit 64f08cd
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ vendor
composer.lock
bootstrap/cache
.phpunit.result.cache
.phpcs/*.json

# Ignore temporary OS files
.DS_Store
Expand Down
Empty file added .phpcs/.gitkeep
Empty file.
6 changes: 6 additions & 0 deletions app/console/class-kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

namespace App\Console;

use Mantle\Facade\Console;
use Mantle\Framework\Console\Kernel as Console_Kernel;

/**
* Application Console Kernel
*
* By default, the application will automatically register any command in this
* directory as well as any command registered in 'routes/console.php'.
*/
class Kernel extends Console_Kernel {
/**
Expand All @@ -29,5 +33,7 @@ class Kernel extends Console_Kernel {
*/
public function commands(): void {
$this->load( __DIR__ );

require base_path( 'routes/console.php' ); // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingCustomFunction
}
}
6 changes: 4 additions & 2 deletions app/exceptions/class-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ class Handler extends ExceptionHandler {
/**
* A list of the exception types that are not reported.
*
* @var array
* @var string[]
*/
protected $dont_report = [];
protected $dont_report = [
// ...
];

/**
* Report or log an exception.
Expand Down
12 changes: 0 additions & 12 deletions bin/clear-bootstrap.sh

This file was deleted.

56 changes: 56 additions & 0 deletions bin/mantle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env php
<?php

define( 'MANTLE_ISOLATION_MODE', true );
defined( 'MANTLE_BASE_DIR' ) || define( 'MANTLE_BASE_DIR', dirname( __DIR__ ) );

/*
|--------------------------------------------------------------------------
| Load Composer
|--------------------------------------------------------------------------
|
| Check if Composer has been installed and attempt to load it. You can remove
| this block of code if Composer is being loaded outside of the plugin.
|
*/

if ( file_exists( __DIR__ . '/../vendor/autoload.php' ) ) {
require __DIR__ . '/../vendor/autoload.php';
} elseif ( ! class_exists( Mantle\Contracts\Console\Kernel::class ) ) {
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;
exit( 1 );
}

$app = require_once __DIR__ . '/../bootstrap/app.php';

/*
|--------------------------------------------------------------------------
| Run the Console Mantle Application
|--------------------------------------------------------------------------
|
| Load the Mantle application and run the console application. With isolation
| mode enabled, we shouldn't have a dependency on WordPress.
|
*/

$kernel = $app->make( Mantle\Contracts\Console\Kernel::class );

$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput(),
);

/*
|--------------------------------------------------------------------------
| Shutdown The Application
|--------------------------------------------------------------------------
|
| Once the application has finished running, we will fire off the shutdown
| events so that any final work may be done by the application before it
| is shut down gracefully.
|
*/

$kernel->terminate( $input, $status );

exit( $status );
17 changes: 0 additions & 17 deletions bin/package-discover.sh

This file was deleted.

13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"alleyinteractive/composer-wordpress-autoloader": "^1.0",
"alleyinteractive/mantle-framework": "^0.7",
"alleyinteractive/mantle-framework": "^0.9",
"fakerphp/faker": "^1.9",
"symfony/mime": "^5.1"
},
Expand Down Expand Up @@ -43,10 +43,15 @@
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"pre-install-cmd": "./bin/clear-bootstrap.sh",
"pre-update-cmd": "./bin/clear-bootstrap.sh",
"post-install-cmd": [
"bin/mantle cache:clear"
],
"post-update-cmd": [
"bin/mantle cache:clear"
],
"post-autoload-dump": [
"./bin/package-discover.sh"
"bin/mantle package:discover",
"bin/mantle model:discover"
],
"lint": "@phpcs",
"lint:fix": "@phpcbf",
Expand Down
5 changes: 4 additions & 1 deletion config/assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
|
| This URL is used to properly generate the URL to built assets.
*/
'url' => env( 'ASSET_BUILD_URL', \plugin_dir_url( __DIR__ ) ),
'url' => env(
'ASSET_BUILD_URL',
function_exists( 'plugin_dir_url' ) ? \plugin_dir_url( __DIR__ ) : '', // todo: replace with a framework helper method.
),
];
24 changes: 17 additions & 7 deletions mantle.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,28 @@ function() {
}
}

/**
* Load the Mantle Application
*/
/*
|--------------------------------------------------------------------------
| Load the Application
|--------------------------------------------------------------------------
|
| Load the Mantle application from the bootstrap file.
|
*/
$app = require_once __DIR__ . '/bootstrap/app.php';

/*
* Run the application.
*/
// Load the Application's Kernel depending on the context it was called.
|--------------------------------------------------------------------------
| Run the Mantle Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request and send it
| the application's kernel (which depends on the context upon which it was
| called). For the console, the kernel's `handle` method is not called intentionally.
|
*/
if ( defined( 'WP_CLI' ) && \WP_CLI ) {
$app_kernel = $app->make( Contracts\Console\Kernel::class );
$app_kernel->handle();
} else {
// Boot up the HTTP Kernel.
$app_kernel = $app->make( Contracts\Http\Kernel::class );
Expand Down
12 changes: 12 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

<arg value="ps" />

<!-- Whenever possible, cache the scan results and re-use those for unchanged files on the next scan. -->
<arg name="cache" value=".phpcs/cache.json" />

<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./" />

<!-- Check up to 20 files simultaneously. -->
<arg name="parallel" value="20" />

<!-- Set severity to 1 to see everything that isn't effectively turned off. -->
<arg name="severity" value="1" />

<exclude-pattern>tests/</exclude-pattern>
<exclude-pattern>bootstrap/cache</exclude-pattern>
<exclude-pattern>storage/framework/views</exclude-pattern>
Expand Down
25 changes: 25 additions & 0 deletions routes/console.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Console Commands
*
* @package Mantle
*/

use Mantle\Facade\Console;

/*
|--------------------------------------------------------------------------
| Console Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of your Closure based console commands.
| Each Closure is bound to a command instance allowing a simple approach
| to interacting with each command's IO methods. Even though this
| file is included in your application configuration, feel free to
| remove it if you are not using console commands.
|
*/

Console::command( 'hello {name}', function ( $name ) {
$this->info( "Hello, {$name}!" );
} )->describe( 'Greet a user by name' );
2 changes: 2 additions & 0 deletions views/error/error-404.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/**
* Error Template: 404
*
* phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
*
* @package Mantle
*/

Expand Down
2 changes: 2 additions & 0 deletions views/error/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Error Template: Generic
* Props to Laravel for a great error template.
*
* phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet
*
* @package Mantle
*/

Expand Down

0 comments on commit 64f08cd

Please sign in to comment.