diff --git a/Form/Extension/Validator/Type/ApiFormTypeValidatorExtension.php b/Form/Extension/Validator/Type/ApiFormTypeValidatorExtension.php index c63627f..daa0f9d 100644 --- a/Form/Extension/Validator/Type/ApiFormTypeValidatorExtension.php +++ b/Form/Extension/Validator/Type/ApiFormTypeValidatorExtension.php @@ -2,6 +2,7 @@ namespace BrauneDigital\ApiBaseBundle\Form\Extension\Validator\Type; +use BrauneDigital\ApiBaseBundle\Form\Extension\Validator\ViolationMapper\ApiViolationMapper; use Symfony\Component\Form\Extension\Validator\Type\BaseValidatorExtension; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper; @@ -28,7 +29,7 @@ class ApiFormTypeValidatorExtension extends BaseValidatorExtension public function __construct(ValidatorInterface $validator) { $this->validator = $validator; - $this->violationMapper = new ViolationMapper(); + $this->violationMapper = new ApiViolationMapper(); } /** diff --git a/Form/Extension/Validator/ViolationMapper/ApiViolationMapper.php b/Form/Extension/Validator/ViolationMapper/ApiViolationMapper.php index 9378f9b..f551856 100644 --- a/Form/Extension/Validator/ViolationMapper/ApiViolationMapper.php +++ b/Form/Extension/Validator/ViolationMapper/ApiViolationMapper.php @@ -6,6 +6,7 @@ use Symfony\Component\Form\Extension\Validator\ViolationMapper\RelativePath; use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapperInterface; use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationPath; +use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationPathIterator; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\Util\InheritDataAwareIterator; use Symfony\Component\PropertyAccess\PropertyPathIterator; diff --git a/Resources/config/services.yml b/Resources/config/services.yml index d7e6f4c..c4954d7 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -24,7 +24,7 @@ services: class: BrauneDigital\ApiBaseBundle\EventListener\RangeHeaderListener tags: - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest } - + braune_digital_api_base.service.token_manager: class: 'BrauneDigital\ApiBaseBundle\Service\TokenManager' arguments: ['@service_container', '%braune_digital_api_base.security.apikey_authenticator.field_name%'] @@ -33,4 +33,9 @@ services: class: 'BrauneDigital\ApiBaseBundle\Form\Extension\Validator\Type\ApiFormTypeValidatorExtension' arguments: ['@validator'] tags: - - { name: form.type_extension, extended_type: 'Symfony\Component\Form\Extension\Core\Type\FormType' } \ No newline at end of file + - { name: form.type_extension, extended_type: 'Symfony\Component\Form\Extension\Core\Type\FormType' } + + braune_digital_api_base.validation.group_resolver: + class: 'BrauneDigital\ApiBaseBundle\Validation\ValidationRequestGroupResolver' + arguments: + - "@request_stack" \ No newline at end of file diff --git a/Validation/ValidationRequestGroupResolver.php b/Validation/ValidationRequestGroupResolver.php new file mode 100644 index 0000000..e8574d2 --- /dev/null +++ b/Validation/ValidationRequestGroupResolver.php @@ -0,0 +1,33 @@ +request = $requestStack->getCurrentRequest(); + } + + /** + * @param FormInterface $form + * @return array + */ + public function __invoke(FormInterface $form) + { + $groups = array(); + if ($this->request->headers->get('validationgroups')) { + $groups = array_merge($groups, explode(',', str_replace(' ', '', $this->request->headers->get('validationgroups')))); + } + return $groups; + } + +} \ No newline at end of file