Skip to content

Commit 0388fd4

Browse files
authored
Fix stringblade.compiler error (#67)
* Fix of BindingResolutionException: Target class [stringblade.compiler] does not exist. * Fix of BindingResolutionException: Target class [stringblade.compiler] does not exist and formatting
1 parent 89fa88c commit 0388fd4

1 file changed

Lines changed: 29 additions & 21 deletions

File tree

src/StringBladeServiceProvider.php

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Wpb\String_Blade_Compiler;
34

45
use Illuminate\View\FileViewFinder;
@@ -7,7 +8,7 @@
78
use Wpb\String_Blade_Compiler\Engines\CompilerEngine;
89
use Wpb\String_Blade_Compiler\Compilers\StringBladeCompiler;
910

10-
class StringBladeServiceProvider extends ViewServiceProvider
11+
class StringBladeServiceProvider extends ViewServiceProvider
1112
{
1213

1314
/**
@@ -19,12 +20,13 @@ public function register()
1920
{
2021
// include the package config
2122
$this->mergeConfigFrom(
22-
__DIR__.'/../config/blade.php', 'blade'
23+
__DIR__ . '/../config/blade.php', 'blade'
2324
);
2425

2526
$this->registerFactory();
2627
$this->registerViewFinder();
2728
$this->registerBladeCompiler();
29+
$this->registerStringbladeCompiler();
2830
$this->registerEngineResolver();
2931

3032
}
@@ -60,9 +62,9 @@ public function registerFactory()
6062
/**
6163
* Create a new Factory Instance.
6264
*
63-
* @param \Illuminate\View\Engines\EngineResolver $resolver
64-
* @param \Illuminate\View\ViewFinderInterface $finder
65-
* @param \Illuminate\Contracts\Events\Dispatcher $events
65+
* @param \Illuminate\View\Engines\EngineResolver $resolver
66+
* @param \Illuminate\View\ViewFinderInterface $finder
67+
* @param \Illuminate\Contracts\Events\Dispatcher $events
6668
* @return \Illuminate\View\Factory
6769
*/
6870
protected function createFactory($resolver, $finder, $events)
@@ -87,12 +89,12 @@ public function registerViewFinder()
8789
// recreate the view.finder
8890
$this->app->bind('view.finder', function ($app) use ($oldFinder) {
8991

90-
$paths = (isset($oldFinder['paths']))?array_unique(array_merge($app['config']['view.paths'], $oldFinder['paths']), SORT_REGULAR):$app['config']['view.paths'];
92+
$paths = (isset($oldFinder['paths'])) ? array_unique(array_merge($app['config']['view.paths'], $oldFinder['paths']), SORT_REGULAR) : $app['config']['view.paths'];
9193

9294
$viewFinder = new FileViewFinder($app['files'], $paths);
9395

9496
if (!empty($oldFinder['hints'])) {
95-
array_walk($oldFinder['hints'], function($value, $key) use ($viewFinder) {
97+
array_walk($oldFinder['hints'], function ($value, $key) use ($viewFinder) {
9698
$viewFinder->addNamespace($key, $value);
9799
});
98100
}
@@ -109,40 +111,46 @@ public function registerViewFinder()
109111
public function registerEngineResolver()
110112
{
111113
// recreate the resolver, adding stringblade
112-
$this->app->singleton('view.engine.resolver', function () {
114+
$this->app->singleton('view.engine.resolver', function ($app) {
113115
$resolver = new EngineResolver;
114116

115117
// Next, we will register the various view engines with the resolver so that the
116118
// environment will resolve the engines needed for various views based on the
117119
// extension of view file. We call a method for each of the view's engines.
118120
foreach (['file', 'php', 'blade', 'stringblade'] as $engine) {
119-
$this->{'register'.ucfirst($engine).'Engine'}($resolver);
121+
$this->{'register' . ucfirst($engine) . 'Engine'}($resolver);
120122
}
121123

122124
return $resolver;
123125
});
124126
}
125127

126128
/**
127-
* Register the StringBlade engine implementation.
129+
* Register the String Blade compiler implementation.
128130
*
129-
* @param \Illuminate\View\Engines\EngineResolver $resolver
130131
* @return void
131132
*/
132-
public function registerStringBladeEngine($resolver)
133+
public function registerStringbladeCompiler()
133134
{
134-
$app = $this->app;
135-
136135
// The Compiler engine requires an instance of the CompilerInterface, which in
137136
// this case will be the Blade compiler, so we'll first create the compiler
138137
// instance to pass into the engine so it can compile the views properly.
139-
$app->singleton('stringblade.compiler', function ($app) {
140-
$cache = $app['config']['view.compiled'];
141-
return new StringBladeCompiler($app['files'], $cache);
138+
$this->app->singleton('stringblade.compiler', function () {
139+
$cache = $this->app['config']['view.compiled'];
140+
return new StringBladeCompiler($this->app['files'], $cache);
142141
});
142+
}
143143

144-
$resolver->register('stringblade', function () use ($app) {
145-
return new CompilerEngine($app['stringblade.compiler']);
144+
/**
145+
* Register the StringBlade engine implementation.
146+
*
147+
* @param \Illuminate\View\Engines\EngineResolver $resolver
148+
* @return void
149+
*/
150+
public function registerStringbladeEngine($resolver)
151+
{
152+
$resolver->register('stringblade', function () {
153+
return new CompilerEngine($this->app['stringblade.compiler']);
146154
});
147155
}
148156

@@ -153,12 +161,12 @@ public function registerStringBladeEngine($resolver)
153161
*/
154162
public function boot()
155163
{
156-
if(config('blade.autoload_custom_directives')) {
164+
if (config('blade.autoload_custom_directives')) {
157165
$blade = app('blade.compiler');
158166
$string_blade = app('stringblade.compiler');
159167

160168
collect($blade->getCustomDirectives())
161-
->each(function($directive, $name) use ($string_blade) {
169+
->each(function ($directive, $name) use ($string_blade) {
162170
$string_blade->directive($name, $directive);
163171
});
164172
}

0 commit comments

Comments
 (0)