Skip to content

Commit

Permalink
Backport fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hbraune committed Apr 16, 2017
1 parent 8393cbd commit c55bd48
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +29,7 @@ class ApiFormTypeValidatorExtension extends BaseValidatorExtension
public function __construct(ValidatorInterface $validator)
{
$this->validator = $validator;
$this->violationMapper = new ViolationMapper();
$this->violationMapper = new ApiViolationMapper();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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%']
Expand All @@ -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' }
- { 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"
33 changes: 33 additions & 0 deletions Validation/ValidationRequestGroupResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace BrauneDigital\ApiBaseBundle\Validation;

use Doctrine\ORM\EntityManagerInterface;
use Nelmio\Alice\ProcessorInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

class ValidationRequestGroupResolver
{
private $request;

public function __construct(RequestStack $requestStack)
{
$this->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;
}

}

0 comments on commit c55bd48

Please sign in to comment.