Skip to content

Commit

Permalink
Merge pull request #365 from alleyinteractive/console-flag
Browse files Browse the repository at this point in the history
Ensure --url doesn't throw an error on bin/mantle
  • Loading branch information
srtfisher authored Feb 17, 2023
2 parents 8f5b06f + 1a379ae commit baa2b2b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/mantle/console/class-exception-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Mantle\Contracts\Exceptions\Handler as Exceptions_Handler;
use Throwable;

use function Termwind\render;

/**
* Exception Handler for use in the console.
*
Expand Down Expand Up @@ -61,6 +63,14 @@ public function should_report( Throwable $e ) {
* @throws Throwable Thrown on error rendering.
*/
public function render( $request, Throwable $e ) {
if ( $e instanceof \Symfony\Component\Console\Exception\RuntimeException ) {
render(
'<div class="p-2 bg-red-500 text-white">' . $e->getMessage() . '</div>'
);

return;
}

( new \NunoMaduro\Collision\Provider() )->register();

throw $e;
Expand Down
10 changes: 9 additions & 1 deletion src/mantle/framework/console/class-kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
use Mantle\Contracts\Console\Application as Console_Application_Contract;
use Mantle\Contracts\Console\Kernel as Kernel_Contract;
use Mantle\Contracts\Exceptions\Handler as Exception_Handler;
use Mantle\Support\Str;
use Mantle\Support\Traits\Loads_Classes;
use ReflectionClass;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Throwable;

use function Mantle\Support\Helpers\collect;

/**
* Console Kernel
*/
Expand Down Expand Up @@ -321,7 +324,12 @@ protected function register_wpcli_command() {
Command::PREFIX,
function () {
$status = $this->handle(
new \Symfony\Component\Console\Input\ArgvInput( array_slice( $_SERVER['argv'] ?? [], 1 ) ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
new \Symfony\Component\Console\Input\ArgvInput(
collect( (array) ( $_SERVER['argv'] ?? [] ) ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
// Remove the `wp` prefix from argv and any invalid arguments (such as --url).
->filter( fn ( $value, $index ) => 0 !== $index && ! Str::starts_with( $value, '--url=' ) )
->all()
),
new \Symfony\Component\Console\Output\ConsoleOutput(),
);

Expand Down
1 change: 1 addition & 0 deletions src/mantle/framework/exceptions/class-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ abstract class Handler implements Contract {
HttpException::class,
Model_Not_Found_Exception::class,
ResourceNotFoundException::class,
\Symfony\Component\Console\Exception\RuntimeException::class,
];

/**
Expand Down

0 comments on commit baa2b2b

Please sign in to comment.