-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRepositoryRegistry.php
More file actions
78 lines (68 loc) · 1.83 KB
/
RepositoryRegistry.php
File metadata and controls
78 lines (68 loc) · 1.83 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Mapbender\DataSourceBundle\Component;
use Doctrine\DBAL\Connection;
use Mapbender\DataSourceBundle\Component\Factory\DataStoreFactory;
/**
* Container-unaware (Symfony 4+) portions of DataStoreService / FeatureTypeService
*
* @since 0.1.22
*/
class RepositoryRegistry
{
/** @var DataStoreFactory */
protected $factory;
/** @var mixed[][] */
protected $repositoryConfigs;
/** @var DataStore[] */
protected $repositories = array();
/**
* @param DataStoreFactory $factory
* @param mixed[][] $repositoryConfigs
*/
public function __construct(DataStoreFactory $factory,
array $repositoryConfigs)
{
$this->factory = $factory;
$this->repositoryConfigs = $repositoryConfigs;
}
/**
* @param array $config
* @return DataStore
*/
public function dataStoreFactory(array $config)
{
return $this->factory->fromConfig($config);
}
/**
* @param string $name
* @return DataStore
* @since 0.1.15
*/
public function getDataStoreByName($name)
{
if (!$name) {
throw new \InvalidArgumentException("Empty dataStore / featureType name " . var_export($name, true));
}
if (!\array_key_exists($name, $this->repositories)) {
$this->repositories[$name] = $this->dataStoreFactory($this->repositoryConfigs[$name]);
}
return $this->repositories[$name];
}
/**
* @return mixed[][]
* @since 0.1.8
*/
public function getDataStoreDeclarations()
{
return $this->repositoryConfigs;
}
/**
* @param string $name
* @return Connection
* @since 0.0.16
*/
public function getDbalConnectionByName($name)
{
return $this->factory->getDbalConnectionByName($name);
}
}