0f4e025b22bd20362736c83160694ffd6f547c36
[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      * @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         set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
70         $content = file_get_contents($this->getPathname());
71         restore_error_handler();
72         if (false === $content) {
73             throw new \RuntimeException($error);
74         }
75
76         return $content;
77     }
78 }