forked from Payum/PayumBundle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ContainerAwareCoreGatewayFactory.php
39 lines (30 loc) · 1.09 KB
/
ContainerAwareCoreGatewayFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace Payum\Bundle\PayumBundle;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\CoreGatewayFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ContainerAwareCoreGatewayFactory extends CoreGatewayFactory
{
private ContainerInterface $container;
public function __construct(ContainerInterface $container, array $defaultConfig = [])
{
$this->container = $container;
parent::__construct($defaultConfig);
}
protected function buildClosures(ArrayObject $config): void
{
foreach ($config as $name => $value) {
if (! $value || ! is_string($value)) {
continue;
}
$match = [];
if (preg_match('/^%(.*?)%$/', $value, $match)) {
$config[$name] = $value = $this->container->getParameter($match[1]);
}
if ('@' === $value[0] && $this->container->has(substr($value, 1))) {
$config[$name] = $value = $this->container->get(substr($value, 1));
}
}
parent::buildClosures($config);
}
}