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\DBAL\DriverManager; |
23
|
|
|
use Doctrine\DBAL\Types\Type; |
24
|
|
|
use DoctrineModule\Service\AbstractFactory; |
25
|
|
|
use Zend\ServiceManager\ServiceLocatorInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* DBAL Connection ServiceManager factory |
29
|
|
|
* |
30
|
|
|
* @license MIT |
31
|
|
|
* @link http://www.doctrine-project.org/ |
32
|
|
|
* @author Kyle Spraggs <[email protected]> |
33
|
|
|
*/ |
34
|
|
|
class DBALConnectionFactory extends AbstractFactory |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* {@inheritDoc} |
38
|
|
|
* @return \Doctrine\DBAL\Connection |
39
|
|
|
*/ |
40
|
58 |
|
public function createService(ServiceLocatorInterface $sl) |
41
|
|
|
{ |
42
|
|
|
/** @var $options \DoctrineORMModule\Options\DBALConnection */ |
43
|
58 |
|
$options = $this->getOptions($sl, 'connection'); |
44
|
58 |
|
$pdo = $options->getPdo(); |
45
|
|
|
|
46
|
58 |
|
if (is_string($pdo)) { |
47
|
|
|
$pdo = $sl->get($pdo); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$params = array( |
51
|
58 |
|
'driverClass' => $options->getDriverClass(), |
52
|
58 |
|
'wrapperClass' => $options->getWrapperClass(), |
53
|
58 |
|
'pdo' => $pdo, |
54
|
58 |
|
); |
55
|
58 |
|
$params = array_merge($params, $options->getParams()); |
56
|
|
|
|
57
|
58 |
|
$configuration = $sl->get($options->getConfiguration()); |
58
|
58 |
|
$eventManager = $sl->get($options->getEventManager()); |
59
|
|
|
|
60
|
58 |
|
$connection = DriverManager::getConnection($params, $configuration, $eventManager); |
|
|
|
|
61
|
58 |
|
$platform = $connection->getDatabasePlatform(); |
62
|
58 |
|
foreach ($options->getDoctrineTypeMappings() as $dbType => $doctrineType) { |
63
|
2 |
|
$platform->registerDoctrineTypeMapping($dbType, $doctrineType); |
64
|
58 |
|
} |
65
|
|
|
|
66
|
58 |
|
foreach ($options->getDoctrineCommentedTypes() as $type) { |
67
|
1 |
|
$platform->markDoctrineTypeCommented(Type::getType($type)); |
68
|
58 |
|
} |
69
|
|
|
|
70
|
58 |
|
return $connection; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the class name of the options associated with this factory. |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
58 |
|
public function getOptionsClass() |
79
|
|
|
{ |
80
|
58 |
|
return 'DoctrineORMModule\Options\DBALConnection'; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
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: