for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace BEAR\Resource;
use BEAR\Resource\Exception\SchemeException;
use Override;
use function array_key_exists;
final class SchemeCollection implements SchemeCollectionInterface
{
private string $scheme = '';
private string $appName = '';
/** @var AdapterInterface[] */
private array $collection = [];
/**
* {@inheritDoc}
*/
#[Override]
public function scheme(string $scheme): SchemeCollectionInterface
$this->scheme = $scheme;
return $this;
}
public function host(string $host): SchemeCollectionInterface
$this->appName = $host;
public function toAdapter(AdapterInterface $adapter): SchemeCollectionInterface
$this->collection[$this->scheme . '://' . $this->appName] = $adapter;
*
* @throws SchemeException
public function getAdapter(AbstractUri $uri): AdapterInterface
$schemeIndex = $uri->scheme . '://' . $uri->host;
if (! array_key_exists($schemeIndex, $this->collection)) {
if ($uri->scheme === 'http' || $uri->scheme === 'https') {
return $this->collection['http://self'];
throw new SchemeException($uri->scheme . '://' . $uri->host);
return $this->collection[$schemeIndex];