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
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* @see https://github.com/zendframework/zend-config for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-config/blob/master/LICENSE.md New BSD License
*/
namespace Zend\Config;
use Psr\Container\ContainerInterface;
class StandaloneWriterPluginManager implements ContainerInterface
{
private $knownPlugins = [
'ini' => Writer\Ini::class,
'javaproperties' => Writer\JavaProperties::class,
'json' => Writer\Json::class,
'php' => Writer\PhpArray::class,
'phparray' => Writer\PhpArray::class,
'xml' => Writer\Xml::class,
'yaml' => Writer\Yaml::class,
];
/**
* @param string $plugin
* @return bool
*/
public function has($plugin)
{
if (in_array($plugin, array_values($this->knownPlugins), true)) {
return true;
}
return in_array(strtolower($plugin), array_keys($this->knownPlugins), true);
}
/**
* @param string $plugin
* @return Reader\ReaderInterface
* @throws Exception\PluginNotFoundException
*/
public function get($plugin)
{
if (! $this->has($plugin)) {
throw new Exception\PluginNotFoundException(sprintf(
'Config writer plugin by name %s not found',
$plugin
));
}
if (! class_exists($plugin)) {
$plugin = $this->knownPlugins[strtolower($plugin)];
}
return new $plugin();
}
}