2017 © Pedro Peláez
 

library catchor

This package gives you an easy way to manage exceptions.

image

krypter/catchor

This package gives you an easy way to manage exceptions.

  • Sunday, August 10, 2014
  • by krypter
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Laravel Catchor

This package gives you an easy way to manage exceptions., (*1)

Installation

Install Catchor through Composer., (*2)

"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., (*3)

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., (*4)

'providers' => [
    'Krypter\Catchor\CatchorServiceProvider'
]

Usage

With a simple file

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., (*5)

Finaly, write the code you want in it., (*6)

<?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., (*7)

'raw_files' => [
    app_path() . '/exceptions/catchers.php',  // By default
    '/path/to/your/file.php' // Your path
]

You're done!, (*8)

With a class

First, create a class. It must extends Krypter\Catchor\ExceptionCatcher, (*9)

<?php namespace Acme\Exception;

use Krypter\Catchor\ExceptionCatcher;

class Catcher extends ExceptionCatcher {

    // We will catch exception from here

}

Next, add functions starting with catch, (*10)

// 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;, (*11)


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., (*12)

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), (*13)

'catchers' => [
    'Acme\Exception\Catcher'
],
'raw_files' => []

You're done!, (*14)

MIT License

View the license for this repo., (*15)

Contact

Follow @krypter_io on Twitter for the latest news., (*16)

The Versions

10/08 2014

dev-master

9999999-dev

This package gives you an easy way to manage exceptions.

  Sources   Download

MIT

The Requires

 

by Avatar krypter

laravel exception

09/08 2014

v0.2

0.2.0.0

Class to catch and handle exceptions.

  Sources   Download

MIT

The Requires

 

by Avatar krypter

laravel exception

07/08 2014

v0.1

0.1.0.0

Class to catch and handle exceptions.

  Sources   Download

MIT

The Requires

 

by Avatar krypter

laravel exception