2017 © Pedro Peláez
 

library exceper

Provides temporary error handler automatically using set_error_handler() and restore_error_handler().

image

mpyw/exceper

Provides temporary error handler automatically using set_error_handler() and restore_error_handler().

  • Friday, September 22, 2017
  • by mpyw
  • Repository
  • 2 Watchers
  • 2 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Exceper Build Status Coverage Status Scrutinizer Code Quality

Provides temporary error handler automatically using [set_error_handler()] and [restore_error_handler()]., (*1)

PHP :question: Feature Restriction
5.3.2~ :smile: Supported
~5.3.1 :boom: Incompatible

Installing

composer require mpyw/exceper

Quick Example

<?php

require __DIR__ . '/vendor/autoload.php';

use Mpyw\Exceper\Convert;

try {

    // We pick errors triggered by fopen() or fgets().
    // They are converted into \RuntimeException.
    Convert::toRuntimeException(function () {
        $fp = fopen('http://example.com', 'rb');
        while (false !== $line = fgets($fp)) {
            echo $line;
        }
    });

} catch (\RuntimeException $e) {

    // Do something here

}

// Error handler is already automatically restored.

API

Mpyw\Exceper\Convert::to()
Mpyw\Exceper\Convert::to{$class}()

Capture errors to convert into an instance of the specified class., (*2)

  • Error handlers are automatically restored.
  • ->getFile() and ->getLine() returns correct locations like ErrorException does.
static Mpyw\Exceper\Convert::to(string $class, callable $callback, int $types = E_ALL | E_STRICT): mixed
static Mpyw\Exceper\Convert::to{$class}(callable $callback, int $types = E_ALL | E_STRICT): mixed
static Mpyw\Exceper\Convert::to(string $class, int $code, callable $callback, int $types = E_ALL | E_STRICT): mixed
static Mpyw\Exceper\Convert::to{$class}(int $code, callable $callback, int $types = E_ALL | E_STRICT): mixed

Arguments

  • (string) __$class__
    Conversion target class name which is an instance of \Exception or \Throwable. Please note that case-sensitivity of class name depends on the implementation of your autoloaders, which can cause an unexpected behavior if the target class is not loaded.
  • (int) __$code__
    Error code passed to the constructor as the second argument. Default to 0.
  • (callable) __$callback__
    Callback function to be executed. This parameter SHOULD be used as \Closure because arguments cannot be specified.
  • (int) __$types__
    Bit mask of target error severities.

Return Value

(mixed)
Propagates upcoming value from $callback()., (*3)

Exception

Converted errors., (*4)

Mpyw\Exceper\Convert::silent()

Capture errors but never throw anything., (*5)

static Mpyw\Exceper\Convert::silent(callable $callback, int $types = E_ALL | E_STRICT, bool $captureExceptions = true): mixed

Arguments

  • (callable) __$callback__
    Callback function to be executed. This parameter SHOULD be a \Closure because arguments cannot be specified.
  • (int) __$types__
    Bit mask of target error severities.
  • (bool) __$captureExceptions__
    Capture exceptions that were directly thrown; not originated in set_error_handler().

Return Value

(mixed)
Propagates upcoming value from $callback(). Returns null if something thrown., (*6)

The Versions

22/09 2017

dev-master

9999999-dev

Provides temporary error handler automatically using set_error_handler() and restore_error_handler().

  Sources   Download

MIT

The Requires

  • php ^5.3.2 || ^7.0

 

The Development Requires

error temporary errorexception set_error_handler restore_error_handler

22/09 2017

v1.1.1

1.1.1.0

Provides temporary error handler automatically using set_error_handler() and restore_error_handler().

  Sources   Download

MIT

The Requires

  • php ^5.3.2 || ^7.0

 

The Development Requires

error temporary errorexception set_error_handler restore_error_handler

22/09 2017

v1.1.0

1.1.0.0

Provides temporary error handler automatically using set_error_handler() and restore_error_handler().

  Sources   Download

MIT

The Requires

  • php ^5.3.2 || ^7.0

 

The Development Requires

error temporary errorexception set_error_handler restore_error_handler

21/05 2017

v1.0

1.0.0.0

Provides temporary error handler automatically using set_error_handler() and restore_error_handler().

  Sources   Download

MIT

The Requires

  • php ^5.3.2 || ^7.0

 

The Development Requires

error temporary errorexception set_error_handler restore_error_handler