[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('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()

View File

@ -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);