|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
6
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
7
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
8
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
9
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
10
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
11
|
|
|
* THE SOFTWARE. |
|
12
|
|
|
* |
|
13
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
14
|
|
|
* and is licensed under the MIT license. |
|
15
|
|
|
* |
|
16
|
|
|
* Copyright (c) 2014-2019 Yuuki Takezawa |
|
17
|
|
|
* |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Ytake\LaravelSmarty; |
|
21
|
|
|
|
|
22
|
|
|
use Illuminate\Support\ServiceProvider; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class LaravelSmartyServiceProvider |
|
26
|
|
|
* |
|
27
|
|
|
* @author yuuki.takezawa<[email protected]> |
|
28
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
|
29
|
|
|
*/ |
|
30
|
|
|
class SmartyServiceProvider extends ServiceProvider |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* boot |
|
34
|
|
|
*/ |
|
35
|
|
|
public function boot() |
|
36
|
|
|
{ |
|
37
|
|
|
// add Smarty Extension |
|
38
|
|
|
$extension = $this->app['config']->get('ytake-laravel-smarty.extension', 'tpl'); |
|
39
|
|
|
$this->app['view']->addExtension($extension, 'smarty', function () { |
|
40
|
|
|
// @codeCoverageIgnoreStart |
|
41
|
|
|
$smarty = $this->app->make('smarty.view'); |
|
42
|
|
|
|
|
43
|
|
|
return new Engines\SmartyEngine($smarty->getSmarty()); |
|
44
|
|
|
// @codeCoverageIgnoreEnd |
|
45
|
|
|
}); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function register() |
|
52
|
|
|
{ |
|
53
|
|
|
$configPath = __DIR__ . '/config/ytake-laravel-smarty.php'; |
|
54
|
|
|
$this->mergeConfigFrom($configPath, 'ytake-laravel-smarty'); |
|
55
|
|
|
$this->publishes([ |
|
56
|
|
|
$configPath => $this->resolveConfigurePath() . DIRECTORY_SEPARATOR . 'ytake-laravel-smarty.php', |
|
57
|
|
|
]); |
|
58
|
|
|
|
|
59
|
|
|
$this->app->singleton('smarty.view', function ($app) { |
|
60
|
|
|
$smartyTemplate = new Smarty; |
|
61
|
|
|
$factory = new SmartyFactory( |
|
62
|
|
|
$app['view.engine.resolver'], |
|
63
|
|
|
$app['view.finder'], |
|
64
|
|
|
$app['events'], |
|
65
|
|
|
$smartyTemplate, |
|
66
|
|
|
$this->app['config'] |
|
67
|
|
|
); |
|
68
|
|
|
// Pass the container to the factory so it can be used to resolve view composers. |
|
69
|
|
|
$factory->setContainer($app); |
|
70
|
|
|
$factory->share('app', $app); |
|
71
|
|
|
// resolve cache storage |
|
72
|
|
|
$factory->resolveSmartyCache(); |
|
73
|
|
|
// smarty configure(use ytake-laravel-smarty.php) |
|
74
|
|
|
$factory->setSmartyConfigure(); |
|
75
|
|
|
$smartyTemplate->setViewFactory($factory); |
|
76
|
|
|
|
|
77
|
|
|
return $factory; |
|
78
|
|
|
}); |
|
79
|
|
|
$this->app->alias('smarty.view', SmartyFactory::class); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function resolveConfigurePath(): string |
|
86
|
|
|
{ |
|
87
|
|
|
return (isset($this->app['path.config'])) |
|
88
|
|
|
? (string)$this->app['path.config'] : $this->app->basePath() . DIRECTORY_SEPARATOR . 'config'; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|