mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-12-14 01:57:26 +01:00
f99a96e0a2
Add ErrorHandler interface, as well as ErrorHandler\Throwing and ErrorHandler\Collecting. The error handler is passed to Parser::parse(). This supersedes the throwOnError option. NameResolver now accepts an ErrorHandler in the ctor.
46 lines
839 B
PHP
46 lines
839 B
PHP
<?php
|
|
|
|
namespace PhpParser\ErrorHandler;
|
|
|
|
use PhpParser\Error;
|
|
use PhpParser\ErrorHandler;
|
|
|
|
/**
|
|
* Error handler that collects all errors into an array.
|
|
*
|
|
* This allows graceful handling of errors.
|
|
*/
|
|
class Collecting implements ErrorHandler
|
|
{
|
|
/** @var Error[] Collected errors */
|
|
private $errors = [];
|
|
|
|
public function handleError(Error $error) {
|
|
$this->errors[] = $error;
|
|
}
|
|
|
|
/**
|
|
* Get collected errors.
|
|
*
|
|
* @return Error[]
|
|
*/
|
|
public function getErrors() {
|
|
return $this->errors;
|
|
}
|
|
|
|
/**
|
|
* Check whether there are any errors.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function hasErrors() {
|
|
return !empty($this->errors);
|
|
}
|
|
|
|
/**
|
|
* Reset/clear collected errors.
|
|
*/
|
|
public function clearErrors() {
|
|
$this->errors = [];
|
|
}
|
|
} |