1 | <?php |
||
19 | class EntityStoreFromConfigurationBuilder { |
||
20 | |||
21 | /** |
||
22 | * @param string $configurationFileName |
||
23 | * @return EntityStore |
||
24 | */ |
||
25 | 2 | public function buildEntityStore( $configurationFileName ) { |
|
40 | |||
41 | /** |
||
42 | * @param string $configurationFileName |
||
43 | * @return Cache |
||
44 | */ |
||
45 | public function buildCache( $configurationFileName ) { |
||
46 | $config = $this->parseConfiguration( $configurationFileName ); |
||
47 | |||
48 | if( !array_key_exists( 'cache', $config ) ) { |
||
49 | throw new InvalidArgumentException( 'No cache key in configuration' ); |
||
50 | } |
||
51 | return $this->buildCacheFromConfig( $config['cache'] ); |
||
52 | } |
||
53 | |||
54 | 2 | private function buildEntityStoreFromConfig( $config ) { |
|
55 | 2 | $options = new EntityStoreOptions( $config['options'] ); |
|
56 | |||
57 | 2 | switch( $config['backend'] ) { |
|
58 | 2 | case 'api': |
|
59 | 1 | return new ApiEntityStore( |
|
60 | 1 | $this->getWikibaseApi( $config['api'] ), |
|
61 | 1 | $this->getWikidataQueryApi( $config['api'] ), |
|
62 | $options |
||
63 | 1 | ); |
|
64 | 1 | case 'mongodb': |
|
65 | 2 | return new MongoDBEntityStore( $this->getMongoDbDatabase( $config['mongodb'] ), $options ); |
|
66 | 1 | default: |
|
67 | throw new InvalidArgumentException( 'Unknown backend: ' . $config['backend'] ); |
||
68 | } |
||
69 | 1 | } |
|
70 | |||
71 | 1 | private function getWikibaseApi( $config ) { |
|
74 | |||
75 | 1 | private function getWikidataQueryApi( $config ) { |
|
82 | |||
83 | 1 | private function getMongoDbDatabase( $config ) { |
|
92 | |||
93 | 1 | private function buildCacheFromConfig( $config ) { |
|
121 | |||
122 | 2 | private function parseConfiguration( $configurationFileName ) { |
|
132 | } |
||
133 |