From 25b8840f2a7b1a3c0ae56ef8205f3fb89880e20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cengizhan=20=C3=87al=C4=B1=C5=9Fkan?= Date: Sun, 19 Mar 2017 18:40:34 +0300 Subject: [PATCH 1/2] Support of multiple instance --- DependencyInjection/Configuration.php | 1 + Type/CaptchaType.php | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a415275..2b4cf36 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -47,6 +47,7 @@ class Configuration implements ConfigurationInterface ->arrayNode('background_images')->prototype('scalar')->end()->end() ->scalarNode('disabled')->defaultValue(false)->end() ->scalarNode('ignore_all_effects')->defaultValue(false)->end() + ->scalarNode('session_key')->defaultValue('captcha')->end() ->end() ; diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index 6f3ac51..b610479 100644 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -22,6 +22,8 @@ use Gregwar\CaptchaBundle\Generator\CaptchaGenerator; */ class CaptchaType extends AbstractType { + const SESSION_KEY_PREFIX = '_captcha/'; + /** * @var SessionInterface */ @@ -53,7 +55,7 @@ class CaptchaType extends AbstractType { $this->session = $session; $this->generator = $generator; - $this->translator = $translator; + $this->translator = $translator; $this->options = $options; } @@ -65,7 +67,7 @@ class CaptchaType extends AbstractType $validator = new CaptchaValidator( $this->translator, $this->session, - sprintf('gcb_%s', $builder->getForm()->getName()), + sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']), $options['invalid_message'], $options['bypass_code'], $options['humanity'] @@ -83,7 +85,7 @@ class CaptchaType extends AbstractType throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information'); } - $sessionKey = sprintf('gcb_%s', $form->getName()); + $sessionKey = sprintf('%s%s', self::SESSION_KEY_PREFIX, $options['session_key']); $isHuman = false; if ($options['humanity'] > 0) { From ba9c0e6166fb68ffd403c1c8f6cf8eeacc0ee86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cengizhan=20=C3=87al=C4=B1=C5=9Fkan?= Date: Mon, 27 Mar 2017 22:32:00 +0300 Subject: [PATCH 2/2] Change session key for as_url option --- Type/CaptchaType.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index b610479..619ad82 100644 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -22,7 +22,7 @@ use Gregwar\CaptchaBundle\Generator\CaptchaGenerator; */ class CaptchaType extends AbstractType { - const SESSION_KEY_PREFIX = '_captcha/'; + const SESSION_KEY_PREFIX = '_captcha_'; /** * @var SessionInterface