comparison vendor/symfony/finder/SplFileInfo.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children c2387f117808
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Finder;
13
14 /**
15 * Extends \SplFileInfo to support relative paths.
16 *
17 * @author Fabien Potencier <fabien@symfony.com>
18 */
19 class SplFileInfo extends \SplFileInfo
20 {
21 private $relativePath;
22 private $relativePathname;
23
24 /**
25 * @param string $file The file name
26 * @param string $relativePath The relative path
27 * @param string $relativePathname The relative path name
28 */
29 public function __construct($file, $relativePath, $relativePathname)
30 {
31 parent::__construct($file);
32 $this->relativePath = $relativePath;
33 $this->relativePathname = $relativePathname;
34 }
35
36 /**
37 * Returns the relative path.
38 *
39 * This path does not contain the file name.
40 *
41 * @return string the relative path
42 */
43 public function getRelativePath()
44 {
45 return $this->relativePath;
46 }
47
48 /**
49 * Returns the relative path name.
50 *
51 * This path contains the file name.
52 *
53 * @return string the relative path name
54 */
55 public function getRelativePathname()
56 {
57 return $this->relativePathname;
58 }
59
60 /**
61 * Returns the contents of the file.
62 *
63 * @return string the contents of the file
64 *
65 * @throws \RuntimeException
66 */
67 public function getContents()
68 {
69 $level = error_reporting(0);
70 $content = file_get_contents($this->getPathname());
71 error_reporting($level);
72 if (false === $content) {
73 $error = error_get_last();
74 throw new \RuntimeException($error['message']);
75 }
76
77 return $content;
78 }
79 }