1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace T4web\DomainModule\Infrastructure; |
4
|
|
|
|
5
|
|
|
use Zend\Db\TableGateway\TableGateway; |
6
|
|
|
use Zend\ServiceManager\AbstractFactoryInterface; |
7
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
8
|
|
|
use T4webInfrastructure\Repository; |
9
|
|
|
use T4webInfrastructure\Config; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Create Service by template: |
13
|
|
|
* MODULE-NAME\ENTITY-NAME\Infrastructure\Repository |
14
|
|
|
* |
15
|
|
|
* @package T4web\DomainModule\Infrastructure |
16
|
|
|
*/ |
17
|
|
|
class RepositoryAbstractFactory implements AbstractFactoryInterface |
18
|
|
|
{ |
19
|
|
|
public function canCreateServiceWithName(ServiceLocatorInterface $serviceManager, $name, $requestedName) |
20
|
|
|
{ |
21
|
|
|
return substr($requestedName, -strlen('Infrastructure\Repository')) == 'Infrastructure\Repository'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function createServiceWithName(ServiceLocatorInterface $serviceManager, $name, $requestedName) |
25
|
|
|
{ |
26
|
|
|
$namespace = strstr($requestedName, 'Infrastructure\Repository', true); |
27
|
|
|
|
28
|
|
|
list($moduleName, $entityName) = explode('\\', $namespace); |
29
|
|
|
|
30
|
|
|
$dbAdapter = $serviceManager->get('Zend\Db\Adapter\Adapter'); |
31
|
|
|
/** @var Config $config */ |
32
|
|
|
$config = $serviceManager->get("$moduleName\\$entityName\\Infrastructure\\Config"); |
33
|
|
|
|
34
|
|
|
$features = []; |
35
|
|
|
$tableSequence = $config->getSequence($entityName); |
|
|
|
|
36
|
|
|
$tablePrimaryKey = $config->getPrimaryKey($entityName); |
|
|
|
|
37
|
|
|
if (!empty($tableSequence) && !empty($tablePrimaryKey)) { |
38
|
|
|
$features[] = new SequenceFeature($tablePrimaryKey, $tableSequence); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$tableGateway = new TableGateway($config->getTable($entityName), $dbAdapter, $features); |
|
|
|
|
42
|
|
|
|
43
|
|
|
$eventManager = $serviceManager->get('EventManager'); |
44
|
|
|
$eventManager->addIdentifiers($requestedName); |
45
|
|
|
|
46
|
|
|
return new Repository( |
47
|
|
|
$entityName, |
48
|
|
|
$serviceManager->get("$moduleName\\$entityName\\Infrastructure\\CriteriaFactory"), |
|
|
|
|
49
|
|
|
$tableGateway, |
50
|
|
|
$serviceManager->get("$moduleName\\$entityName\\Infrastructure\\Mapper"), |
|
|
|
|
51
|
|
|
$config, |
52
|
|
|
$eventManager |
|
|
|
|
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.