| 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 |
namespace WindPressPackages\Symfony\Component\Finder; |
| 12 |
|
| 13 |
/** |
| 14 |
* Extends \SplFileInfo to support relative paths. |
| 15 |
* |
| 16 |
* @author Fabien Potencier <fabien@symfony.com> |
| 17 |
*/ |
| 18 |
class SplFileInfo extends \SplFileInfo |
| 19 |
{ |
| 20 |
private $relativePath; |
| 21 |
private $relativePathname; |
| 22 |
/** |
| 23 |
* @param string $file The file name |
| 24 |
* @param string $relativePath The relative path |
| 25 |
* @param string $relativePathname The relative path name |
| 26 |
*/ |
| 27 |
public function __construct(string $file, string $relativePath, string $relativePathname) |
| 28 |
{ |
| 29 |
parent::__construct($file); |
| 30 |
$this->relativePath = $relativePath; |
| 31 |
$this->relativePathname = $relativePathname; |
| 32 |
} |
| 33 |
/** |
| 34 |
* Returns the relative path. |
| 35 |
* |
| 36 |
* This path does not contain the file name. |
| 37 |
* |
| 38 |
* @return string |
| 39 |
*/ |
| 40 |
public function getRelativePath() |
| 41 |
{ |
| 42 |
return $this->relativePath; |
| 43 |
} |
| 44 |
/** |
| 45 |
* Returns the relative path name. |
| 46 |
* |
| 47 |
* This path contains the file name. |
| 48 |
* |
| 49 |
* @return string |
| 50 |
*/ |
| 51 |
public function getRelativePathname() |
| 52 |
{ |
| 53 |
return $this->relativePathname; |
| 54 |
} |
| 55 |
public function getFilenameWithoutExtension(): string |
| 56 |
{ |
| 57 |
$filename = $this->getFilename(); |
| 58 |
return pathinfo($filename, \PATHINFO_FILENAME); |
| 59 |
} |
| 60 |
/** |
| 61 |
* Returns the contents of the file. |
| 62 |
* |
| 63 |
* @return string |
| 64 |
* |
| 65 |
* @throws \RuntimeException |
| 66 |
*/ |
| 67 |
public function getContents() |
| 68 |
{ |
| 69 |
set_error_handler(function ($type, $msg) use (&$error) { |
| 70 |
$error = $msg; |
| 71 |
}); |
| 72 |
try { |
| 73 |
$content = file_get_contents($this->getPathname()); |
| 74 |
} finally { |
| 75 |
restore_error_handler(); |
| 76 |
} |
| 77 |
if (\false === $content) { |
| 78 |
throw new \RuntimeException($error); |
| 79 |
} |
| 80 |
return $content; |
| 81 |
} |
| 82 |
} |
| 83 |
|