| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws; |
| 4 |
|
| 5 |
/** |
| 6 |
* AWS command object. |
| 7 |
*/ |
| 8 |
class Command implements CommandInterface |
| 9 |
{ |
| 10 |
use HasDataTrait; |
| 11 |
/** @var string */ |
| 12 |
private $name; |
| 13 |
/** @var HandlerList */ |
| 14 |
private $handlerList; |
| 15 |
/** @var array */ |
| 16 |
private $authSchemes; |
| 17 |
/** @var MetricsBuilder */ |
| 18 |
private $metricsBuilder; |
| 19 |
/** |
| 20 |
* Accepts an associative array of command options, including: |
| 21 |
* |
| 22 |
* - @http: (array) Associative array of transfer options. |
| 23 |
* |
| 24 |
* @param string $name Name of the command |
| 25 |
* @param array $args Arguments to pass to the command |
| 26 |
* @param HandlerList $list Handler list |
| 27 |
*/ |
| 28 |
public function __construct($name, array $args = [], ?HandlerList $list = null, ?MetricsBuilder $metricsBuilder = null) |
| 29 |
{ |
| 30 |
$this->name = $name; |
| 31 |
$this->data = $args; |
| 32 |
$this->handlerList = $list ?: new HandlerList(); |
| 33 |
if (!isset($this->data['@http'])) { |
| 34 |
$this->data['@http'] = []; |
| 35 |
} |
| 36 |
if (!isset($this->data['@context'])) { |
| 37 |
$this->data['@context'] = []; |
| 38 |
} |
| 39 |
$this->metricsBuilder = $metricsBuilder ?: new MetricsBuilder(); |
| 40 |
} |
| 41 |
public function __clone() |
| 42 |
{ |
| 43 |
$this->handlerList = clone $this->handlerList; |
| 44 |
} |
| 45 |
public function getName() |
| 46 |
{ |
| 47 |
return $this->name; |
| 48 |
} |
| 49 |
public function hasParam($name) |
| 50 |
{ |
| 51 |
return \array_key_exists($name, $this->data); |
| 52 |
} |
| 53 |
public function getHandlerList() |
| 54 |
{ |
| 55 |
return $this->handlerList; |
| 56 |
} |
| 57 |
/** |
| 58 |
* For overriding auth schemes on a per endpoint basis when using |
| 59 |
* EndpointV2 provider. Intended for internal use only. |
| 60 |
* |
| 61 |
* @param array $authSchemes |
| 62 |
* |
| 63 |
* @deprecated In favor of using the @context property bag. |
| 64 |
* Auth Schemes are now accessible via the `signature_version` key |
| 65 |
* in a Command's context, if applicable. Auth Schemes set using |
| 66 |
* This method are no longer consumed. |
| 67 |
* |
| 68 |
* @internal |
| 69 |
*/ |
| 70 |
public function setAuthSchemes(array $authSchemes) |
| 71 |
{ |
| 72 |
\trigger_error(__METHOD__ . ' is deprecated. Auth schemes ' . 'resolved using the service `auth` trait or via endpoint resolution ' . 'are now set in the command `@context` property.`', \E_USER_WARNING); |
| 73 |
$this->authSchemes = $authSchemes; |
| 74 |
} |
| 75 |
/** |
| 76 |
* Get auth schemes added to command as required |
| 77 |
* for endpoint resolution |
| 78 |
* |
| 79 |
* @returns array |
| 80 |
* |
| 81 |
* @deprecated In favor of using the @context property bag. |
| 82 |
* Auth schemes are now accessible via the `signature_version` key |
| 83 |
* in a Command's context, if applicable. |
| 84 |
*/ |
| 85 |
public function getAuthSchemes() |
| 86 |
{ |
| 87 |
\trigger_error(__METHOD__ . ' is deprecated. Auth schemes ' . 'resolved using the service `auth` trait or via endpoint resolution ' . 'can now be found in the command `@context` property.`', \E_USER_WARNING); |
| 88 |
return $this->authSchemes ?: []; |
| 89 |
} |
| 90 |
/** @deprecated */ |
| 91 |
public function get($name) |
| 92 |
{ |
| 93 |
return $this[$name]; |
| 94 |
} |
| 95 |
/** |
| 96 |
* Returns the metrics builder instance tied up to this command. |
| 97 |
* |
| 98 |
* @internal |
| 99 |
* |
| 100 |
* @return MetricsBuilder |
| 101 |
*/ |
| 102 |
public function getMetricsBuilder() : MetricsBuilder |
| 103 |
{ |
| 104 |
return $this->metricsBuilder; |
| 105 |
} |
| 106 |
} |
| 107 |
|