PHPackages                             brenno-duarte/modern-php-exception - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. brenno-duarte/modern-php-exception

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

brenno-duarte/modern-php-exception
==================================

Display PHP errors and exceptions in a modern and intuitive way

3.4.1(9mo ago)1289↑136.8%13MITPHPPHP ^8.3

Since Apr 28Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/brenno-duarte/modern-php-exception)[ Packagist](https://packagist.org/packages/brenno-duarte/modern-php-exception)[ RSS](/packages/brenno-duarte-modern-php-exception/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (39)Used By (3)

Modern PHP Exception
====================

[](#modern-php-exception)

Display PHP errors and exceptions in a modern and intuitive way!

[![](https://camo.githubusercontent.com/f538c8e1cc19e7fd817d16a2d14b5194e4357848bd8f66ab0852afbbfd9730b9/68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f62646c736c74666d6b2f696d6167652f75706c6f61642f76313730343733313038382f696e6465785f796b6e6879652e706e67)](https://camo.githubusercontent.com/f538c8e1cc19e7fd817d16a2d14b5194e4357848bd8f66ab0852afbbfd9730b9/68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f62646c736c74666d6b2f696d6167652f75706c6f61642f76313730343733313038382f696e6465785f796b6e6879652e706e67)

Requirements
------------

[](#requirements)

- PHP &gt;= 8.3
- ext-mbstring
- ext-pdo

Installing via Composer
-----------------------

[](#installing-via-composer)

Use the command below:

```
composer require brenno-duarte/modern-php-exception

```

How to use
----------

[](#how-to-use)

You only need to call a single method as shown below.

```
use ModernPHPException\ModernPHPException;

$exc = new ModernPHPException();
$exc->start();
```

From there, all errors and exceptions that are triggered will be displayed through the ModernPHPException component.

If you want to highlight a part of the message during an exception, you can use `{` and `}`.

```
use ModernPHPException\ModernPHPException;

$exc = new ModernPHPException();
$exc->start();

throw new CustomException("Highlighting {this part}");
```

You can change the return, title and theme settings in the class constructor as shown in the items below.

YAML configuration
------------------

[](#yaml-configuration)

You can customize the exception title, enable dark mode and also enable production mode. Use the example file `config.example.yaml` or create a new one.

```
$config = __DIR__ . '/config.example.yaml';

$exc = new ModernPHPException($config);
$exc->start();
```

**Changing the page title**

```
title: My title
```

**Enabling dark mode**

```
# Default: false
dark_mode: true
```

**Enabling production mode**

```
# Default: false
production_mode: true
```

To change the message, change the `error_message` variable:

```
production_mode: true
error_message: Something wrong!
```

[![](https://camo.githubusercontent.com/e1192a131a0eb3101cc84a93d15f07c995e3d09692845f1222a84c68f2fdbbda/68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f62646c736c74666d6b2f696d6167652f75706c6f61642f76313635313431323138302f70726f64756374696f6e2d6d6f64655f7a616a6577672e706e67)](https://camo.githubusercontent.com/e1192a131a0eb3101cc84a93d15f07c995e3d09692845f1222a84c68f2fdbbda/68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f62646c736c74666d6b2f696d6167652f75706c6f61642f76313635313431323138302f70726f64756374696f6e2d6d6f64655f7a616a6577672e706e67)

**Load CSS files if there is no internet connection**

```
# Use `false` only if you have no internet connection
enable_cdn_assets: false
```

**Enabling Log file**

```
enable_logs: false

# Default: sys_get_temp_dir() . "/ModernPHPExceptionLogs/ModernPHPExceptionLogs.log"
dir_logs: C:\wamp64\www\modern-php-exception\
```

Enable occurrences
------------------

[](#enable-occurrences)

If you want to have a history of all exceptions and errors that your application displays, you can enable the occurrences using the `enableOccurrences` method:

```
$config = __DIR__ . '/config.example.yaml';

$exc = new ModernPHPException($config);
$exc->enableOccurrences(); // start();
```

Don't forget to configure the database in the `config.example.yaml` file.

```
# Database for Occurrences
db_drive: mysql
db_host: localhost
db_name: database_name
db_user: root
db_pass: pass
```

[![](https://camo.githubusercontent.com/65a5ad1d2a46adf3dfef50960879b1c52bf941882841d91f416e731429e8a87b/68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f62646c736c74666d6b2f696d6167652f75706c6f61642f76313730343733303837302f6f6363757272656e6365735f6e76646d62652e706e67)](https://camo.githubusercontent.com/65a5ad1d2a46adf3dfef50960879b1c52bf941882841d91f416e731429e8a87b/68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f62646c736c74666d6b2f696d6167652f75706c6f61642f76313730343733303837302f6f6363757272656e6365735f6e76646d62652e706e67)

Creating a solution for an exception
====================================

[](#creating-a-solution-for-an-exception)

If you are creating a custom exception class, you can add a solution to resolve this exception.

For that, use the static `getSolution` method implementing the `SolutionInterface` interface:

```
