Skip to content

Commit 8a72266

Browse files
author
mwieser
committed
PSR-2 formatting
1 parent 515ba70 commit 8a72266

File tree

5 files changed

+62
-62
lines changed

5 files changed

+62
-62
lines changed

src/Compilers/BladeCompiler.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
use Illuminate\View\Compilers\BladeCompiler as BaseBladeCompiler;
44
use Illuminate\View\Compilers\CompilerInterface;
55

6-
class BladeCompiler extends BaseBladeCompiler implements CompilerInterface {
6+
class BladeCompiler extends BaseBladeCompiler implements CompilerInterface
7+
{
78

89
/**
910
* Compile the include statements into valid PHP.
1011
*
11-
* @param string $expression
12+
* @param string $expression
1213
* @return string
1314
*/
1415
protected function compileRaw($expression)
1516
{
16-
if (starts_with($expression, '('))
17-
{
17+
if (starts_with($expression, '(')) {
1818
$expression = substr($expression, 1, -1);
1919
}
2020

2121
return "<?php echo \$__env->make($expression, ['raw' => true], array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>";
2222
}
2323

24-
}
24+
}

src/Compilers/HandlebarsCompiler.php

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php namespace ProAI\Handlebars\Compilers;
22

3+
use Illuminate\Support\Facades\Lang;
34
use Illuminate\View\Compilers\Compiler;
45
use Illuminate\View\Compilers\CompilerInterface;
56
use Illuminate\Filesystem\Filesystem;
67
use ProAI\Handlebars\Support\LightnCandy;
78

8-
class HandlebarsCompiler extends Compiler implements CompilerInterface {
9+
class HandlebarsCompiler extends Compiler implements CompilerInterface
10+
{
911

1012
/**
1113
* LightnCandy instance.
@@ -38,10 +40,9 @@ class HandlebarsCompiler extends Compiler implements CompilerInterface {
3840
/**
3941
* Create a new compiler instance.
4042
*
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
4546
*/
4647
public function __construct(Filesystem $files, LightnCandy $lightncandy, $cachePath)
4748
{
@@ -57,7 +58,9 @@ public function __construct(Filesystem $files, LightnCandy $lightncandy, $cacheP
5758
$this->options['basedir'] = $app['config']->get('view.paths');
5859

5960
// 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+
}
6164

6265
// set language helpers option
6366
$this->languageHelpers = (isset($this->options['language_helpers']))
@@ -78,7 +81,7 @@ public function __construct(Filesystem $files, LightnCandy $lightncandy, $cacheP
7881
/**
7982
* Compile the view at the given path.
8083
*
81-
* @param string $path
84+
* @param string $path
8285
* @return void
8386
*/
8487
public function compile($path)
@@ -95,27 +98,24 @@ public function compile($path)
9598
/**
9699
* Compile the view at the given path.
97100
*
98-
* @param string $path
99-
* @param array $options
100-
* @param bool $raw
101-
* @return void
101+
* @param string $path
102+
* @param bool $raw
102103
*/
103104
public function compileString($path, $raw = false)
104105
{
105106
$options = $this->options;
106-
107+
107108
// set partials directory
108-
if ( ! $raw) {
109+
if (!$raw) {
109110
$options['basedir'][] = dirname($path);
110111
}
111112

112113
// set raw option
113114
array_set($options, 'compile_helpers_only', $raw);
114115

115116
// set language helper functions
116-
if($this->languageHelpers)
117-
{
118-
if ( ! $raw) {
117+
if ($this->languageHelpers) {
118+
if (!$raw) {
119119
$helpers = array_merge($this->getLanguageHelpers(), $options['helpers']);
120120
} elseif ($this->translateRawOutput) {
121121
$helpers = $this->getLanguageHelpers();
@@ -143,7 +143,7 @@ public function compileString($path, $raw = false)
143143

144144
$contents = $this->lightncandy->compile($this->files->get($path), $options);
145145

146-
if ( ! is_null($this->cachePath)) {
146+
if (!is_null($this->cachePath)) {
147147
// As of LightnCandy v0.90 generated PHP code will not includes `<?php`.
148148
$this->files->put($this->getCompiledPath($path, $raw), "<?php $contents");
149149
}
@@ -152,15 +152,17 @@ public function compileString($path, $raw = false)
152152
/**
153153
* Get the path to the compiled version of a view.
154154
*
155-
* @param string $path
156-
* @param bool $raw
155+
* @param string $path
156+
* @param bool $raw
157157
* @return string
158158
*/
159159
public function getCompiledPath($path, $raw = false)
160160
{
161-
if ($raw) $path .= '-raw';
161+
if ($raw) {
162+
$path .= '-raw';
163+
}
162164

163-
return $this->cachePath.'/'.md5($path.'-raw');
165+
return $this->cachePath . '/' . md5($path . '-raw');
164166
}
165167

166168
/**
@@ -171,11 +173,11 @@ public function getCompiledPath($path, $raw = false)
171173
protected function getLanguageHelpers()
172174
{
173175
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);
176178
},
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);
179181
}
180182
];
181183
}

src/Engines/HandlebarsEngine.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
use Illuminate\View\Engines\EngineInterface;
44
use Illuminate\View\Engines\CompilerEngine;
55

6-
class HandlebarsEngine extends CompilerEngine implements EngineInterface {
6+
class HandlebarsEngine extends CompilerEngine implements EngineInterface
7+
{
78

89
/**
910
* Get the evaluated contents of the view.
1011
*
11-
* @param string $path
12-
* @param array $data
12+
* @param string $path
13+
* @param array $data
1314
* @return string
1415
*/
1516
public function get($path, array $data = array())
@@ -19,8 +20,7 @@ public function get($path, array $data = array())
1920
// If this given view has expired, which means it has simply been edited since
2021
// it was last compiled, we will re-compile the views so we can evaluate a
2122
// fresh copy of the view. We'll pass the compiler the path of the view.
22-
if ($this->compiler->isExpired($path))
23-
{
23+
if ($this->compiler->isExpired($path)) {
2424
$this->compiler->compile($path);
2525
}
2626

@@ -43,8 +43,8 @@ public function get($path, array $data = array())
4343
/**
4444
* Get the evaluated contents of the view at the given path.
4545
*
46-
* @param string $__path
47-
* @param array $__data
46+
* @param string $__path
47+
* @param array $__data
4848
* @return string
4949
*/
5050
protected function evaluatePath($__path, $__data)
@@ -70,4 +70,4 @@ protected function convertObjectToArray($item)
7070
return $item;
7171
}
7272

73-
}
73+
}

src/HandlebarsServiceProvider.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use ProAI\Handlebars\Compilers\HandlebarsCompiler;
77
use ProAI\Handlebars\Compilers\BladeCompiler;
88

9-
class HandlebarsServiceProvider extends ServiceProvider {
9+
class HandlebarsServiceProvider extends ServiceProvider
10+
{
1011

1112
/**
1213
* Register the application services.
@@ -43,8 +44,7 @@ protected function registerConfig()
4344
*/
4445
protected function registerEngineResolverExtensions()
4546
{
46-
$this->app->extend('view.engine.resolver', function($resolver, $app)
47-
{
47+
$this->app->extend('view.engine.resolver', function ($resolver, $app) {
4848
$this->registerBladeEngine($resolver);
4949

5050
$this->registerHandlebarsEngine($resolver);
@@ -56,7 +56,7 @@ protected function registerEngineResolverExtensions()
5656
/**
5757
* Register the Blade engine implementation.
5858
*
59-
* @param \Illuminate\View\Engines\EngineResolver $resolver
59+
* @param \Illuminate\View\Engines\EngineResolver $resolver
6060
* @return void
6161
*/
6262
public function registerBladeEngine($resolver)
@@ -66,8 +66,7 @@ public function registerBladeEngine($resolver)
6666
// The Compiler engine requires an instance of the CompilerInterface, which in
6767
// this case will be the Blade compiler, so we'll first create the compiler
6868
// instance to pass into the engine so it can compile the views properly.
69-
$app->singleton('blade.compiler', function($app)
70-
{
69+
$app->singleton('blade.compiler', function ($app) {
7170
$cache = $app['config']['view.compiled'];
7271

7372
return new BladeCompiler($app['files'], $cache);
@@ -77,7 +76,7 @@ public function registerBladeEngine($resolver)
7776
/**
7877
* Register the mustache engine implementation.
7978
*
80-
* @param \Illuminate\View\Engines\EngineResolver $resolver
79+
* @param \Illuminate\View\Engines\EngineResolver $resolver
8180
* @return void
8281
*/
8382
public function registerHandlebarsEngine($resolver)
@@ -87,20 +86,17 @@ public function registerHandlebarsEngine($resolver)
8786
// The Compiler engine requires an instance of the CompilerInterface, which in
8887
// this case will be the Handlebars compiler, so we'll first create the compiler
8988
// instance to pass into the engine so it can compile the views properly.
90-
$app->singleton('handlebars.lightncandy', function($app)
91-
{
89+
$app->singleton('handlebars.lightncandy', function ($app) {
9290
return new LightnCandy;
9391
});
9492

95-
$app->singleton('handlebars.compiler', function($app)
96-
{
93+
$app->singleton('handlebars.compiler', function ($app) {
9794
$cache = $app['config']['view.compiled'];
9895

9996
return new HandlebarsCompiler($app['files'], $app['handlebars.lightncandy'], $cache);
10097
});
10198

102-
$resolver->register('handlebars', function() use ($app)
103-
{
99+
$resolver->register('handlebars', function () use ($app) {
104100
return new HandlebarsEngine($app['handlebars.compiler']);
105101
});
106102
}
@@ -112,11 +108,10 @@ public function registerHandlebarsEngine($resolver)
112108
*/
113109
protected function registerFileExtensions()
114110
{
115-
$this->app->extend('view', function($env, $app)
116-
{
111+
$this->app->extend('view', function ($env, $app) {
117112
$fileexts = $app['config']['handlebars.fileext'];
118113

119-
foreach($fileexts as $fileext) {
114+
foreach ($fileexts as $fileext) {
120115
$env->addExtension(trim($fileext, '.'), 'handlebars');
121116
}
122117

@@ -134,4 +129,4 @@ public function provides()
134129
return ['handlebars'];
135130
}
136131

137-
}
132+
}

src/Support/LightnCandy.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
use LightnCandy\LightnCandy as BaseLightnCandy;
44

5-
class LightnCandy extends BaseLightnCandy {
5+
class LightnCandy extends BaseLightnCandy
6+
{
67

78
protected static $compileHelpersOnly;
89

@@ -14,7 +15,8 @@ class LightnCandy extends BaseLightnCandy {
1415
*
1516
* @return string|false Compiled PHP code when successed. If error happened and compile failed, return false.
1617
*/
17-
public static function compile($template, $options = array('flags' => self::FLAG_BESTPERFORMANCE)) {
18+
public static function compile($template, $options = array('flags' => self::FLAG_BESTPERFORMANCE))
19+
{
1820
self::$compileHelpersOnly = (isset($options['compile_helpers_only']) && $options['compile_helpers_only'] == true);
1921

2022
return parent::compile($template, $options);
@@ -27,18 +29,19 @@ public static function compile($template, $options = array('flags' => self::FLAG
2729
* @param string $left left string of a token
2830
* @param string $right right string of a token
2931
*/
30-
protected static function setupToken(&$context, $left = '{{', $right = '}}') {
32+
protected static function setupToken(&$context, $left = '{{', $right = '}}')
33+
{
3134
parent::setupToken($context, $left, $right);
3235

3336
if (self::$compileHelpersOnly) {
3437
$helperTokens = array();
35-
foreach($context['helpers'] as $helper => $value) {
36-
$helperTokens[] = $helper.'.*?';
38+
foreach ($context['helpers'] as $helper => $value) {
39+
$helperTokens[] = $helper . '.*?';
3740
}
3841
$helperTokens = implode('|', $helperTokens);
3942

40-
$context['tokens']['search'] = "/^(.*?)(\\s*)($left)(~?)([\\^#\\/!&>]?)(".$helperTokens.")(~?)($right)(\\s*)(.*)\$/s";
43+
$context['tokens']['search'] = "/^(.*?)(\\s*)($left)(~?)([\\^#\\/!&>]?)(" . $helperTokens . ")(~?)($right)(\\s*)(.*)\$/s";
4144
}
4245
}
4346

44-
}
47+
}

0 commit comments

Comments
 (0)