1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrs\StoredProcedureBundle\Utils; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
|
|
|
6
|
|
|
use Doctrs\StoredProcedureBundle\Event\ChangeConnectionEvent; |
7
|
|
|
use Doctrs\StoredProcedureBundle\Event\ChangeConnectionNameEvent; |
8
|
|
|
use Doctrs\StoredProcedureBundle\Event\ChangeResultEvent; |
9
|
|
|
use Doctrs\StoredProcedureBundle\Event\StoredProcedureEvents; |
10
|
|
|
use PgFunc\Configuration; |
11
|
|
|
use PgFunc\Connection; |
12
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
13
|
|
|
use Symfony\Component\DependencyInjection\Exception\BadMethodCallException; |
14
|
|
|
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; |
15
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
|
|
|
|
16
|
|
|
|
17
|
|
|
class Procedure implements ProcedureInterface |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var ArrayCollection |
21
|
|
|
*/ |
22
|
|
|
private $configurations; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var ArrayCollection |
26
|
|
|
*/ |
27
|
|
|
private $connections; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var EventDispatcher |
31
|
|
|
*/ |
32
|
|
|
private $dispatcher; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Procedure constructor. |
36
|
|
|
* |
37
|
|
|
* @param EventDispatcher $dispatcher |
38
|
|
|
*/ |
39
|
|
|
public function __construct(ContainerInterface $container) |
40
|
|
|
{ |
41
|
|
|
$this->dispatcher = $container->get('event_dispatcher'); |
42
|
|
|
$this->configurations = new ArrayCollection(); |
43
|
|
|
$this->connections = new ArrayCollection(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $connection |
48
|
|
|
* @param \PgFunc\Procedure $procedure |
49
|
|
|
* |
50
|
|
|
* @return mixed |
51
|
|
|
* |
52
|
|
|
* @throws \PgFunc\Exception |
53
|
|
|
* @throws ParameterNotFoundException |
54
|
|
|
*/ |
55
|
|
|
public function execute($connection, \PgFunc\Procedure $procedure) |
56
|
|
|
{ |
57
|
|
|
$event = new ChangeConnectionNameEvent($connection); |
58
|
|
|
$this->dispatcher->dispatch(StoredProcedureEvents::CONNECTION_NAME, $event); |
59
|
|
|
|
60
|
|
|
$connection = $event->getName(); |
61
|
|
|
if (!$this->configurations->get($connection)) { |
62
|
|
|
throw new ParameterNotFoundException( |
63
|
|
|
sprintf('Configuration "%s" not found in configuration pool', $connection) |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if (!$this->connections->get($connection)) { |
68
|
|
|
$this->connections->set($connection, new Connection($this->configurations->get($connection))); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** @var Connection $connection */ |
72
|
|
|
$connection = $this->connections->get($connection); |
73
|
|
|
|
74
|
|
|
// Connection event |
75
|
|
|
$event = new ChangeConnectionEvent($connection, $procedure); |
76
|
|
|
$this->dispatcher->dispatch(StoredProcedureEvents::CONNECTION, $event); |
77
|
|
|
|
78
|
|
|
$connection = $event->getConnection(); |
79
|
|
|
$procedure = $event->getProcedure(); |
80
|
|
|
|
81
|
|
|
$result = $connection->queryProcedure($procedure); |
82
|
|
|
|
83
|
|
|
// Result Event |
84
|
|
|
$event = new ChangeResultEvent($result); |
85
|
|
|
$this->dispatcher->dispatch(StoredProcedureEvents::RESULT, $event); |
86
|
|
|
|
87
|
|
|
return $event->getResult(); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $key |
92
|
|
|
* @param array $connectionData |
93
|
|
|
* |
94
|
|
|
* @return ProcedureInterface |
95
|
|
|
* |
96
|
|
|
* @throws BadMethodCallException |
97
|
|
|
*/ |
98
|
|
|
public function setConfiguration($key, array $connectionData): ProcedureInterface |
99
|
|
|
{ |
100
|
|
|
$configuration = new \PgFunc\Configuration(); |
101
|
|
|
|
102
|
|
|
foreach ($connectionData as $method => $value) { |
103
|
|
|
$method = 'set'.str_replace('_', '', ucwords($method, '_')); |
104
|
|
|
|
105
|
|
|
if (!method_exists($configuration, $method)) { |
106
|
|
|
throw new BadMethodCallException( |
107
|
|
|
sprintf('Method "%s" not found in class "%s"', $method, get_class($configuration)) |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$configuration->$method($value); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$this->configurations->set($key, $configuration); |
115
|
|
|
|
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param Configuration|string $configuration |
121
|
|
|
* |
122
|
|
|
* @return Procedure |
123
|
|
|
*/ |
124
|
|
|
public function removeConfiguration($configuration): ProcedureInterface |
125
|
|
|
{ |
126
|
|
|
if ($configuration instanceof Configuration) { |
127
|
|
|
$this->configurations->removeElement($configuration); |
128
|
|
|
} else { |
129
|
|
|
$this->configurations->remove($configuration); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return $this; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param Connection $connection |
137
|
|
|
* |
138
|
|
|
* @return Procedure |
139
|
|
|
*/ |
140
|
|
|
public function setConnection($key, Connection $connection): ProcedureInterface |
141
|
|
|
{ |
142
|
|
|
$this->connections->set($key, $connection); |
143
|
|
|
|
144
|
|
|
return $this; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param Connection|string $connection |
149
|
|
|
* |
150
|
|
|
* @return Procedure |
151
|
|
|
*/ |
152
|
|
|
public function removeConnection($connection): ProcedureInterface |
153
|
|
|
{ |
154
|
|
|
if ($connection instanceof Connection) { |
155
|
|
|
$this->connections->removeElement($connection); |
156
|
|
|
} else { |
157
|
|
|
$this->connections->remove($connection); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths