From 8211257008ab9aa057b38e34627a648d54771ac9 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 3 Feb 2017 14:59:18 +0200 Subject: [PATCH] Fix endless recursion --- src/Payum/Silex/PayumProvider.php | 47 +++++++++++++++++-------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/Payum/Silex/PayumProvider.php b/src/Payum/Silex/PayumProvider.php index 0d62b90..ff31bfc 100644 --- a/src/Payum/Silex/PayumProvider.php +++ b/src/Payum/Silex/PayumProvider.php @@ -19,6 +19,7 @@ use Silex\ControllerCollection; use Silex\ControllerProviderInterface; use Silex\ServiceProviderInterface; +use Symfony\Component\OptionsResolver\Options; class PayumProvider implements ServiceProviderInterface, ControllerProviderInterface { @@ -77,39 +78,43 @@ public function register(Application $app) $app['form.types'] = $app->share($app->extend('form.types', function ($types) use ($app) { $types[] = new CreditCardType(); $types[] = new CreditCardExpirationDateType(); - $types[] = new GatewayFactoriesChoiceType($app['payum.gateway_factory_choices']); - $types[] = new GatewayChoiceType($app['payum.gateway_choices']); + $types[] = new GatewayFactoriesChoiceType($app['payum.gateway_factory_choices_callback']); + $types[] = new GatewayChoiceType($app['payum.gateway_choices_callback']); $types[] = new GatewayConfigType($app['payum']); return $types; })); - $app['payum.gateway_factory_choices'] = $app->share(function ($app) { - /** @var Payum $payum */ - $payum = $app['payum']; + $app['payum.gateway_factory_choices_callback'] = $app->share(function ($app) { + return function(Options $options) use ($app) { + /** @var Payum $payum */ + $payum = $app['payum']; - $choices = []; - foreach ($payum->getGatewayFactories() as $name => $factory) { - if (in_array($name, ['omnipay', 'omnipay_direct', 'omnipay_offsite'])) { - continue; - } + $choices = []; + foreach ($payum->getGatewayFactories() as $name => $factory) { + if (in_array($name, ['omnipay', 'omnipay_direct', 'omnipay_offsite'])) { + continue; + } - $choices[ucwords(str_replace(['_', 'omnipay'], ' ', $name))] = $name; - } + $choices[ucwords(str_replace(['_', 'omnipay'], ' ', $name))] = $name; + } - return $choices; + return $choices; + }; }); - $app['payum.gateway_choices'] = $app->share(function ($app) { - /** @var Payum $payum */ - $payum = $app['payum']; + $app['payum.gateway_choices_callback'] = $app->share(function ($app) { + return function(Options $options) use ($app) { + /** @var Payum $payum */ + $payum = $app['payum']; - $choices = []; - foreach ($payum->getGateways() as $name => $gateway) { - $choices[$name] = ucwords(str_replace(['_'], ' ', $name)); - } + $choices = []; + foreach ($payum->getGateways() as $name => $gateway) { + $choices[$name] = ucwords(str_replace(['_'], ' ', $name)); + } - return $choices; + return $choices; + }; }); $app->error(function (\Exception $e, $code) use ($app) {