From 926d7d71263daabea50637e5a15c09573a415054 Mon Sep 17 00:00:00 2001 From: Anush Ramani Date: Thu, 17 Jul 2014 19:23:03 +0530 Subject: [PATCH] Parse config on instantiation (do not defer) --- Service/Omnipay.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Service/Omnipay.php b/Service/Omnipay.php index 20d8068..aa5e552 100644 --- a/Service/Omnipay.php +++ b/Service/Omnipay.php @@ -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; } /** @@ -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; }