| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Rest\BasicAccess; |
| 4 |
|
| 5 |
use MediaWiki\Rest\Handler; |
| 6 |
use MediaWiki\Rest\RequestInterface; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
class CompoundAuthorizer implements BasicAuthorizerInterface { |
| 15 |
|
| 16 |
|
| 17 |
private $authorizers; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
public function __construct( array $authorizers = [] ) { |
| 23 |
$this->authorizers = $authorizers; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public function addAuthorizer( BasicAuthorizerInterface $authorizer ): CompoundAuthorizer { |
| 32 |
$this->authorizers[] = $authorizer; |
| 33 |
return $this; |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 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 |
} |