This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor event validation and now validate events on dispatch (#5)
- Loading branch information
1 parent
5a2d299
commit bfdb14e
Showing
11 changed files
with
869 additions
and
47 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Superbalist\EventPubSub; | ||
|
||
use Exception; | ||
use Throwable; | ||
|
||
class ValidationException extends Exception | ||
{ | ||
/** | ||
* @var ValidationResult | ||
*/ | ||
protected $validationResult; | ||
|
||
/** | ||
* @param ValidationResult $validationResult | ||
* @param string $message | ||
* @param int $code | ||
* @param Throwable|null $previous | ||
*/ | ||
public function __construct( | ||
ValidationResult $validationResult, | ||
$message = 'The event failed validation.', | ||
$code = 0, | ||
Throwable $previous = null | ||
) { | ||
parent::__construct($message, $code, $previous); | ||
|
||
$this->validationResult = $validationResult; | ||
} | ||
|
||
/** | ||
* @return ValidationResult | ||
*/ | ||
public function getValidationResult() | ||
{ | ||
return $this->validationResult; | ||
} | ||
} |
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,88 @@ | ||
<?php | ||
|
||
namespace Superbalist\EventPubSub; | ||
|
||
class ValidationResult | ||
{ | ||
/** | ||
* @var EventValidatorInterface | ||
*/ | ||
protected $validator; | ||
|
||
/** | ||
* @var EventInterface | ||
*/ | ||
protected $event; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected $passes; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $errors; | ||
|
||
/** | ||
* @param EventValidatorInterface $validator | ||
* @param EventInterface $event | ||
* @param bool $passes | ||
* @param array $errors | ||
*/ | ||
public function __construct(EventValidatorInterface $validator, EventInterface $event, $passes, array $errors = []) | ||
{ | ||
$this->validator = $validator; | ||
$this->event = $event; | ||
$this->passes = $passes; | ||
$this->errors = $errors; | ||
} | ||
|
||
/** | ||
* @return EventValidatorInterface | ||
*/ | ||
public function getValidator() | ||
{ | ||
return $this->validator; | ||
} | ||
|
||
/** | ||
* @return EventInterface | ||
*/ | ||
public function getEvent() | ||
{ | ||
return $this->event; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function passes() | ||
{ | ||
return $this->passes; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function fails() | ||
{ | ||
return !$this->passes; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function errors() | ||
{ | ||
return $this->errors; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getErrors() | ||
{ | ||
return $this->errors(); | ||
} | ||
} |
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
Oops, something went wrong.