Package Data | |
---|---|
Maintainer Username: | krypter |
Maintainer Contact: | contact@krypter.io (Krypter) |
Package Create Date: | 2014-08-07 |
Package Last Update: | 2014-08-10 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:16:50 |
Package Statistics | |
---|---|
Total Downloads: | 30 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This package gives you an easy way to manage exceptions.
Install Catchor through Composer.
"require": {
"krypter/catchor": "0.2"
}
Publish the config file from the command line. (optional)
The config file will be publish here app/config/packages/krypter/catchor/config.php
.
php artisan config:publish krypter/catchor
Update app/config/app.php
to include a reference to this package's service provider in the providers array.
'providers' => [
'Krypter\Catchor\CatchorServiceProvider'
]
By default Catchor looking for app/exceptions/catchers.php
. You need to create the exceptions
directory inside the app
directory and create a file named catchers.php
inside the exceptions
directory.
Finaly, write the code you want in it.
<?php
// Example
App::error(function(Exception $e)
{
Log::error($e);
});
You can change the path of this file and/or add other files if you want it to. You must publish the config and modify the raw_files
array.
'raw_files' => [
app_path() . '/exceptions/catchers.php', // By default
'/path/to/your/file.php' // Your path
]
You're done!
First, create a class. It must extends Krypter\Catchor\ExceptionCatcher
<?php namespace Acme\Exception;
use Krypter\Catchor\ExceptionCatcher;
class Catcher extends ExceptionCatcher {
// We will catch exception from here
}
Next, add functions starting with catch
// Template
public function catchException(\Exception $e, $code, $fromConsole)
{
return 'Do what you wanna do!';
}
// Real world example
public function catchNotFoundHttpException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e, $code, $fromConsole)
{
return \View::make('pages.404');
}
You can also use raw()
method and write what you want in it. To enable this option you need to add public $raw = true;
public $raw = true;
public function raw()
{
// Example
App::error(function(Exception $e)
{
Log::error($e);
});
}
If you don't have method starting with catch
you need to disable this option by adding public $catch = false
.
Finally, you must have publish the config, empty the raw_files
array (unless you use it) and modify the catchers
array to add this class in the config file. (You can add multiple catcher)
'catchers' => [
'Acme\Exception\Catcher'
],
'raw_files' => []
You're done!
View the license for this repo.
Follow @krypter_io on Twitter for the latest news.