Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Share error handling in one base class
Signed-off-by: Michal Čihař <michal@cihar.com>
- Loading branch information
Showing
3 changed files
with
56 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* Defines the core helper infrastructure of the library. | ||
* | ||
* @package SqlParser | ||
*/ | ||
namespace SqlParser; | ||
|
||
|
||
class Core | ||
{ | ||
|
||
/** | ||
* Whether errors should throw exceptions or just be stored. | ||
* | ||
* @var bool | ||
* | ||
* @see static::$errors | ||
*/ | ||
public $strict = false; | ||
|
||
/** | ||
* List of errors that occurred during lexing. | ||
* | ||
* Usually, the lexing does not stop once an error occurred because that | ||
* error might be false positive or a partial result (even a bad one) | ||
* might be needed. | ||
* | ||
* @var Exception[] | ||
* | ||
* @see Core::error() | ||
*/ | ||
public $errors = array(); | ||
|
||
/** | ||
* Creates a new error log. | ||
* | ||
* @param Exception $error The error exception. | ||
* | ||
* @throws Exception Throws the exception, if strict mode is enabled. | ||
* | ||
* @return void | ||
*/ | ||
public function error($error) | ||
{ | ||
if ($this->strict) { | ||
throw $error; | ||
} | ||
$this->errors[] = $error; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters