-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
HorstOeko
committed
Oct 4, 2024
1 parent
9e9ce05
commit 99ef8cd
Showing
2 changed files
with
68 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/** | ||
* This file is a part of horstoeko/zugferdmail. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace horstoeko\zugferdmail\concerns; | ||
|
||
use RuntimeException; | ||
|
||
/** | ||
* Trait representing general facillities to raise | ||
* exceptions of several types | ||
* | ||
* @category ZugferdMail | ||
* @package ZugferdMail | ||
* @author D. Erling <horstoeko@erling.com.de> | ||
* @license https://opensource.org/licenses/MIT MIT | ||
* @link https://github.com/horstoeko/zugferdmail | ||
*/ | ||
trait ZugferdMailRaisesExceptions | ||
{ | ||
/** | ||
* Raise exception defined by $class if $condition is evaludated to trze | ||
* | ||
* @param boolean $condidition | ||
* @param string $exceptionClass | ||
* @param string $message | ||
* @return void | ||
*/ | ||
protected function raiseExceptionClassIf(bool $condidition, string $exceptionClass, string $message = "") | ||
{ | ||
if ($condidition !== true) { | ||
return; | ||
} | ||
|
||
throw new $exceptionClass($message); | ||
} | ||
|
||
/** | ||
* Raise Runtime Exception if $condition is evaludated to trze | ||
* | ||
* @param boolean $condidition | ||
* @param string $message | ||
* @return void | ||
*/ | ||
protected function raiseRuntimeExceptionIf(bool $condidition, string $message = ""): void | ||
{ | ||
$this->raiseExceptionClassIf($condidition, RuntimeException::class, $message); | ||
} | ||
} |