-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Customize overwriting file and line in ValidationException
I've already changed the `ValidationException` so as not to let the file and line from the Validator.php [1]. However, one could go even further when creating more customizations on top of this library, and allowing to customize the line could be very useful. What motivated me making this change because it will be handy when I get back to work on [Assertion][]. [1]: 75a9b8e [Assertion]: https://github.com/Respect/Assertion
- Loading branch information
1 parent
1d1da7f
commit 549c744
Showing
5 changed files
with
125 additions
and
12 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,30 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright (c) Alexandre Gomes Gaigalas <[email protected]> | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Respect\Validation\Test\Stubs; | ||
|
||
use Respect\Validation\Exceptions\ValidationException; | ||
use Respect\Validation\Validator; | ||
use Respect\Validation\ValidatorDefaults; | ||
|
||
final class MyValidator | ||
{ | ||
public static function assertIntType(mixed $input): void | ||
{ | ||
$originalIgnoredBacktracePaths = ValidatorDefaults::getIgnoredBacktracePaths(); | ||
ValidatorDefaults::setIgnoredBacktracePaths(__FILE__, ...$originalIgnoredBacktracePaths); | ||
try { | ||
Validator::intType()->assert($input); | ||
} catch (ValidationException $exception) { | ||
// This is a workaround to avoid changing exceptions that are thrown in other places. | ||
ValidatorDefaults::setIgnoredBacktracePaths(...$originalIgnoredBacktracePaths); | ||
throw $exception; | ||
} | ||
} | ||
} |