Debian Codegraph @

includes/Rest/BasicAccess/CompoundAuthorizer.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Rest\BasicAccess;
4
5 use MediaWiki\Rest\Handler;
6 use MediaWiki\Rest\RequestInterface;
7
8 /**
9 * Wraps an array of BasicAuthorizerInterface and checks them
10 * all to authorize the request
11 * @internal
12 * @package MediaWiki\Rest\BasicAccess
13 */
14 class CompoundAuthorizer implements BasicAuthorizerInterface {
15
16 /** @var BasicAuthorizerInterface[] */
17 private $authorizers;
18
19 /**
20 * @param array $authorizers
21 */
22 public function __construct( array $authorizers = [] ) {
23 $this->authorizers = $authorizers;
24 }
25
26 /**
27 * Adds a BasicAuthorizerInterface to the chain of authorizers.
28 * @param BasicAuthorizerInterface $authorizer
29 * @return CompoundAuthorizer
30 */
31 public function addAuthorizer( BasicAuthorizerInterface $authorizer ): CompoundAuthorizer {
32 $this->authorizers[] = $authorizer;
33 return $this;
34 }
35
36 /**
37 * Checks all registered authorizers and returns the first encountered error.
38 * @param RequestInterface $request
39 * @param Handler $handler
40 * @return string|null
41 */
42 public function authorize( RequestInterface $request, Handler $handler ) {
43 foreach ( $this->authorizers as $authorizer ) {
44 $result = $authorizer->authorize( $request, $handler );
45 if ( $result ) {
46 return $result;
47 }
48 }
49 return null;
50 }
51 }