FileLoader.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\Exception\MappingException;
  12. /**
  13. * Base loader for loading validation metadata from a file.
  14. *
  15. * @author Bernhard Schussek <bschussek@gmail.com>
  16. *
  17. * @see YamlFileLoader
  18. * @see XmlFileLoader
  19. */
  20. abstract class FileLoader extends AbstractLoader
  21. {
  22. protected $file;
  23. /**
  24. * Creates a new loader.
  25. *
  26. * @param string $file The mapping file to load
  27. *
  28. * @throws MappingException If the file does not exist or is not readable
  29. */
  30. public function __construct(string $file)
  31. {
  32. if (!is_file($file)) {
  33. throw new MappingException(sprintf('The mapping file "%s" does not exist.', $file));
  34. }
  35. if (!is_readable($file)) {
  36. throw new MappingException(sprintf('The mapping file "%s" is not readable.', $file));
  37. }
  38. if (!stream_is_local($this->file)) {
  39. throw new MappingException(sprintf('The mapping file "%s" is not a local file.', $file));
  40. }
  41. $this->file = $file;
  42. }
  43. }