-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfigFactory.php
More file actions
46 lines (42 loc) · 1.13 KB
/
ConfigFactory.php
File metadata and controls
46 lines (42 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/*
* This file is part of the Koded package.
*
* (c) Mihail Binev <mihail@kodeart.com>
*
* Please view the LICENSE distributed with this source code
* for the full copyright and license information.
*/
namespace Koded\Caching\Configuration;
use Koded\Stdlib\{Config, Configuration};
use Koded\Caching\CacheException;
use Throwable;
use function join;
use function ucfirst;
/**
* Class ConfigFactory
*
* @property int|null $ttl Default Time-To-Live seconds for the cached items
*
*/
class ConfigFactory extends Config
{
public function __construct(array $parameters = [])
{
parent::__construct();
$parameters && $this->import($parameters);
}
public function build(string $context): Configuration
{
try {
$class = join('\\', [__NAMESPACE__, ucfirst($context) . 'Configuration']);
return new $class($this->toArray());
// @codeCoverageIgnoreStart
} catch (CacheException $e) {
throw $e;
// @codeCoverageIgnoreEnd
} catch (Throwable) {
return new class($this->toArray()) extends CacheConfiguration {};
}
}
}