/** * buildExtensions. * * @method buildExtensions * * @param \Payum\Core\Gateway $gateway * @param \Payum\Core\Bridge\Spl\ArrayObject $config */ protected function buildExtensions(Gateway $gateway, ArrayObject $config) { foreach ($config as $name => $value) { if (0 === strpos($name, 'payum.extension') && false == is_object($config[$name])) { $config[$name] = $this->app[$config[$name]]; } } parent::buildExtensions($gateway, $config); }
/** * @param ArrayObject $config */ protected function buildClosures(ArrayObject $config) { foreach ($config as $name => $value) { if (false == $value || false == 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); }
/** * @test */ public function shouldAllowPrependExtensions() { $firstExtension = $this->getMock(ExtensionInterface::class); $secondExtension = $this->getMock(ExtensionInterface::class); $factory = new CoreGatewayFactory(); $gateway = $factory->create(array('payum.extension.foo' => $firstExtension, 'payum.extension.bar' => $secondExtension)); $extensions = $this->readAttribute($this->readAttribute($gateway, 'extensions'), 'extensions'); $this->assertSame($firstExtension, $extensions[0]); $this->assertSame($secondExtension, $extensions[1]); $gateway = $factory->create(array('payum.extension.foo' => $firstExtension, 'payum.extension.bar' => $secondExtension, 'payum.prepend_extensions' => array('payum.extension.bar'))); $extensions = $this->readAttribute($this->readAttribute($gateway, 'extensions'), 'extensions'); $this->assertSame($secondExtension, $extensions[0]); $this->assertSame($firstExtension, $extensions[1]); }
/** * {@inheritDoc} */ public function createConfig(array $config = array()) { $config = ArrayObject::ensureArrayObject($config); $config->defaults(parent::createConfig((array) $config)); $prependActions = array(); foreach ($this->actionsTags as $id => $tagAttributes) { foreach ($tagAttributes as $attributes) { $name = isset($attributes['alias']) ? $attributes['alias'] : $id; if (isset($attributes['all']) && $attributes['all']) { $config["payum.action.{$name}"] = $this->container->get($id); } if (isset($attributes['factory']) && isset($config['payum.factory_name']) && $config['payum.factory_name'] === $attributes['factory']) { $config["payum.action.{$name}"] = $this->container->get($id); } if (isset($attributes['gateway']) && isset($config['payum.gateway_name']) && $config['payum.gateway_name'] === $attributes['gateway']) { $config["payum.action.{$name}"] = $this->container->get($id); } if (isset($attributes['prepend'])) { $prependActions[] = "payum.action.{$name}"; } } } $config['payum.prepend_actions'] = $prependActions; $prependExtensions = array(); foreach ($this->extensionsTags as $id => $tagAttributes) { foreach ($tagAttributes as $attributes) { $name = isset($attributes['alias']) ? $attributes['alias'] : $id; if (isset($attributes['all']) && $attributes['all']) { $config["payum.extension.{$name}"] = $this->container->get($id); } if (isset($attributes['factory']) && isset($config['payum.factory_name']) && $config['payum.factory_name'] === $attributes['factory']) { $config["payum.extension.{$name}"] = $this->container->get($id); } if (isset($attributes['gateway']) && isset($config['payum.gateway_name']) && $config['payum.gateway_name'] === $attributes['gateway']) { $config["payum.extension.{$name}"] = $this->container->get($id); } if (isset($attributes['prepend'])) { $prependExtensions[] = "payum.extension.{$name}"; } } } $config['payum.prepend_extensions'] = $prependExtensions; $prependApis = array(); foreach ($this->apisTags as $id => $tagAttributes) { foreach ($tagAttributes as $attributes) { $name = isset($attributes['alias']) ? $attributes['alias'] : $id; if (isset($attributes['all']) && $attributes['all']) { $config["payum.api.{$name}"] = $this->container->get($id); } if (isset($attributes['factory']) && isset($config['payum.factory_name']) && $config['payum.factory_name'] === $attributes['factory']) { $config["payum.api.{$name}"] = $this->container->get($id); } if (isset($attributes['gateway']) && isset($config['payum.gateway_name']) && $config['payum.gateway_name'] === $attributes['gateway']) { $config["payum.api.{$name}"] = $this->container->get($id); } if (isset($attributes['prepend'])) { $prependApis[] = "payum.api.{$name}"; } } } $config['payum.prepend_apis'] = $prependApis; return (array) $config; }