FileLoader.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. /**
  23. * The file to load.
  24. *
  25. * @var string
  26. */
  27. protected $file;
  28. /**
  29. * Creates a new loader.
  30. *
  31. * @param string $file The mapping file to load
  32. *
  33. * @throws MappingException If the file does not exist or is not readable
  34. */
  35. public function __construct($file)
  36. {
  37. if (!is_file($file)) {
  38. throw new MappingException(sprintf('The mapping file "%s" does not exist', $file));
  39. }
  40. if (!is_readable($file)) {
  41. throw new MappingException(sprintf('The mapping file "%s" is not readable', $file));
  42. }
  43. if (!stream_is_local($this->file)) {
  44. throw new MappingException(sprintf('The mapping file "%s" is not a local file', $file));
  45. }
  46. $this->file = $file;
  47. }
  48. }