2011-08-25 22:50:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Gregwar\CaptchaBundle\DependencyInjection;
|
|
|
|
|
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
|
|
|
use Symfony\Component\Config\FileLocator;
|
|
|
|
|
2012-11-14 04:33:36 +01:00
|
|
|
/**
|
|
|
|
* Extension used to load the configuration, set parameters, and initialize the captcha view
|
|
|
|
*
|
|
|
|
* @author Gregwar <g.passault@gmail.com>
|
|
|
|
*/
|
2011-08-25 22:50:59 +02:00
|
|
|
class GregwarCaptchaExtension extends Extension
|
|
|
|
{
|
2012-11-14 04:33:36 +01:00
|
|
|
/**
|
|
|
|
* @param array $configs
|
|
|
|
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
|
|
|
|
*/
|
2011-08-25 22:50:59 +02:00
|
|
|
public function load(array $configs, ContainerBuilder $container)
|
|
|
|
{
|
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
|
|
|
$loader->load('services.yml');
|
|
|
|
|
2011-09-08 17:02:40 +02:00
|
|
|
$configuration = new Configuration();
|
|
|
|
$config = $this->processConfiguration($configuration, $configs);
|
|
|
|
|
2011-12-02 18:36:34 +01:00
|
|
|
$container->setParameter('gregwar_captcha.config', $config);
|
2012-11-14 04:33:36 +01:00
|
|
|
$container->setParameter('gregwar_captcha.config.image_folder', $config['image_folder']);
|
|
|
|
$container->setParameter('gregwar_captcha.config.web_path', $config['web_path']);
|
|
|
|
$container->setParameter('gregwar_captcha.config.gc_freq', $config['gc_freq']);
|
|
|
|
$container->setParameter('gregwar_captcha.config.expiration', $config['expiration']);
|
2012-12-04 11:33:54 +01:00
|
|
|
$container->setParameter('gregwar_captcha.config.whitelist_key', $config['whitelist_key']);
|
2011-09-09 20:02:47 +02:00
|
|
|
|
2012-12-25 20:07:00 +01:00
|
|
|
if ($config['reload'] && !$config['as_url']) {
|
|
|
|
throw new \InvalidArgumentException('GregwarCaptcha: The reload option cannot be set without as_url, see the README for more information');
|
|
|
|
}
|
|
|
|
|
2011-08-25 22:50:59 +02:00
|
|
|
$resources = $container->getParameter('twig.form.resources');
|
2012-12-02 13:17:04 +01:00
|
|
|
$container->setParameter('twig.form.resources', array_merge(array('GregwarCaptchaBundle::captcha.html.twig'), $resources));
|
2011-08-25 22:50:59 +02:00
|
|
|
}
|
|
|
|
}
|