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