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
|
69 |
|
public function createService(ServiceLocatorInterface $serviceLocator) |
34
|
|
|
{ |
35
|
|
|
/** @var $options \DoctrineORMModule\Options\Configuration */ |
36
|
69 |
|
$options = $this->getOptions($serviceLocator); |
37
|
69 |
|
$config = new Configuration(); |
38
|
|
|
|
39
|
69 |
|
$config->setAutoGenerateProxyClasses($options->getGenerateProxies()); |
40
|
69 |
|
$config->setProxyDir($options->getProxyDir()); |
41
|
69 |
|
$config->setProxyNamespace($options->getProxyNamespace()); |
42
|
|
|
|
43
|
69 |
|
$config->setEntityNamespaces($options->getEntityNamespaces()); |
44
|
|
|
|
45
|
69 |
|
$config->setCustomDatetimeFunctions($options->getDatetimeFunctions()); |
46
|
69 |
|
$config->setCustomStringFunctions($options->getStringFunctions()); |
47
|
69 |
|
$config->setCustomNumericFunctions($options->getNumericFunctions()); |
48
|
|
|
|
49
|
69 |
|
$config->setClassMetadataFactoryName($options->getClassMetadataFactoryName()); |
50
|
|
|
|
51
|
69 |
|
foreach ($options->getNamedQueries() as $name => $query) { |
52
|
|
|
$config->addNamedQuery($name, $query); |
53
|
69 |
|
} |
54
|
|
|
|
55
|
69 |
|
foreach ($options->getNamedNativeQueries() as $name => $query) { |
56
|
|
|
$config->addNamedNativeQuery($name, $query['sql'], new $query['rsm']); |
57
|
69 |
|
} |
58
|
|
|
|
59
|
69 |
|
foreach ($options->getCustomHydrationModes() as $modeName => $hydrator) { |
60
|
|
|
$config->addCustomHydrationMode($modeName, $hydrator); |
61
|
69 |
|
} |
62
|
|
|
|
63
|
69 |
|
foreach ($options->getFilters() as $name => $class) { |
64
|
|
|
$config->addFilter($name, $class); |
65
|
69 |
|
} |
66
|
|
|
|
67
|
69 |
|
$config->setMetadataCacheImpl($serviceLocator->get($options->getMetadataCache())); |
|
|
|
|
68
|
69 |
|
$config->setQueryCacheImpl($serviceLocator->get($options->getQueryCache())); |
|
|
|
|
69
|
69 |
|
$config->setResultCacheImpl($serviceLocator->get($options->getResultCache())); |
|
|
|
|
70
|
69 |
|
$config->setHydrationCacheImpl($serviceLocator->get($options->getHydrationCache())); |
|
|
|
|
71
|
69 |
|
$config->setMetadataDriverImpl($serviceLocator->get($options->getDriver())); |
|
|
|
|
72
|
|
|
|
73
|
69 |
|
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
|
68 |
|
} |
78
|
|
|
|
79
|
1 |
|
$config->setNamingStrategy($serviceLocator->get($namingStrategy)); |
|
|
|
|
80
|
1 |
|
} else { |
81
|
1 |
|
$config->setNamingStrategy($namingStrategy); |
82
|
|
|
} |
83
|
2 |
|
} |
84
|
|
|
|
85
|
68 |
|
if ($quoteStrategy = $options->getQuoteStrategy()) { |
86
|
|
|
if (is_string($quoteStrategy)) { |
87
|
|
|
if (!$serviceLocator->has($quoteStrategy)) { |
88
|
|
|
throw new InvalidArgumentException(sprintf('Quote strategy "%s" not found', $quoteStrategy)); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$config->setQuoteStrategy($serviceLocator->get($quoteStrategy)); |
|
|
|
|
92
|
|
|
} else { |
93
|
|
|
$config->setQuoteStrategy($quoteStrategy); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
68 |
|
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
|
68 |
|
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
|
68 |
|
$secondLevelCache = $options->getSecondLevelCache(); |
120
|
|
|
|
121
|
68 |
|
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
|
68 |
|
if ($className = $options->getDefaultRepositoryClassName()) { |
150
|
57 |
|
$config->setDefaultRepositoryClassName($className); |
151
|
57 |
|
} |
152
|
|
|
|
153
|
68 |
|
$this->setupDBALConfiguration($serviceLocator, $config); |
154
|
|
|
|
155
|
68 |
|
return $config; |
156
|
|
|
} |
157
|
|
|
|
158
|
69 |
|
protected function getOptionsClass() |
159
|
|
|
{ |
160
|
69 |
|
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: