-
-
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
Showing
13 changed files
with
191 additions
and
122 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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PetrKnap\Binary\Coder; | ||
|
||
use Throwable; | ||
|
||
abstract class Coder implements CoderInterface | ||
{ | ||
public function encode(string $decoded): string | ||
{ | ||
try { | ||
return $this->doEncode($decoded); | ||
} catch (Throwable $reason) { | ||
if ($reason instanceof Exception\CouldNotEncodeData) { | ||
throw $reason; | ||
} | ||
throw new Exception\CouldNotEncodeData(__METHOD__, $decoded, $reason); | ||
} | ||
} | ||
|
||
public function decode(string $encoded): string | ||
{ | ||
try { | ||
return $this->doDecode($encoded); | ||
} catch (Throwable $reason) { | ||
if ($reason instanceof Exception\CouldNotDecodeData) { | ||
throw $reason; | ||
} | ||
throw new Exception\CouldNotDecodeData(__METHOD__, $encoded, $reason); | ||
} | ||
} | ||
|
||
/** | ||
* @throws Throwable | ||
*/ | ||
|
||
abstract protected function doEncode(string $decoded): string; | ||
|
||
/** | ||
* @throws Throwable | ||
*/ | ||
abstract protected function doDecode(string $encoded): string; | ||
} |
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
Oops, something went wrong.