Skip to content

Commit 0b1c2cd

Browse files
committed
inject DbBladeCompilerEngine in DbView, bind DbBladeCompiler, created DbBladeCompilerEngine
1 parent d0c4956 commit 0b1c2cd

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

src/Flynsarmy/DbBladeCompiler/DbBladeCompiler.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<?php namespace Flynsarmy\DbBladeCompiler;
22

3+
use Illuminate\Config\Repository;
4+
use Illuminate\Database\Eloquent\Model;
35
use Illuminate\View\Compilers\BladeCompiler;
46
use Illuminate\View\Compilers\CompilerInterface;
57

68
class DbBladeCompiler extends BladeCompiler implements CompilerInterface
79
{
810

9-
/** @var \Illuminate\Config\Repository */
11+
/** @var Repository */
1012
protected $config;
1113

12-
public function __construct($filesystem, $cache_path, $config, $app)
14+
public function __construct($filesystem, $cache_path, Repository $config)
1315
{
1416
// Get Current Blade Instance
1517
$blade = app('view')->getEngineResolver()->resolve('blade')->getCompiler();
@@ -26,7 +28,7 @@ public function __construct($filesystem, $cache_path, $config, $app)
2628
/**
2729
* Compile the view at the given path.
2830
*
29-
* @param Illuminate\Database\Eloquent\Model $path
31+
* @param Model $path
3032
* @return void
3133
*/
3234
public function compile($path)
@@ -48,7 +50,7 @@ public function compile($path)
4850
/**
4951
* Get the path to the compiled version of a view.
5052
*
51-
* @param Illuminate\Database\Eloquent\Model $model
53+
* @param Model $model
5254
* @return string
5355
*/
5456
public function getCompiledPath($model)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php namespace Flynsarmy\DbBladeCompiler;
2+
3+
use Illuminate\View\Engines\CompilerEngine;
4+
5+
class DbBladeCompilerEngine extends CompilerEngine
6+
{
7+
/**
8+
* DbBladeCompilerEngine constructor.
9+
*
10+
* @param DbBladeCompiler $bladeCompiler
11+
*/
12+
public function __construct(DbBladeCompiler $bladeCompiler)
13+
{
14+
parent::__construct($bladeCompiler);
15+
}
16+
}

src/Flynsarmy/DbBladeCompiler/DbBladeCompilerServiceProvider.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@ public function register()
3838
$this->mergeConfigFrom($config_path, 'db-blade-compiler');
3939

4040
$this->app['dbview'] = $this->app->share(function ($app) {
41-
$cache_path = storage_path('app/db-blade-compiler/views');
41+
return $app->make(DbView::class);
42+
});
4243

43-
$db_view = new DbView($app['config']);
44-
$compiler = new DbBladeCompiler($app['files'], $cache_path, $app['config'], $app);
45-
$db_view->setEngine(new CompilerEngine($compiler));
44+
$this->app->bind(DbBladeCompiler::class, function($app) {
45+
$cache_path = storage_path('app/db-blade-compiler/views');
4646

47-
return $db_view;
47+
return new DbBladeCompiler($app['files'], $cache_path, $app['config']);
4848
});
49+
4950
$this->app->booting(function () {
5051
$loader = \Illuminate\Foundation\AliasLoader::getInstance();
51-
$loader->alias('DbView', 'Flynsarmy\DbBladeCompiler\Facades\DbView');
52+
$loader->alias('DbView', DbView::class);
5253
});
5354
}
5455

src/Flynsarmy/DbBladeCompiler/DbView.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use Illuminate\Contracts\Support\Arrayable;
55
use Illuminate\Contracts\Support\Renderable;
66
use Illuminate\Config\Repository;
7-
use Illuminate\View\Engines\EngineInterface;
87
use Illuminate\Database\Eloquent\Model;
98

109
class DbView extends \Illuminate\View\View implements ArrayAccess, Renderable
@@ -15,20 +14,16 @@ class DbView extends \Illuminate\View\View implements ArrayAccess, Renderable
1514
/** @var Repository */
1615
protected $config;
1716

18-
public function __construct(Repository $config)
19-
{
20-
$this->config = $config;
21-
}
22-
2317
/**
24-
* @param EngineInterface $compiler
25-
* @return DbView
18+
* DbView constructor.
19+
*
20+
* @param Repository $config
21+
* @param DbBladeCompilerEngine $engine
2622
*/
27-
public function setEngine(EngineInterface $compiler)
23+
public function __construct(Repository $config, DbBladeCompilerEngine $engine)
2824
{
29-
$this->engine = $compiler;
30-
31-
return $this;
25+
$this->config = $config;
26+
$this->engine = $engine;
3227
}
3328

3429
/**

0 commit comments

Comments
 (0)