1
1
<?php namespace ProAI \Handlebars \Compilers ;
2
2
3
+ use Illuminate \Support \Facades \Lang ;
3
4
use Illuminate \View \Compilers \Compiler ;
4
5
use Illuminate \View \Compilers \CompilerInterface ;
5
6
use Illuminate \Filesystem \Filesystem ;
6
7
use ProAI \Handlebars \Support \LightnCandy ;
7
8
8
- class HandlebarsCompiler extends Compiler implements CompilerInterface {
9
+ class HandlebarsCompiler extends Compiler implements CompilerInterface
10
+ {
9
11
10
12
/**
11
13
* LightnCandy instance.
@@ -38,10 +40,9 @@ class HandlebarsCompiler extends Compiler implements CompilerInterface {
38
40
/**
39
41
* Create a new compiler instance.
40
42
*
41
- * @param \Illuminate\Filesystem\Filesystem $files
42
- * @param \ProAI\Handlebars\Support\LightnCandy $lightncandy
43
- * @param string $cachePath
44
- * @return void
43
+ * @param \Illuminate\Filesystem\Filesystem $files
44
+ * @param \ProAI\Handlebars\Support\LightnCandy $lightncandy
45
+ * @param string $cachePath
45
46
*/
46
47
public function __construct (Filesystem $ files , LightnCandy $ lightncandy , $ cachePath )
47
48
{
@@ -57,7 +58,9 @@ public function __construct(Filesystem $files, LightnCandy $lightncandy, $cacheP
57
58
$ this ->options ['basedir ' ] = $ app ['config ' ]->get ('view.paths ' );
58
59
59
60
// make sure helpers array is set
60
- if ( ! isset ($ this ->options ['helpers ' ])) $ this ->options ['helpers ' ] = [];
61
+ if (!isset ($ this ->options ['helpers ' ])) {
62
+ $ this ->options ['helpers ' ] = [];
63
+ }
61
64
62
65
// set language helpers option
63
66
$ this ->languageHelpers = (isset ($ this ->options ['language_helpers ' ]))
@@ -78,7 +81,7 @@ public function __construct(Filesystem $files, LightnCandy $lightncandy, $cacheP
78
81
/**
79
82
* Compile the view at the given path.
80
83
*
81
- * @param string $path
84
+ * @param string $path
82
85
* @return void
83
86
*/
84
87
public function compile ($ path )
@@ -95,27 +98,24 @@ public function compile($path)
95
98
/**
96
99
* Compile the view at the given path.
97
100
*
98
- * @param string $path
99
- * @param array $options
100
- * @param bool $raw
101
- * @return void
101
+ * @param string $path
102
+ * @param bool $raw
102
103
*/
103
104
public function compileString ($ path , $ raw = false )
104
105
{
105
106
$ options = $ this ->options ;
106
-
107
+
107
108
// set partials directory
108
- if ( ! $ raw ) {
109
+ if (! $ raw ) {
109
110
$ options ['basedir ' ][] = dirname ($ path );
110
111
}
111
112
112
113
// set raw option
113
114
array_set ($ options , 'compile_helpers_only ' , $ raw );
114
115
115
116
// set language helper functions
116
- if ($ this ->languageHelpers )
117
- {
118
- if ( ! $ raw ) {
117
+ if ($ this ->languageHelpers ) {
118
+ if (!$ raw ) {
119
119
$ helpers = array_merge ($ this ->getLanguageHelpers (), $ options ['helpers ' ]);
120
120
} elseif ($ this ->translateRawOutput ) {
121
121
$ helpers = $ this ->getLanguageHelpers ();
@@ -143,7 +143,7 @@ public function compileString($path, $raw = false)
143
143
144
144
$ contents = $ this ->lightncandy ->compile ($ this ->files ->get ($ path ), $ options );
145
145
146
- if ( ! is_null ($ this ->cachePath )) {
146
+ if (! is_null ($ this ->cachePath )) {
147
147
// As of LightnCandy v0.90 generated PHP code will not includes `<?php`.
148
148
$ this ->files ->put ($ this ->getCompiledPath ($ path , $ raw ), "<?php $ contents " );
149
149
}
@@ -152,15 +152,17 @@ public function compileString($path, $raw = false)
152
152
/**
153
153
* Get the path to the compiled version of a view.
154
154
*
155
- * @param string $path
156
- * @param bool $raw
155
+ * @param string $path
156
+ * @param bool $raw
157
157
* @return string
158
158
*/
159
159
public function getCompiledPath ($ path , $ raw = false )
160
160
{
161
- if ($ raw ) $ path .= '-raw ' ;
161
+ if ($ raw ) {
162
+ $ path .= '-raw ' ;
163
+ }
162
164
163
- return $ this ->cachePath . '/ ' . md5 ($ path. '-raw ' );
165
+ return $ this ->cachePath . '/ ' . md5 ($ path . '-raw ' );
164
166
}
165
167
166
168
/**
@@ -171,11 +173,11 @@ public function getCompiledPath($path, $raw = false)
171
173
protected function getLanguageHelpers ()
172
174
{
173
175
return [
174
- 'lang ' => function ($ args , $ named ) {
175
- return \ Illuminate \ Support \ Facades \ Lang::get ($ args [0 ], $ named );
176
+ 'lang ' => function ($ args , $ named ) {
177
+ return Lang::get ($ args [0 ], $ named );
176
178
},
177
- 'choice ' => function ($ args , $ named ) {
178
- return \ Illuminate \ Support \ Facades \ Lang::choice ($ args [0 ], $ args [1 ], $ named );
179
+ 'choice ' => function ($ args , $ named ) {
180
+ return Lang::choice ($ args [0 ], $ args [1 ], $ named );
179
181
}
180
182
];
181
183
}
0 commit comments