Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
75.00% |
3 / 4 |
CRAP | |
97.92% |
47 / 48 |
| BladeExtensionsServiceProvider | |
0.00% |
0 / 1 |
|
75.00% |
3 / 4 |
9 | |
97.92% |
47 / 48 |
| boot | |
100.00% |
1 / 1 |
2 | |
100.00% |
18 / 18 |
|||
| anonymous function | |
100.00% |
1 / 1 |
1 | |
100.00% |
5 / 5 |
|||
| register | |
0.00% |
0 / 1 |
4.00 | |
94.12% |
16 / 17 |
|||
| provides | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
| <?php | |
| /** | |
| * A laravel service provider to register the class into the the IoC container | |
| */ | |
| namespace Radic\BladeExtensions; | |
| use Caffeinated\Beverage\ServiceProvider; | |
| use Exception; | |
| use Illuminate\Contracts\Foundation\Application; | |
| use Illuminate\View\Engines\CompilerEngine; | |
| use Radic\BladeExtensions\Compilers\MarkdownCompiler; | |
| use Radic\BladeExtensions\Directives\AssignmentDirectives; | |
| use Radic\BladeExtensions\Directives\DebugDirectives; | |
| use Radic\BladeExtensions\Directives\EmbeddingDirectives; | |
| use Radic\BladeExtensions\Directives\ForeachDirectives; | |
| use Radic\BladeExtensions\Directives\MacroDirectives; | |
| use Radic\BladeExtensions\Directives\MarkdownDirectives; | |
| use Radic\BladeExtensions\Directives\MinifyDirectives; | |
| use Radic\BladeExtensions\Engines\BladeMarkdownEngine; | |
| use Radic\BladeExtensions\Engines\PhpMarkdownEngine; | |
| use Radic\BladeExtensions\Renderers\BladeStringRenderer; | |
| /** | |
| * A laravel service provider to register the class into the the IoC container | |
| * | |
| * @package Radic\BladeExtensions | |
| * @version 2.1.0 | |
| * @author Robin Radic | |
| * @license MIT License - http://radic.mit-license.org | |
| * @copyright 2011-2015, Robin Radic | |
| * @link http://robin.radic.nl/blade-extensions | |
| * | |
| */ | |
| class BladeExtensionsServiceProvider extends ServiceProvider | |
| { | |
| /** {@inheritDoc} */ | |
| protected $configFiles = [ 'blade_extensions' ]; | |
| /** | |
| * {@inheritDoc} | |
| */ | |
| protected $dir = __DIR__; | |
| protected $providers = [ \Caffeinated\Beverage\BeverageServiceProvider::class ]; | |
| protected $provides = [ 'blade.helpers', 'blade.string' ]; | |
| protected $bindings = [ | |
| 'blade.string' => BladeStringRenderer::class | |
| ]; | |
| protected $singletons = [ | |
| 'blade.helpers' => Helpers\HelperRepository::class | |
| ]; | |
| /** {@inheritDoc} */ | |
| public function boot() | |
| { | |
| /** @var \Illuminate\Foundation\Application $app */ | |
| $app = parent::boot(); | |
| $config = array_dot($this->app['config']['blade_extensions']); | |
| if ($config['markdown.enabled']) { | |
| $view = $app->make('view'); | |
| $compiler = $app->make('markdown.compiler'); | |
| $markdown = $app->make('markdown'); | |
| $blade = $app->make('blade.compiler'); | |
| $view->getEngineResolver()->register('md', function () use ($compiler) { | |
| return new CompilerEngine($compiler); | |
| }); | |
| $view->addExtension('md', 'md'); | |
| $view->getEngineResolver()->register('phpmd', function () use ($markdown) { | |
| return new PhpMarkdownEngine($markdown); | |
| }); | |
| $view->addExtension('md.php', 'phpmd'); | |
| $view->getEngineResolver()->register('blademd', function () use ($blade, $markdown) { | |
| return new BladeMarkdownEngine($blade, $markdown); | |
| }); | |
| $view->addExtension('md.blade.php', 'blademd'); | |
| } | |
| } | |
| /** {@inheritDoc} */ | |
| public function register() | |
| { | |
| /** @var \Illuminate\Foundation\Application $app */ | |
| $app = parent::register(); | |
| $config = array_dot($this->app['config']['blade_extensions']); | |
| if ($config['example_views'] === true) { | |
| $this->viewDirs = [ 'views' => 'blade-ext' ]; | |
| } | |
| AssignmentDirectives::attach($app); | |
| DebugDirectives::attach($app); | |
| ForeachDirectives::attach($app); | |
| EmbeddingDirectives::attach($app); | |
| MacroDirectives::attach($app); | |
| MinifyDirectives::attach($app); | |
| # Optional markdown compiler, engines and directives | |
| if ($config['markdown.enabled']) { | |
| if (! class_exists($config['markdown.renderer'])) { | |
| throw new Exception('The configured markdown renderer class does not exist'); | |
| } | |
| $app->bind('Radic\BladeExtensions\Contracts\MarkdownRenderer', $config['markdown.renderer']); | |
| $app->singleton('markdown', function (Application $app) { | |
| return $app->make('Radic\BladeExtensions\Contracts\MarkdownRenderer'); | |
| }); | |
| $app->singleton('markdown.compiler', function (Application $app) { | |
| $markdownRenderer = $app->make('markdown'); | |
| $files = $app->make('files'); | |
| $storagePath = $app['config']->get('view.compiled'); | |
| return new MarkdownCompiler($markdownRenderer, $files, $storagePath); | |
| }); | |
| MarkdownDirectives::attach($app); | |
| } | |
| } | |
| /** | |
| * @inheritDoc | |
| */ | |
| public function provides() | |
| { | |
| $p = parent::provides(); | |
| if ($this->app['config']['blade_extensions.markdown.enabled']) { | |
| $p = array_merge($p, [ 'markdown', 'markdown.compiler' ]); | |
| } | |
| return $p; | |
| } | |
| } |