AutoMappingTrait.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Mapping\Loader;
  11. use Symfony\Component\Validator\Mapping\AutoMappingStrategy;
  12. use Symfony\Component\Validator\Mapping\ClassMetadata;
  13. /**
  14. * Utility methods to create auto mapping loaders.
  15. *
  16. * @author Kévin Dunglas <dunglas@gmail.com>
  17. */
  18. trait AutoMappingTrait
  19. {
  20. private function isAutoMappingEnabledForClass(ClassMetadata $metadata, string $classValidatorRegexp = null): bool
  21. {
  22. // Check if AutoMapping constraint is set first
  23. if (AutoMappingStrategy::NONE !== $strategy = $metadata->getAutoMappingStrategy()) {
  24. return AutoMappingStrategy::ENABLED === $strategy;
  25. }
  26. // Fallback on the config
  27. return null !== $classValidatorRegexp && preg_match($classValidatorRegexp, $metadata->getClassName());
  28. }
  29. }