Skip to content

Commit

Permalink
#51: Add SSL Server settings via ServerConfig
Browse files Browse the repository at this point in the history
- fix setters to be fluent
  • Loading branch information
arthurkushman committed Dec 27, 2020
1 parent 0f7687e commit 6db9477
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 29 deletions.
55 changes: 40 additions & 15 deletions src/Components/ClientConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use WSSC\Contracts\WscCommonsContract;

/**
* Class ClientConfig
* @package WSSC\Components
*/
class ClientConfig
{
private $scheme;
Expand Down Expand Up @@ -35,10 +39,12 @@ public function getTimeout(): int

/**
* @param int $timeout
* @return ClientConfig
*/
public function setTimeout(int $timeout)
public function setTimeout(int $timeout): ClientConfig
{
$this->timeout = $timeout;
return $this;
}

/**
Expand All @@ -51,10 +57,12 @@ public function getHeaders(): array

/**
* @param array $headers
* @return ClientConfig
*/
public function setHeaders(array $headers)
public function setHeaders(array $headers): ClientConfig
{
$this->headers = $headers;
return $this;
}

/**
Expand All @@ -67,10 +75,12 @@ public function getFragmentSize(): int

/**
* @param int $fragmentSize
* @return ClientConfig
*/
public function setFragmentSize(int $fragmentSize)
public function setFragmentSize(int $fragmentSize): ClientConfig
{
$this->fragmentSize = $fragmentSize;
return $this;
}

/**
Expand All @@ -83,10 +93,12 @@ public function getContext()

/**
* @param mixed $context
* @return ClientConfig
*/
public function setContext($context)
public function setContext($context): ClientConfig
{
$this->context = $context;
return $this;
}

/**
Expand All @@ -99,10 +111,12 @@ public function getScheme(): string

/**
* @param void $scheme
* @return ClientConfig
*/
public function setScheme($scheme): void
public function setScheme($scheme): ClientConfig
{
$this->scheme = $scheme;
return $this;
}

/**
Expand All @@ -115,10 +129,12 @@ public function getHost(): string

/**
* @param void $host
* @return ClientConfig
*/
public function setHost($host): void
public function setHost($host): ClientConfig
{
$this->host = $host;
return $this;
}

/**
Expand All @@ -131,10 +147,12 @@ public function getUser(): string

/**
* @param array $urlParts
* @return ClientConfig
*/
public function setUser(array $urlParts): void
public function setUser(array $urlParts): ClientConfig
{
$this->user = isset($urlParts['user']) ? $urlParts['user'] : '';
$this->user = $urlParts['user'] ?? '';
return $this;
}

/**
Expand All @@ -148,9 +166,10 @@ public function getPassword(): string
/**
* @param array $urlParts
*/
public function setPassword(array $urlParts): void
public function setPassword(array $urlParts): ClientConfig
{
$this->password = isset($urlParts['pass']) ? $urlParts['pass'] : '';
$this->password = $urlParts['pass'] ?? '';
return $this;
}

/**
Expand All @@ -164,9 +183,10 @@ public function getPort(): string
/**
* @param array $urlParts
*/
public function setPort(array $urlParts): void
public function setPort(array $urlParts): ClientConfig
{
$this->port = isset($urlParts['port']) ? $urlParts['port'] : ($this->scheme === 'wss' ? '443' : '80');
$this->port = $urlParts['port'] ?? ($this->scheme === 'wss' ? '443' : '80');
return $this;
}

/**
Expand All @@ -179,21 +199,25 @@ public function getContextOptions(): array

/**
* @param array $contextOptions
* @return ServerConfig
*/
public function setContextOptions($contextOptions): void
public function setContextOptions(array $contextOptions): ClientConfig
{
$this->contextOptions = $contextOptions;
return $this;
}

/**
* @param string $ip
* @param string $port
*/
public function setProxy(string $ip, string $port): void
public function setProxy(string $ip, string $port): ClientConfig
{
$this->hasProxy = true;
$this->proxyIp = $ip;
$this->proxyPort = $port;

return $this;
}

/**
Expand All @@ -202,9 +226,10 @@ public function setProxy(string $ip, string $port): void
* @param string $userName
* @param string $password
*/
public function setProxyAuth(string $userName, string $password): void
public function setProxyAuth(string $userName, string $password): ClientConfig
{
$this->proxyAuth = (empty($userName) === false && empty($password) === false) ? base64_encode($userName.':'.$password) : null;
return $this;
}

/**
Expand Down
Loading

0 comments on commit 6db9477

Please sign in to comment.