[Configuration] Cleaner organization (fixes #10)

This commit is contained in:
Gregwar 2011-12-02 18:36:34 +01:00
parent 249036c745
commit c0530a0b26
3 changed files with 16 additions and 18 deletions

View File

@ -19,14 +19,7 @@ class GregwarCaptchaExtension extends Extension
$configuration = new Configuration(); $configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs); $config = $this->processConfiguration($configuration, $configs);
$container->setParameter('gregwar_captcha.length', $config['length']); $container->setParameter('gregwar_captcha.config', $config);
$container->setParameter('gregwar_captcha.height', $config['height']);
$container->setParameter('gregwar_captcha.width', $config['width']);
$container->setParameter('gregwar_captcha.as_file', $config['as_file']);
$container->setParameter('gregwar_captcha.image_folder', $config['image_folder']);
$container->setParameter('gregwar_captcha.web_path', $config['web_path']);
$container->setParameter('gregwar_captcha.gc_freq', $config['gc_freq']);
$container->setParameter('gregwar_captcha.expiration', $config['expiration']);
$resources = $container->getParameter('twig.form.resources'); $resources = $container->getParameter('twig.form.resources');
$container->setParameter('twig.form.resources',array_merge(array('GregwarCaptchaBundle::captcha.html.twig'), $resources)); $container->setParameter('twig.form.resources',array_merge(array('GregwarCaptchaBundle::captcha.html.twig'), $resources));

View File

@ -3,6 +3,6 @@ services:
# captcha type # captcha type
captcha.type: captcha.type:
class: Gregwar\CaptchaBundle\Type\CaptchaType class: Gregwar\CaptchaBundle\Type\CaptchaType
arguments: [ "@session", %gregwar_captcha.width%, %gregwar_captcha.height%, %gregwar_captcha.length%, %gregwar_captcha.as_file%, %gregwar_captcha.image_folder%, %gregwar_captcha.web_path%, %gregwar_captcha.gc_freq%, %gregwar_captcha.expiration% ] arguments: [ "@session", %gregwar_captcha.config% ]
tags: tags:
- { name: form.type, alias: captcha } - { name: form.type, alias: captcha }

View File

@ -76,20 +76,25 @@ class CaptchaType extends AbstractType
*/ */
protected $session; protected $session;
/**
* Session key
* @var String
*/
private $key = 'captcha'; private $key = 'captcha';
public function __construct(Session $session, $width, $height, $length, $asFile, $imageFolder, $webPath, $gcFreq, $expiration) public function __construct(Session $session, $config)
{ {
$this->session = $session; $this->session = $session;
$this->width = $width;
$this->height = $height; $this->width = $config['width'];
$this->length = $length; $this->height = $config['height'];
$this->asFile = $asFile; $this->length = $config['length'];
$this->imageFolder = $imageFolder; $this->asFile = $config['as_file'];
$this->webPath = $webPath; $this->imageFolder = $config['image_folder'];
$this->gcFreq = $gcFreq; $this->webPath = $config['web_path'];
$this->expiration = $expiration; $this->gcFreq = $config['gc_freq'];
$this->expiration = $config['expiration'];
} }
public function buildForm(FormBuilder $builder, array $options) public function buildForm(FormBuilder $builder, array $options)