Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\View\Engines;
4
 
5
use Illuminate\Contracts\View\Engine;
6
use Illuminate\Filesystem\Filesystem;
7
use Throwable;
8
 
9
class PhpEngine implements Engine
10
{
11
    /**
12
     * The filesystem instance.
13
     *
14
     * @var \Illuminate\Filesystem\Filesystem
15
     */
16
    protected $files;
17
 
18
    /**
19
     * Create a new file engine instance.
20
     *
21
     * @param  \Illuminate\Filesystem\Filesystem  $files
22
     * @return void
23
     */
24
    public function __construct(Filesystem $files)
25
    {
26
        $this->files = $files;
27
    }
28
 
29
    /**
30
     * Get the evaluated contents of the view.
31
     *
32
     * @param  string  $path
33
     * @param  array  $data
34
     * @return string
35
     */
36
    public function get($path, array $data = [])
37
    {
38
        return $this->evaluatePath($path, $data);
39
    }
40
 
41
    /**
42
     * Get the evaluated contents of the view at the given path.
43
     *
44
     * @param  string  $path
45
     * @param  array  $data
46
     * @return string
47
     */
48
    protected function evaluatePath($path, $data)
49
    {
50
        $obLevel = ob_get_level();
51
 
52
        ob_start();
53
 
54
        // We'll evaluate the contents of the view inside a try/catch block so we can
55
        // flush out any stray output that might get out before an error occurs or
56
        // an exception is thrown. This prevents any partial views from leaking.
57
        try {
58
            $this->files->getRequire($path, $data);
59
        } catch (Throwable $e) {
60
            $this->handleViewException($e, $obLevel);
61
        }
62
 
63
        return ltrim(ob_get_clean());
64
    }
65
 
66
    /**
67
     * Handle a view exception.
68
     *
69
     * @param  \Throwable  $e
70
     * @param  int  $obLevel
71
     * @return void
72
     *
73
     * @throws \Throwable
74
     */
75
    protected function handleViewException(Throwable $e, $obLevel)
76
    {
77
        while (ob_get_level() > $obLevel) {
78
            ob_end_clean();
79
        }
80
 
81
        throw $e;
82
    }
83
}