[Configuration] Adding a "keep_value" key (fixes #11)

This commit is contained in:
Gregwar 2011-12-02 18:54:42 +01:00
parent 537716fe38
commit a8434542af
2 changed files with 10 additions and 2 deletions

View File

@ -22,6 +22,7 @@ class Configuration implements ConfigurationInterface
->scalarNode('length')->defaultValue(5)->end() ->scalarNode('length')->defaultValue(5)->end()
->scalarNode('width')->defaultValue(120)->end() ->scalarNode('width')->defaultValue(120)->end()
->scalarNode('height')->defaultValue(40)->end() ->scalarNode('height')->defaultValue(40)->end()
->scalarNode('keep_value')->defaultValue(true)->end()
->scalarNode('charset')->defaultValue('abcdefhjkmnprstuvwxyz23456789')->end() ->scalarNode('charset')->defaultValue('abcdefhjkmnprstuvwxyz23456789')->end()
->scalarNode('as_file')->defaultValue(false)->end() ->scalarNode('as_file')->defaultValue(false)->end()
->scalarNode('image_folder')->defaultValue('captcha')->end() ->scalarNode('image_folder')->defaultValue('captcha')->end()

View File

@ -45,6 +45,12 @@ class CaptchaType extends AbstractType
*/ */
protected $asFile; protected $asFile;
/**
* Keep value between two requests ?
* @var boolean
*/
protected $keepValue;
/** /**
* Charset used * Charset used
* @var string * @var string
@ -96,8 +102,9 @@ class CaptchaType extends AbstractType
$this->width = $config['width']; $this->width = $config['width'];
$this->height = $config['height']; $this->height = $config['height'];
$this->length = $config['length']; $this->length = $config['length'];
$this->asFile = $config['as_file'];
$this->charset = $config['charset']; $this->charset = $config['charset'];
$this->keepValue = $config['keep_value'];
$this->asFile = $config['as_file'];
$this->imageFolder = $config['image_folder']; $this->imageFolder = $config['image_folder'];
$this->webPath = $config['web_path']; $this->webPath = $config['web_path'];
$this->gcFreq = $config['gc_freq']; $this->gcFreq = $config['gc_freq'];
@ -161,7 +168,7 @@ class CaptchaType extends AbstractType
private function generateCaptchaValue() private function generateCaptchaValue()
{ {
if (!$this->session->has($this->key)) { if (!$this->keepValue || !$this->session->has($this->key)) {
$value = ''; $value = '';
$chars = str_split($this->charset); $chars = str_split($this->charset);