Skip to content

Commit

Permalink
Parse config on instantiation (do not defer)
Browse files Browse the repository at this point in the history
  • Loading branch information
anush committed Jul 17, 2014
1 parent f7ad5ba commit 926d7d7
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions Service/Omnipay.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,21 @@ class Omnipay

public function __construct(Container $container)
{
$this->parameters = $container->getParameterBag()->all();
$this->initConfig($container->getParameterBag()->all());
}

private function initConfig($parameters)
{
$key = 'omnipay';
$configs = array($key);
foreach ($parameters as $param => $value) {
if (!preg_match("/^$key/", $param)) {
continue;
}
$this->assignArrayByPath($configs, $param, $value);
}

$this->config = isset($configs[$key]) ? $configs[$key] : null;
}

/**
Expand Down Expand Up @@ -86,20 +100,6 @@ public function getGatewayName($key)

public function getConfig()
{
if (!isset($this->config)) {
// Config has not been parsed yet. So do it.
$key = 'omnipay';
$configs = array($key);
foreach ($this->parameters as $param => $value) {
if (!preg_match("/^$key/", $param)) {
continue;
}
$this->assignArrayByPath($configs, $param, $value);
}

$this->config = isset($configs[$key]) ? $configs[$key] : null;
}

return $this->config;
}

Expand Down

0 comments on commit 926d7d7

Please sign in to comment.