AddonFactory.php
856 Bytes
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
<?php
declare(strict_types=1);
namespace ACP;
use AC\Asset\Location\Absolute;
use AC\Registerable;
use AC\Vendor\Psr\Container\ContainerInterface;
use DomainException;
final class AddonFactory
{
private $addons;
private $location;
private $container;
public function __construct(array $addons, Absolute $location, ContainerInterface $container)
{
$this->addons = $addons;
$this->location = $location;
$this->container = $container;
}
public function create(string $key): Registerable
{
$addon = $this->addons[$key] ?? null;
if (null === $addon) {
throw new DomainException(sprintf('Addon %s does not exist', $key));
}
return new $addon(
$this->location->with_suffix('addons/' . $key),
$this->container
);
}
}