Open Journal Systems  3.3.0
Matching.php
1 <?php
2 
4 
8 
9 @trigger_error('The '.__NAMESPACE__.'\Matching class is deprecated since version 1.2 and will be removed in 2.0. Use Http\Message\Authentication\RequestConditional instead.', E_USER_DEPRECATED);
10 
18 final class Matching implements Authentication
19 {
23  private $authentication;
24 
28  private $matcher;
29 
34  public function __construct(Authentication $authentication, callable $matcher = null)
35  {
36  if (is_null($matcher)) {
37  $matcher = function () {
38  return true;
39  };
40  }
41 
42  $this->authentication = $authentication;
43  $this->matcher = new CallbackRequestMatcher($matcher);
44  }
45 
49  public function authenticate(RequestInterface $request)
50  {
51  if ($this->matcher->matches($request)) {
52  return $this->authentication->authenticate($request);
53  }
54 
55  return $request;
56  }
57 
66  public static function createUrlMatcher(Authentication $authentication, $url)
67  {
68  $matcher = function (RequestInterface $request) use ($url) {
69  return preg_match($url, $request->getRequestTarget());
70  };
71 
72  return new static($authentication, $matcher);
73  }
74 }
Http\Message\Authentication
Definition: AutoBasicAuth.php:3
Psr\Http\Message\RequestInterface
Definition: vendor/psr/http-message/src/RequestInterface.php:24
Psr\Http\Message\RequestInterface\getRequestTarget
getRequestTarget()
Http\Message\Authentication\Matching
Definition: Matching.php:18
Http\Message\Authentication
Definition: Authentication.php:12
Http\Message\Authentication\Matching\createUrlMatcher
static createUrlMatcher(Authentication $authentication, $url)
Definition: Matching.php:72
Http\Message\Authentication\Matching\__construct
__construct(Authentication $authentication, callable $matcher=null)
Definition: Matching.php:40
Http\Message\Authentication\Matching\authenticate
authenticate(RequestInterface $request)
Definition: Matching.php:55
Http\Message\RequestMatcher\CallbackRequestMatcher
Definition: CallbackRequestMatcher.php:13