|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace DoctrineORMModule\Service; |
|
21
|
|
|
|
|
22
|
|
|
use Doctrine\ORM\Cache\CacheConfiguration; |
|
23
|
|
|
use Doctrine\ORM\Cache\DefaultCacheFactory; |
|
24
|
|
|
use Doctrine\ORM\Cache\RegionsConfiguration; |
|
25
|
|
|
use Doctrine\ORM\Mapping\EntityListenerResolver; |
|
26
|
|
|
use DoctrineORMModule\Service\DBALConfigurationFactory as DoctrineConfigurationFactory; |
|
27
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
|
28
|
|
|
use Zend\ServiceManager\Exception\InvalidArgumentException; |
|
29
|
|
|
use Doctrine\ORM\Configuration; |
|
30
|
|
|
|
|
31
|
|
|
class ConfigurationFactory extends DoctrineConfigurationFactory |
|
32
|
|
|
{ |
|
33
|
72 |
|
public function createService(ServiceLocatorInterface $serviceLocator) |
|
34
|
|
|
{ |
|
35
|
|
|
/** @var $options \DoctrineORMModule\Options\Configuration */ |
|
36
|
72 |
|
$options = $this->getOptions($serviceLocator); |
|
37
|
72 |
|
$config = new Configuration(); |
|
38
|
|
|
|
|
39
|
72 |
|
$config->setAutoGenerateProxyClasses($options->getGenerateProxies()); |
|
40
|
72 |
|
$config->setProxyDir($options->getProxyDir()); |
|
41
|
72 |
|
$config->setProxyNamespace($options->getProxyNamespace()); |
|
42
|
|
|
|
|
43
|
72 |
|
$config->setEntityNamespaces($options->getEntityNamespaces()); |
|
44
|
|
|
|
|
45
|
72 |
|
$config->setCustomDatetimeFunctions($options->getDatetimeFunctions()); |
|
46
|
72 |
|
$config->setCustomStringFunctions($options->getStringFunctions()); |
|
47
|
72 |
|
$config->setCustomNumericFunctions($options->getNumericFunctions()); |
|
48
|
|
|
|
|
49
|
72 |
|
$config->setClassMetadataFactoryName($options->getClassMetadataFactoryName()); |
|
50
|
|
|
|
|
51
|
72 |
|
foreach ($options->getNamedQueries() as $name => $query) { |
|
52
|
|
|
$config->addNamedQuery($name, $query); |
|
53
|
72 |
|
} |
|
54
|
|
|
|
|
55
|
72 |
|
foreach ($options->getNamedNativeQueries() as $name => $query) { |
|
56
|
|
|
$config->addNamedNativeQuery($name, $query['sql'], new $query['rsm']); |
|
57
|
72 |
|
} |
|
58
|
|
|
|
|
59
|
72 |
|
foreach ($options->getCustomHydrationModes() as $modeName => $hydrator) { |
|
60
|
|
|
$config->addCustomHydrationMode($modeName, $hydrator); |
|
61
|
72 |
|
} |
|
62
|
|
|
|
|
63
|
72 |
|
foreach ($options->getFilters() as $name => $class) { |
|
64
|
|
|
$config->addFilter($name, $class); |
|
65
|
72 |
|
} |
|
66
|
|
|
|
|
67
|
72 |
|
$config->setMetadataCacheImpl($serviceLocator->get($options->getMetadataCache())); |
|
|
|
|
|
|
68
|
72 |
|
$config->setQueryCacheImpl($serviceLocator->get($options->getQueryCache())); |
|
|
|
|
|
|
69
|
72 |
|
$config->setResultCacheImpl($serviceLocator->get($options->getResultCache())); |
|
|
|
|
|
|
70
|
72 |
|
$config->setHydrationCacheImpl($serviceLocator->get($options->getHydrationCache())); |
|
|
|
|
|
|
71
|
72 |
|
$config->setMetadataDriverImpl($serviceLocator->get($options->getDriver())); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
72 |
|
if ($namingStrategy = $options->getNamingStrategy()) { |
|
74
|
3 |
|
if (is_string($namingStrategy)) { |
|
75
|
2 |
|
if (!$serviceLocator->has($namingStrategy)) { |
|
76
|
1 |
|
throw new InvalidArgumentException(sprintf('Naming strategy "%s" not found', $namingStrategy)); |
|
77
|
70 |
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
$config->setNamingStrategy($serviceLocator->get($namingStrategy)); |
|
|
|
|
|
|
80
|
1 |
|
} else { |
|
81
|
1 |
|
$config->setNamingStrategy($namingStrategy); |
|
82
|
|
|
} |
|
83
|
2 |
|
} |
|
84
|
|
|
|
|
85
|
71 |
|
if ($quoteStrategy = $options->getQuoteStrategy()) { |
|
86
|
3 |
|
if (is_string($quoteStrategy)) { |
|
87
|
2 |
|
if (!$serviceLocator->has($quoteStrategy)) { |
|
88
|
1 |
|
throw new InvalidArgumentException(sprintf('Quote strategy "%s" not found', $quoteStrategy)); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
1 |
|
$config->setQuoteStrategy($serviceLocator->get($quoteStrategy)); |
|
|
|
|
|
|
92
|
1 |
|
} else { |
|
93
|
1 |
|
$config->setQuoteStrategy($quoteStrategy); |
|
94
|
|
|
} |
|
95
|
2 |
|
} |
|
96
|
|
|
|
|
97
|
70 |
|
if ($repositoryFactory = $options->getRepositoryFactory()) { |
|
98
|
|
|
if (is_string($repositoryFactory)) { |
|
99
|
|
|
if (!$serviceLocator->has($repositoryFactory)) { |
|
100
|
|
|
throw new InvalidArgumentException( |
|
101
|
|
|
sprintf('Repository factory "%s" not found', $repositoryFactory) |
|
102
|
|
|
); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
$config->setRepositoryFactory($serviceLocator->get($repositoryFactory)); |
|
|
|
|
|
|
106
|
|
|
} else { |
|
107
|
|
|
$config->setRepositoryFactory($repositoryFactory); |
|
108
|
1 |
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
70 |
|
if ($entityListenerResolver = $options->getEntityListenerResolver()) { |
|
112
|
2 |
|
if ($entityListenerResolver instanceof EntityListenerResolver) { |
|
113
|
1 |
|
$config->setEntityListenerResolver($entityListenerResolver); |
|
114
|
1 |
|
} else { |
|
115
|
1 |
|
$config->setEntityListenerResolver($serviceLocator->get($entityListenerResolver)); |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
2 |
|
} |
|
118
|
|
|
|
|
119
|
70 |
|
$secondLevelCache = $options->getSecondLevelCache(); |
|
120
|
|
|
|
|
121
|
70 |
|
if ($secondLevelCache->isEnabled()) { |
|
122
|
1 |
|
$regionsConfig = new RegionsConfiguration( |
|
123
|
1 |
|
$secondLevelCache->getDefaultLifetime(), |
|
124
|
1 |
|
$secondLevelCache->getDefaultLockLifetime() |
|
125
|
1 |
|
); |
|
126
|
|
|
|
|
127
|
1 |
|
foreach ($secondLevelCache->getRegions() as $regionName => $regionConfig) { |
|
128
|
1 |
|
if (isset($regionConfig['lifetime'])) { |
|
129
|
1 |
|
$regionsConfig->setLifetime($regionName, $regionConfig['lifetime']); |
|
130
|
1 |
|
} |
|
131
|
|
|
|
|
132
|
1 |
|
if (isset($regionConfig['lock_lifetime'])) { |
|
133
|
1 |
|
$regionsConfig->setLockLifetime($regionName, $regionConfig['lock_lifetime']); |
|
134
|
1 |
|
} |
|
135
|
1 |
|
} |
|
136
|
|
|
|
|
137
|
|
|
// As Second Level Cache caches queries results, we reuse the result cache impl |
|
138
|
1 |
|
$cacheFactory = new DefaultCacheFactory($regionsConfig, $config->getResultCacheImpl()); |
|
|
|
|
|
|
139
|
1 |
|
$cacheFactory->setFileLockRegionDirectory($secondLevelCache->getFileLockRegionDirectory()); |
|
140
|
|
|
|
|
141
|
1 |
|
$cacheConfiguration = new CacheConfiguration(); |
|
142
|
1 |
|
$cacheConfiguration->setCacheFactory($cacheFactory); |
|
143
|
1 |
|
$cacheConfiguration->setRegionsConfiguration($regionsConfig); |
|
144
|
|
|
|
|
145
|
1 |
|
$config->setSecondLevelCacheEnabled(); |
|
146
|
1 |
|
$config->setSecondLevelCacheConfiguration($cacheConfiguration); |
|
147
|
1 |
|
} |
|
148
|
|
|
|
|
149
|
70 |
|
if ($className = $options->getDefaultRepositoryClassName()) { |
|
150
|
57 |
|
$config->setDefaultRepositoryClassName($className); |
|
151
|
57 |
|
} |
|
152
|
|
|
|
|
153
|
70 |
|
$this->setupDBALConfiguration($serviceLocator, $config); |
|
154
|
|
|
|
|
155
|
70 |
|
return $config; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
72 |
|
protected function getOptionsClass() |
|
159
|
|
|
{ |
|
160
|
72 |
|
return 'DoctrineORMModule\Options\Configuration'; |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: