ManifestLoader.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php declare(strict_types = 1);
  2. /*
  3. * This file is part of PharIo\Manifest.
  4. *
  5. * Copyright (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de> and contributors
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. *
  10. */
  11. namespace PharIo\Manifest;
  12. use function sprintf;
  13. class ManifestLoader {
  14. public static function fromFile(string $filename): Manifest {
  15. try {
  16. return (new ManifestDocumentMapper())->map(
  17. ManifestDocument::fromFile($filename)
  18. );
  19. } catch (Exception $e) {
  20. throw new ManifestLoaderException(
  21. sprintf('Loading %s failed.', $filename),
  22. (int)$e->getCode(),
  23. $e
  24. );
  25. }
  26. }
  27. public static function fromPhar(string $filename): Manifest {
  28. return self::fromFile('phar://' . $filename . '/manifest.xml');
  29. }
  30. public static function fromString(string $manifest): Manifest {
  31. try {
  32. return (new ManifestDocumentMapper())->map(
  33. ManifestDocument::fromString($manifest)
  34. );
  35. } catch (Exception $e) {
  36. throw new ManifestLoaderException(
  37. 'Processing string failed',
  38. (int)$e->getCode(),
  39. $e
  40. );
  41. }
  42. }
  43. }