Created
June 19, 2018 15:07
-
-
Save vasildakov-zz/7694010dddc3c305d1ea35247c6287e0 to your computer and use it in GitHub Desktop.
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
<?php | |
interface Sign | |
{ | |
/** | |
* @param string $string | |
* @return string | |
*/ | |
public function __invoke(string $string) : 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
<?php | |
class SignatureService implements SignatureServiceInterface | |
{ | |
/** | |
* @param Sign $sign | |
* @param Verify $verify | |
*/ | |
public function __construct(Sign $sign, Verify $verify) | |
{ | |
$this->sign = $sign; | |
$this->verify = $verify; | |
} | |
public function sign(string $string) : string | |
{ | |
return ($this->sign)($string); | |
} | |
public function verify(string $signed, string $signature) : bool | |
{ | |
return ($this->verify)($signed, $signature); | |
} | |
} |
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
<?php | |
final class SignatureValidatorMiddleware implements MiddlewareInterface | |
{ | |
/** | |
* @param SignatureServiceInterface $service | |
*/ | |
private $service; | |
public function __construct(SignatureServiceInterface $service) | |
{ | |
$this->service = $service; | |
} | |
public function __invoke(ServerRequestInterface $request, ResponseInterface $response,callable $next = null) | |
{ | |
$this->service->validate($something); | |
} | |
} |
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
<?php | |
interface Verify | |
{ | |
/** | |
* @param string $string | |
* @param string $signature | |
* @return bool | |
*/ | |
public function __invoke(string $signed, string $signature) : bool; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment