ManifestLoader.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * This file is part of PharIo\Manifest.
  4. *
  5. * (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
  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 PharIo\Manifest;
  11. class ManifestLoader {
  12. /**
  13. * @param string $filename
  14. *
  15. * @return Manifest
  16. *
  17. * @throws ManifestLoaderException
  18. */
  19. public static function fromFile($filename) {
  20. try {
  21. return (new ManifestDocumentMapper())->map(
  22. ManifestDocument::fromFile($filename)
  23. );
  24. } catch (Exception $e) {
  25. throw new ManifestLoaderException(
  26. sprintf('Loading %s failed.', $filename),
  27. $e->getCode(),
  28. $e
  29. );
  30. }
  31. }
  32. /**
  33. * @param string $filename
  34. *
  35. * @return Manifest
  36. *
  37. * @throws ManifestLoaderException
  38. */
  39. public static function fromPhar($filename) {
  40. return self::fromFile('phar://' . $filename . '/manifest.xml');
  41. }
  42. /**
  43. * @param string $manifest
  44. *
  45. * @return Manifest
  46. *
  47. * @throws ManifestLoaderException
  48. */
  49. public static function fromString($manifest) {
  50. try {
  51. return (new ManifestDocumentMapper())->map(
  52. ManifestDocument::fromString($manifest)
  53. );
  54. } catch (Exception $e) {
  55. throw new ManifestLoaderException(
  56. 'Processing string failed',
  57. $e->getCode(),
  58. $e
  59. );
  60. }
  61. }
  62. }