1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the PPI Framework. |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2011-2016 Paul Dragoonis <[email protected]> |
6
|
|
|
* @license http://opensource.org/licenses/mit-license.php MIT |
7
|
|
|
* |
8
|
|
|
* @link http://www.ppi.io |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace PPI\Framework\ServiceManager\Factory; |
12
|
|
|
|
13
|
|
|
use PPI\Framework\DataSource\ConnectionManager; |
14
|
|
|
use Zend\ServiceManager\FactoryInterface; |
15
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* DataSource Factory. |
19
|
|
|
* |
20
|
|
|
* @author Vítor Brandão <[email protected]> |
21
|
|
|
* @author Paul Dragoonis <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class DataSourceFactory implements FactoryInterface |
24
|
|
|
{ |
25
|
|
|
protected $connectionClassMap = array( |
26
|
|
|
'laravel' => 'PPI\Framework\DataSource\Connection\Laravel', |
27
|
|
|
'doctrine_dbal' => 'PPI\Framework\DataSource\Connection\DoctrineDBAL', |
28
|
|
|
'doctrine_mongdb' => 'PPI\Framework\DataSource\Connection\DoctrineMongoDB', |
29
|
|
|
'fuelphp' => 'PPI\Framework\DataSource\Connection\FuelPHP', |
30
|
|
|
'monga' => 'PPI\Framework\DataSource\Connection\Monga', |
31
|
|
|
'zend_db' => 'PPI\Framework\DataSource\Connection\ZendDb', |
32
|
|
|
); |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Create and return the datasource service. |
36
|
|
|
* |
37
|
|
|
* @param ServiceLocatorInterface $serviceLocator |
38
|
|
|
* |
39
|
|
|
* @return \PPI\Framework\DataSource\DataSource; |
|
|
|
|
40
|
|
|
*/ |
41
|
|
|
public function createService(ServiceLocatorInterface $serviceLocator) |
42
|
|
|
{ |
43
|
|
|
$config = $serviceLocator->get('ApplicationConfig'); |
44
|
|
|
$allConnections = $libraryToConnMap = $configMap = array(); |
|
|
|
|
45
|
|
|
|
46
|
|
|
// Early return |
47
|
|
|
if (!isset($config['datasource']['connections'])) { |
48
|
|
|
return new ConnectionManager($allConnections, $this->connectionClassMap); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
foreach ($config['datasource']['connections'] as $name => $config) { |
52
|
|
|
$allConnections[$name] = $config; |
53
|
|
|
$configMap[$config['library']][$name] = $config; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return new ConnectionManager($allConnections, $this->connectionClassMap); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.