Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 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 string $relativePath;
22
    private string $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(string $file, string $relativePath, string $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
    public function getRelativePath(): string
42
    {
43
        return $this->relativePath;
44
    }
45
 
46
    /**
47
     * Returns the relative path name.
48
     *
49
     * This path contains the file name.
50
     */
51
    public function getRelativePathname(): string
52
    {
53
        return $this->relativePathname;
54
    }
55
 
56
    public function getFilenameWithoutExtension(): string
57
    {
58
        $filename = $this->getFilename();
59
 
60
        return pathinfo($filename, \PATHINFO_FILENAME);
61
    }
62
 
63
    /**
64
     * Returns the contents of the file.
65
     *
66
     * @throws \RuntimeException
67
     */
68
    public function getContents(): string
69
    {
70
        set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
71
        try {
72
            $content = file_get_contents($this->getPathname());
73
        } finally {
74
            restore_error_handler();
75
        }
76
        if (false === $content) {
77
            throw new \RuntimeException($error);
78
        }
79
 
80
        return $content;
81
    }
82
}