RecursiveValidator example

use TranslatorTrait;
            };
            // Force the locale to be 'en' when no translator is provided rather than relying on the Intl default locale             // This avoids depending on Intl or the stub implementation being available. It also ensures that Symfony             // validation messages are pluralized properly even when the default locale gets changed because they are in             // English.             $translator->setLocale('en');
        }

        $contextFactory = new ExecutionContextFactory($translator$this->translationDomain);

        return new RecursiveValidator($contextFactory$metadataFactory$validatorFactory$this->initializers);
    }

    private function createAnnotationReader(): Reader
    {
        if (!class_exists(AnnotationReader::class)) {
            throw new LogicException('Enabling annotation based constraint mapping requires the packages doctrine/annotations and symfony/cache to be installed.');
        }

        if (class_exists(ArrayAdapter::class)) {
            return new PsrCachedReader(new AnnotationReader()new ArrayAdapter());
        }

        

  public function setValidator(ValidatorInterface $validator) {
    $this->validator = $validator;
  }

  /** * {@inheritdoc} */
  public function getValidator() {
    if (!isset($this->validator)) {
      $this->validator = new RecursiveValidator(
        new ExecutionContextFactory(new DrupalTranslator()),
        new ConstraintValidatorFactory($this->classResolver),
        $this
      );
    }
    return $this->validator;
  }

  /** * {@inheritdoc} */
  
$container->set('typed_data_manager', $this->typedDataManager);
    \Drupal::setContainer($container);

    $translator = $this->createMock('Drupal\Core\Validation\TranslatorInterface');
    $translator->expects($this->any())
      ->method('trans')
      ->willReturnCallback(function D$id) {
        return $id;
      });
    $this->contextFactory = new ExecutionContextFactory($translator);
    $this->validatorFactory = new ConstraintValidatorFactory();
    $this->recursiveValidator = new RecursiveValidator($this->contextFactory, $this->validatorFactory, $this->typedDataManager);
  }

  /** * Ensures that passing an explicit group is not supported. * * @covers ::validate */
  public function testValidateWithGroups() {
    $this->expectException(\LogicException::class);
    $this->recursiveValidator->validate('test', NULL, 'test group');
  }

  
use TranslatorTrait;
            };
            // Force the locale to be 'en' when no translator is provided rather than relying on the Intl default locale             // This avoids depending on Intl or the stub implementation being available. It also ensures that Symfony             // validation messages are pluralized properly even when the default locale gets changed because they are in             // English.             $translator->setLocale('en');
        }

        $contextFactory = new ExecutionContextFactory($translator$this->translationDomain);

        return new RecursiveValidator($contextFactory$metadataFactory$validatorFactory$this->initializers);
    }

    private function createAnnotationReader(): Reader
    {
        if (!class_exists(AnnotationReader::class)) {
            throw new LogicException('Enabling annotation based constraint mapping requires the packages doctrine/annotations and symfony/cache to be installed.');
        }

        if (class_exists(ArrayAdapter::class)) {
            return new PsrCachedReader(new AnnotationReader()new ArrayAdapter());
        }

        
$this->assertCount(3, $violations);
    }

    protected function createValidator(MetadataFactoryInterface $metadataFactory, array $objectInitializers = []): ValidatorInterface
    {
        $translator = new IdentityTranslator();
        $translator->setLocale('en');

        $contextFactory = new ExecutionContextFactory($translator);
        $validatorFactory = new ConstraintValidatorFactory();

        return new RecursiveValidator($contextFactory$metadataFactory$validatorFactory$objectInitializers);
    }

    public function testEmptyGroupsArrayDoesNotTriggerDeprecation()
    {
        $entity = new Entity();
        $childA = new ChildA();
        $childB = new ChildB();
        $childA->name = false;
        $childB->name = 'fake';
        $entity->childA = [$childA];
        $entity->childB = [$childB];
        
Home | Imprint | This part of the site doesn't use cookies.