FileLoader.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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\Serializer\Mapping\Loader;
  11. use Symfony\Component\Serializer\Exception\MappingException;
  12. /**
  13. * Base class for all file based loaders.
  14. *
  15. * @author Kévin Dunglas <dunglas@gmail.com>
  16. */
  17. abstract class FileLoader implements LoaderInterface
  18. {
  19. protected $file;
  20. /**
  21. * @param string $file The mapping file to load
  22. *
  23. * @throws MappingException if the mapping file does not exist or is not readable
  24. */
  25. public function __construct(string $file)
  26. {
  27. if (!is_file($file)) {
  28. throw new MappingException(sprintf('The mapping file "%s" does not exist.', $file));
  29. }
  30. if (!is_readable($file)) {
  31. throw new MappingException(sprintf('The mapping file "%s" is not readable.', $file));
  32. }
  33. $this->file = $file;
  34. }
  35. }