-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from clear01/master
Add better exception for PacketAttributesFault
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 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,32 @@ | ||
<?php | ||
|
||
namespace Salamek\Zasilkovna\Exception; | ||
|
||
use function is_array; | ||
|
||
class PacketAttributesFault extends \Exception | ||
{ | ||
|
||
private $fails; | ||
|
||
public function __construct($fails) | ||
{ | ||
|
||
$fails = !is_array($fails) ? [$fails] : $fails; | ||
|
||
foreach ($fails as $fail) { | ||
$this->fails[$fail->name] = $fail->fault; | ||
} | ||
parent::__construct($this->__toString()); | ||
} | ||
|
||
public function __toString() | ||
{ | ||
$string = ''; | ||
foreach ($this->fails as $name => $fail) { | ||
$string .= $name . ': ' . $fail . ', '; | ||
} | ||
|
||
return trim($string, ', '); | ||
} | ||
} |