Skip to content

Commit

Permalink
Merge pull request #1 from webrgp/feature/bootable-extension
Browse files Browse the repository at this point in the history
Auto replace default Error Handler
  • Loading branch information
webrgp authored Nov 21, 2024
2 parents 4f9a9aa + dd089bc commit 61290ec
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
13 changes: 0 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ You can install the plugin via Composer:
composer require webrgp/craft-ignition
```

Then, in you can replace the default error handler in your `config/app.php` file:

```php
return [
// ...
'components' => [
'errorHandler' => [
'class' => \webrgp\ignition\IgnitionErrorHandler::class,
],
],
];
```

That's it! Now you can enjoy Ignition's beautiful error pages in your Craft CMS project.

## Customizing Ignition
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@
},
"optimize-autoloader": true,
"sort-packages": true
},
"extra": {
"bootstrap": "webrgp\\ignition\\Ignition"
}
}
2 changes: 1 addition & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use craft\ecs\SetList;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ECSConfig $ecsConfig): void {
return static function(ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__FILE__,
Expand Down
36 changes: 36 additions & 0 deletions src/Ignition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace webrgp\ignition;

use craft\console\Application as CraftConsoleApp;
use craft\web\Application as CraftWebApp;
use webrgp\ignition\web\IgnitionErrorHandler;
use yii\base\BootstrapInterface;

class Ignition implements BootstrapInterface
{
/**
* Bootstraps the application by registering the Ignition error handler.
*
* @param \yii\base\Application $app The application instance.
*
* Only bootstraps if the application is an instance of CraftWebApp or CraftConsoleApp.
* Registers the Ignition error handler and sets it to the application's errorHandler component.
*/
public function bootstrap($app)
{
// Only bootstrap if this is a CraftWebApp
if (!($app instanceof CraftWebApp || $app instanceof CraftConsoleApp)) {
return;
}

// Register the Ignition error handler
$app->set('errorHandler', [
'class' => IgnitionErrorHandler::class,
]);

$errorHandler = $app->getErrorHandler();

$errorHandler->register();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace webrgp\ignition;
namespace webrgp\ignition\web;

use Craft;
use craft\helpers\App;
Expand Down Expand Up @@ -31,7 +31,7 @@ class IgnitionErrorHandler extends \craft\web\ErrorHandler
public ?bool $hideSolutions = null;

/**
* @inheritdoc
* {@inheritdoc}
*/
protected function renderException($exception): void
{
Expand All @@ -40,6 +40,7 @@ protected function renderException($exception): void
// Return JSON for JSON requests
if ($request && $request->getAcceptsJson()) {
parent::renderException($exception);

return;
}

Expand All @@ -57,6 +58,7 @@ protected function renderException($exception): void
// or if the user is an admin and has indicated they want to see it
elseif ($this->showExceptionDetails()) {
$this->getIgnition()->handleException($exception);

return;
}

Expand Down

0 comments on commit 61290ec

Please sign in to comment.