2024-02-02 20:56:25 +00:00
|
|
|
<?php
|
|
|
|
|
2024-02-19 00:30:12 +00:00
|
|
|
namespace Wallabag\SiteConfig;
|
2024-02-02 20:56:25 +00:00
|
|
|
|
|
|
|
class ArraySiteConfigBuilder implements SiteConfigBuilder
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Map of hostname => SiteConfig.
|
|
|
|
*/
|
|
|
|
private $configs = [];
|
|
|
|
|
|
|
|
public function __construct(array $hostConfigMap = [])
|
|
|
|
{
|
|
|
|
foreach ($hostConfigMap as $host => $hostConfig) {
|
|
|
|
$hostConfig['host'] = $host;
|
|
|
|
$this->configs[$host] = new SiteConfig($hostConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildForHost($host)
|
|
|
|
{
|
|
|
|
$host = strtolower($host);
|
|
|
|
|
|
|
|
if ('www.' === substr($host, 0, 4)) {
|
|
|
|
$host = substr($host, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($this->configs[$host])) {
|
|
|
|
return $this->configs[$host];
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|