Yaffs site version 1.1
[yaffs-website] / vendor / symfony / finder / SplFileInfo.php
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      * Constructor.
26      *
27      * @param string $file             The file name
28      * @param string $relativePath     The relative path
29      * @param string $relativePathname The relative path name
30      */
31     public function __construct($file, $relativePath, $relativePathname)
32     {
33         parent::__construct($file);
34         $this->relativePath = $relativePath;
35         $this->relativePathname = $relativePathname;
36     }
37
38     /**
39      * Returns the relative path.
40      *
41      * This path does not contain the file name.
42      *
43      * @return string the relative path
44      */
45     public function getRelativePath()
46     {
47         return $this->relativePath;
48     }
49
50     /**
51      * Returns the relative path name.
52      *
53      * This path contains the file name.
54      *
55      * @return string the relative path name
56      */
57     public function getRelativePathname()
58     {
59         return $this->relativePathname;
60     }
61
62     /**
63      * Returns the contents of the file.
64      *
65      * @return string the contents of the file
66      *
67      * @throws \RuntimeException
68      */
69     public function getContents()
70     {
71         $level = error_reporting(0);
72         $content = file_get_contents($this->getPathname());
73         error_reporting($level);
74         if (false === $content) {
75             $error = error_get_last();
76             throw new \RuntimeException($error['message']);
77         }
78
79         return $content;
80     }
81 }