|
4 | 4 | use Illuminate\View\Compilers\CompilerInterface; |
5 | 5 |
|
6 | 6 | class DbBladeCompiler extends BladeCompiler implements CompilerInterface |
7 | | - { |
| 7 | +{ |
8 | 8 |
|
9 | 9 | /** @var \Illuminate\Config\Repository */ |
10 | 10 | protected $config; |
11 | 11 |
|
12 | 12 | public function __construct($filesystem, $cache_path, $config, $app) |
13 | 13 | { |
14 | | - // Get Current Blade Instance |
15 | | - $blade = $app->make('blade.compiler'); |
| 14 | + // Get Current Blade Instance |
| 15 | + $blade = app('view')->getEngineResolver()->resolve('blade')->getCompiler(); |
16 | 16 |
|
17 | 17 | parent::__construct($filesystem, $cache_path); |
18 | | - $this->rawTags = $blade->getRawTags(); |
19 | | - $this->contentTags = $blade->getContentTags(); |
20 | | - $this->escapedTags = $blade->getEscapedContentTags(); |
21 | | - $this->extensions = $blade->getExtensions(); |
| 18 | + $this->rawTags = $blade->getRawTags(); |
| 19 | + $this->contentTags = $blade->getContentTags(); |
| 20 | + $this->escapedTags = $blade->getEscapedContentTags(); |
| 21 | + $this->extensions = $blade->getExtensions(); |
22 | 22 | $this->customDirectives = $blade->getCustomDirectives(); |
23 | | - $this->config = $config; |
| 23 | + $this->config = $config; |
24 | 24 | } |
25 | 25 |
|
26 | | - /** |
27 | | - * Compile the view at the given path. |
28 | | - * |
29 | | - * @param Illuminate\Database\Eloquent\Model $path |
30 | | - * @return void |
31 | | - */ |
32 | | - public function compile($path) |
33 | | - { |
34 | | - // Defaults to '__db_blade_compiler_content_field' property |
35 | | - $property = $this->config->get('db-blade-compiler.model_property'); |
36 | | - // Defaults to 'contents' column |
37 | | - $column = $path->{$property}; |
38 | | - // Grab the column contents |
39 | | - $string = $path->{$column}; |
40 | | - // Compile to PHP |
41 | | - $contents = $this->compileString($string); |
| 26 | + /** |
| 27 | + * Compile the view at the given path. |
| 28 | + * |
| 29 | + * @param Illuminate\Database\Eloquent\Model $path |
| 30 | + * @return void |
| 31 | + */ |
| 32 | + public function compile($path) |
| 33 | + { |
| 34 | + // Defaults to '__db_blade_compiler_content_field' property |
| 35 | + $property = $this->config->get('db-blade-compiler.model_property'); |
| 36 | + // Defaults to 'contents' column |
| 37 | + $column = $path->{$property}; |
| 38 | + // Grab the column contents |
| 39 | + $string = $path->{$column}; |
| 40 | + // Compile to PHP |
| 41 | + $contents = $this->compileString($string); |
42 | 42 |
|
43 | | - if ( ! is_null($this->cachePath)) |
44 | | - { |
45 | | - $this->files->put($this->getCompiledPath($path), $contents); |
46 | | - } |
47 | | - } |
| 43 | + if (!is_null($this->cachePath)) { |
| 44 | + $this->files->put($this->getCompiledPath($path), $contents); |
| 45 | + } |
| 46 | + } |
48 | 47 |
|
49 | | - /** |
50 | | - * Get the path to the compiled version of a view. |
51 | | - * |
52 | | - * @param Illuminate\Database\Eloquent\Model $model |
53 | | - * @return string |
54 | | - */ |
55 | | - public function getCompiledPath($model) |
56 | | - { |
57 | | - /* |
58 | | - * A unique path for the given model instance must be generated |
59 | | - * so the view has a place to cache. The following generates a |
60 | | - * path using almost the same logic as Blueprint::createIndexName() |
61 | | - * |
62 | | - * e.g db_table_name_id_4 |
63 | | - */ |
64 | | - $field = $this->config->get('db-blade-compiler.model_property'); |
65 | | - $path = 'db_' . $model->getTable() . '_' . $model->{$field} . '_'; |
66 | | - if ( is_null($model->primaryKey) ) |
67 | | - $path .= $model->id; |
68 | | - else if ( is_array($model->primaryKey) ) |
69 | | - $path .= implode('_', $model->primaryKey); |
70 | | - else |
71 | | - $path .= $model->primaryKey; |
| 48 | + /** |
| 49 | + * Get the path to the compiled version of a view. |
| 50 | + * |
| 51 | + * @param Illuminate\Database\Eloquent\Model $model |
| 52 | + * @return string |
| 53 | + */ |
| 54 | + public function getCompiledPath($model) |
| 55 | + { |
| 56 | + /* |
| 57 | + * A unique path for the given model instance must be generated |
| 58 | + * so the view has a place to cache. The following generates a |
| 59 | + * path using almost the same logic as Blueprint::createIndexName() |
| 60 | + * |
| 61 | + * e.g db_table_name_id_4 |
| 62 | + */ |
| 63 | + $field = $this->config->get('db-blade-compiler.model_property'); |
| 64 | + $path = 'db_' . $model->getTable() . '_' . $model->{$field} . '_'; |
| 65 | + if (is_null($model->primaryKey)) { |
| 66 | + $path .= $model->id; |
| 67 | + } else if (is_array($model->primaryKey)) { |
| 68 | + $path .= implode('_', $model->primaryKey); |
| 69 | + } else { |
| 70 | + $path .= $model->primaryKey; |
| 71 | + } |
72 | 72 |
|
73 | | - $path = strtolower(str_replace(array('-', '.'), '_', $path)); |
| 73 | + $path = strtolower(str_replace(array('-', '.'), '_', $path)); |
74 | 74 |
|
75 | | - return $this->cachePath.'/'.md5($path); |
76 | | - } |
| 75 | + return $this->cachePath . '/' . md5($path); |
| 76 | + } |
77 | 77 |
|
78 | | - /** |
79 | | - * Determine if the view at the given path is expired. |
80 | | - * |
81 | | - * @param string $path |
82 | | - * @return bool |
83 | | - */ |
84 | | - public function isExpired($path) |
85 | | - { |
86 | | - if(!$this->config->get('db-blade-compiler.cache')) |
87 | | - { |
88 | | - return true; |
| 78 | + /** |
| 79 | + * Determine if the view at the given path is expired. |
| 80 | + * |
| 81 | + * @param string $path |
| 82 | + * @return bool |
| 83 | + */ |
| 84 | + public function isExpired($path) |
| 85 | + { |
| 86 | + if (!$this->config->get('db-blade-compiler.cache')) { |
| 87 | + return true; |
89 | 88 | } |
90 | | - $compiled = $this->getCompiledPath($path); |
| 89 | + $compiled = $this->getCompiledPath($path); |
91 | 90 |
|
92 | | - // If the compiled file doesn't exist we will indicate that the view is expired |
93 | | - // so that it can be re-compiled. Else, we will verify the last modification |
94 | | - // of the views is less than the modification times of the compiled views. |
95 | | - if ( ! $this->cachePath || ! $this->files->exists($compiled)) |
96 | | - { |
97 | | - return true; |
98 | | - } |
| 91 | + // If the compiled file doesn't exist we will indicate that the view is expired |
| 92 | + // so that it can be re-compiled. Else, we will verify the last modification |
| 93 | + // of the views is less than the modification times of the compiled views. |
| 94 | + if (!$this->cachePath || !$this->files->exists($compiled)) { |
| 95 | + return true; |
| 96 | + } |
99 | 97 |
|
100 | | - $lastModified = strtotime($path->updated_at); |
| 98 | + $lastModified = strtotime($path->updated_at); |
101 | 99 |
|
102 | | - // if ( $lastModified >= $this->files->lastModified($compiled) ) |
103 | | - // echo $lastModified . ' ('.date('r', $lastModified).') > ' . $this->files->lastModified($compiled) . ' ('.date('r', $this->files->lastModified($compiled)).')<br/>'; |
| 100 | + // if ( $lastModified >= $this->files->lastModified($compiled) ) |
| 101 | + // echo $lastModified . ' ('.date('r', $lastModified).') > ' . $this->files->lastModified($compiled) . ' ('.date('r', $this->files->lastModified($compiled)).')<br/>'; |
104 | 102 |
|
105 | | - return $lastModified >= $this->files->lastModified($compiled); |
106 | | - } |
| 103 | + return $lastModified >= $this->files->lastModified($compiled); |
| 104 | + } |
107 | 105 | } |
0 commit comments