Skip to content

Instantly share code, notes, and snippets.

@vasildakov-zz
Created June 19, 2018 15:07
Show Gist options
  • Save vasildakov-zz/7694010dddc3c305d1ea35247c6287e0 to your computer and use it in GitHub Desktop.
Save vasildakov-zz/7694010dddc3c305d1ea35247c6287e0 to your computer and use it in GitHub Desktop.
<?php
interface Sign
{
/**
* @param string $string
* @return string
*/
public function __invoke(string $string) : string;
}
<?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);
}
}
<?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);
}
}
<?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