Runs a callable, capturing all error messages, then provides a method to extract any errors raised during execution.
use Haldayne\Fox\CaptureErrors;
$helper = new CaptureErrors(function ($src, $dst) { return copy($src, $dst); });
if (false === $helper('foo', 'bar')) {
throw new \RuntimeException($helper->getCapturedErrors()->pop()->get('message'));
}
PHP itself, as well as many libraries, rely upon triggered errors to notify developers of problems. Many frameworks provide methods to capure these errors globally and convert them to exceptions, but you do not always have access to those frameworks. Worse, you may be using code that deliberately silences errors.
Errors raised inside the CaptureErrors helper is pushed into a Map stack, with each element also a Map of the error details: error code, error string, file and line where raised, and an array context of variables set at time of error.
package | Haldayne |
---|
__construct(callable $code)
callable
__invoke()
getCapturedErrors() : \Haldayne\Boost\MapOfCollections
\Haldayne\Boost\MapOfCollections
setCapturedErrorTypes(integer $capturedErrorTypes) : void
integer
One or more of the E_* error constants
\InvalidArgumentException |
If $capturedErrorTypes isn't an int |
---|
$capturedErrorTypes
null
$code
null
$map
null