From a8434542aff366c0eb2a3011addc787632fcedd8 Mon Sep 17 00:00:00 2001 From: Gregwar Date: Fri, 2 Dec 2011 18:54:42 +0100 Subject: [PATCH] [Configuration] Adding a "keep_value" key (fixes #11) --- DependencyInjection/Configuration.php | 1 + Type/CaptchaType.php | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 98e995b..1b72967 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -22,6 +22,7 @@ class Configuration implements ConfigurationInterface ->scalarNode('length')->defaultValue(5)->end() ->scalarNode('width')->defaultValue(120)->end() ->scalarNode('height')->defaultValue(40)->end() + ->scalarNode('keep_value')->defaultValue(true)->end() ->scalarNode('charset')->defaultValue('abcdefhjkmnprstuvwxyz23456789')->end() ->scalarNode('as_file')->defaultValue(false)->end() ->scalarNode('image_folder')->defaultValue('captcha')->end() diff --git a/Type/CaptchaType.php b/Type/CaptchaType.php index 74269bb..6ff0a84 100755 --- a/Type/CaptchaType.php +++ b/Type/CaptchaType.php @@ -45,6 +45,12 @@ class CaptchaType extends AbstractType */ protected $asFile; + /** + * Keep value between two requests ? + * @var boolean + */ + protected $keepValue; + /** * Charset used * @var string @@ -96,8 +102,9 @@ class CaptchaType extends AbstractType $this->width = $config['width']; $this->height = $config['height']; $this->length = $config['length']; - $this->asFile = $config['as_file']; $this->charset = $config['charset']; + $this->keepValue = $config['keep_value']; + $this->asFile = $config['as_file']; $this->imageFolder = $config['image_folder']; $this->webPath = $config['web_path']; $this->gcFreq = $config['gc_freq']; @@ -161,7 +168,7 @@ class CaptchaType extends AbstractType private function generateCaptchaValue() { - if (!$this->session->has($this->key)) { + if (!$this->keepValue || !$this->session->has($this->key)) { $value = ''; $chars = str_split($this->charset);