Added the possibility of overriding the width & height in the options

This commit is contained in:
Gregwar 2011-09-09 19:46:12 +02:00
parent 959cf84805
commit ab882512f1
2 changed files with 24 additions and 11 deletions

View File

@ -3,6 +3,6 @@ services:
# captcha type
captcha.type:
class: Gregwar\CaptchaBundle\Type\CaptchaType
arguments: [@session, @service_container]
arguments: [@session, %gregwar_captcha.image.width%, %gregwar_captcha.image.height%]
tags:
- { name: form.type, alias: captcha }

View File

@ -21,18 +21,18 @@ use Gregwar\CaptchaBundle\Generator\CaptchaGenerator;
*/
class CaptchaType extends AbstractType
{
/**
* The image height
* @var integer
*/
protected $height;
/**
* The image width
* @var integer
*/
protected $width;
/**
* The image height
* @var integer
*/
protected $height;
/**
* The session
* @var Symfony\Component\HttpFoundation\Session
@ -42,11 +42,11 @@ class CaptchaType extends AbstractType
private $key = 'captcha';
public function __construct(Session $session, ContainerInterface $container)
public function __construct(Session $session, $width, $height)
{
$this->session = $session;
$this->height = $container->getParameter('gregwar_captcha.image.height');
$this->width = $container->getParameter('gregwar_captcha.image.width');
$this->width = $width;
$this->height = $height;
}
@ -64,7 +64,20 @@ class CaptchaType extends AbstractType
$view->set('captcha_code', $generator->getCode($this->width, $this->height));
$view->set('captcha_width', $this->width);
$view->set('captcha_height', $this->height);
}
}
public function getDefaultOptions(array $options = array())
{
if (isset($options['width'])) {
$this->width = $options['width'];
$this->height = $options['height'];
}
return array(
'width' => $this->width,
'height' => $this->height
);
}
public function getParent(array $options)
{