| 1 |
<?php |
| 2 |
|
| 3 |
namespace Dudlewebs\WPMCS\s3\Aws\ClientSideMonitoring; |
| 4 |
|
| 5 |
class Configuration implements ConfigurationInterface |
| 6 |
{ |
| 7 |
private $clientId; |
| 8 |
private $enabled; |
| 9 |
private $host; |
| 10 |
private $port; |
| 11 |
/** |
| 12 |
* Constructs a new Configuration object with the specified CSM options set. |
| 13 |
* |
| 14 |
* @param mixed $enabled |
| 15 |
* @param string $host |
| 16 |
* @param string|int $port |
| 17 |
* @param string $clientId |
| 18 |
*/ |
| 19 |
public function __construct($enabled, $host, $port, $clientId = '') |
| 20 |
{ |
| 21 |
$this->host = $host; |
| 22 |
$this->port = \filter_var($port, \FILTER_VALIDATE_INT); |
| 23 |
if ($this->port === \false) { |
| 24 |
throw new \InvalidArgumentException("CSM 'port' value must be an integer!"); |
| 25 |
} |
| 26 |
// Unparsable $enabled flag errors on the side of disabling CSM |
| 27 |
$this->enabled = \filter_var($enabled, \FILTER_VALIDATE_BOOLEAN); |
| 28 |
$this->clientId = \trim($clientId); |
| 29 |
} |
| 30 |
/** |
| 31 |
* {@inheritdoc} |
| 32 |
*/ |
| 33 |
public function isEnabled() |
| 34 |
{ |
| 35 |
return $this->enabled; |
| 36 |
} |
| 37 |
/** |
| 38 |
* {@inheritdoc} |
| 39 |
*/ |
| 40 |
public function getClientId() |
| 41 |
{ |
| 42 |
return $this->clientId; |
| 43 |
} |
| 44 |
/** |
| 45 |
* /{@inheritdoc} |
| 46 |
*/ |
| 47 |
public function getHost() |
| 48 |
{ |
| 49 |
return $this->host; |
| 50 |
} |
| 51 |
/** |
| 52 |
* {@inheritdoc} |
| 53 |
*/ |
| 54 |
public function getPort() |
| 55 |
{ |
| 56 |
return $this->port; |
| 57 |
} |
| 58 |
/** |
| 59 |
* {@inheritdoc} |
| 60 |
*/ |
| 61 |
public function toArray() |
| 62 |
{ |
| 63 |
return ['client_id' => $this->getClientId(), 'enabled' => $this->isEnabled(), 'host' => $this->getHost(), 'port' => $this->getPort()]; |
| 64 |
} |
| 65 |
} |
| 66 |
|