1 <?php
2
3 namespace Balance\Db\TableGateway;
4
5 use Zend\Db;
6 use Zend\ServiceManager\AbstractFactoryInterface;
7 use Zend\ServiceManager\ServiceLocatorInterface;
8
9 10 11
12 class AbstractTableGatewayFactory implements AbstractFactoryInterface
13 {
14 15 16
17 public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
18 {
19
20 $config = $serviceLocator->get('Config')['balance_manager']['factories'];
21
22 return
23 isset($config[$requestedName])
24 && isset($config[$requestedName]['factory'])
25 && $config[$requestedName]['factory'] === __CLASS__
26 && isset($config[$requestedName]['params'])
27 && isset($config[$requestedName]['params']['table']);
28 }
29
30 31 32
33 public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
34 {
35
36 $config = $serviceLocator->get('Config')['balance_manager']['factories'][$requestedName];
37
38 $table = new Db\TableGateway\TableGateway($config['params']['table'], $serviceLocator->get('db'));
39
40 if (isset($config['params']['primary_key']) && isset($config['params']['sequence'])) {
41
42 $table->getFeatureSet()->addFeature(
43 new Db\TableGateway\Feature\SequenceFeature(
44 $config['params']['primary_key'],
45 $config['params']['sequence']
46 )
47 );
48 }
49
50 return $table;
51 }
52 }
53