From 9b325c3cc9ef9b9b905062e618b8406cc2af59c1 Mon Sep 17 00:00:00 2001 From: cbeauvoi Date: Tue, 19 Feb 2019 11:05:25 +0100 Subject: [PATCH] test --- {config => Ressources/config}/services.yaml | 0 src/Validator.php => ValidatorBundle.php | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) rename {config => Ressources/config}/services.yaml (100%) rename src/Validator.php => ValidatorBundle.php (95%) diff --git a/config/services.yaml b/Ressources/config/services.yaml similarity index 100% rename from config/services.yaml rename to Ressources/config/services.yaml diff --git a/src/Validator.php b/ValidatorBundle.php similarity index 95% rename from src/Validator.php rename to ValidatorBundle.php index e27b353..d4b2736 100644 --- a/src/Validator.php +++ b/ValidatorBundle.php @@ -2,13 +2,15 @@ namespace Bluesquare; +use Symfony\Component\Config\FileLocator; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\RequestStack; -use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Contracts\Translation\TranslatorInterface; use Traversable; -class Validator extends Bundle +class ValidatorBundle extends Extension { protected $request; protected $context; @@ -29,7 +31,7 @@ class Validator extends Bundle $this->translator = $translator; $this->request = $requestStack->getCurrentRequest(); - $session = $this->request->getSession()->getFlashBag()->get("Bluesquare:Validator"); + $session = $this->request->getSession()->getFlashBag()->get("Bluesquare:ValidatorBundle"); if(is_array($session) && isset($session[0])) { if(isset($session[0]['context'])) $this->context = $session[0]['context']; @@ -100,7 +102,7 @@ class Validator extends Bundle 'values' => $this->values, 'context' => $this->context ]; - $this->request->getSession()->getFlashBag()->add('Bluesquare:Validator', $data); + $this->request->getSession()->getFlashBag()->add('Bluesquare:ValidatorBundle', $data); return $this; } @@ -441,4 +443,15 @@ class Validator extends Bundle $words = array_map('ucfirst', explode('_', $string)); return implode('', $words); } + + /** + * Loads a specific configuration. + * + * @throws \InvalidArgumentException When provided tag is not defined in this extension + */ + public function load(array $configs, ContainerBuilder $container) + { + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader->load('services.xml'); + } }