Laravel version update
Laravel version update
This commit is contained in:
@@ -2,10 +2,20 @@
|
||||
|
||||
namespace Collective\Html;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\Compilers\BladeCompiler;
|
||||
|
||||
class HtmlServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Supported Blade Directives
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $directives = ['entities','decode','script','style','image','favicon','link','secureLink','linkAsset','linkSecureAsset','linkRoute','linkAction','mailto','email','ol','ul','dl','meta','tag','open','model','close','token','label','input','text','password','hidden','email','tel','number','date','datetime','datetimeLocal','time','url','file','textarea','select','selectRange','selectYear','selectMonth','getSelectOption','checkbox','radio','reset','image','color','submit','button','old'
|
||||
];
|
||||
|
||||
/**
|
||||
* Indicates if loading of the provider is deferred.
|
||||
@@ -25,8 +35,10 @@ class HtmlServiceProvider extends ServiceProvider
|
||||
|
||||
$this->registerFormBuilder();
|
||||
|
||||
$this->app->alias('html', 'Collective\Html\HtmlBuilder');
|
||||
$this->app->alias('form', 'Collective\Html\FormBuilder');
|
||||
$this->app->alias('html', HtmlBuilder::class);
|
||||
$this->app->alias('form', FormBuilder::class);
|
||||
|
||||
$this->registerBladeDirectives();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,12 +61,40 @@ class HtmlServiceProvider extends ServiceProvider
|
||||
protected function registerFormBuilder()
|
||||
{
|
||||
$this->app->singleton('form', function ($app) {
|
||||
$form = new FormBuilder($app['html'], $app['url'], $app['view'], $app['session.store']->getToken());
|
||||
$form = new FormBuilder($app['html'], $app['url'], $app['view'], $app['session.store']->token(), $app['request']);
|
||||
|
||||
return $form->setSessionStore($app['session.store']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Blade directives.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerBladeDirectives()
|
||||
{
|
||||
$this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
|
||||
$namespaces = [
|
||||
'Html' => get_class_methods(HtmlBuilder::class),
|
||||
'Form' => get_class_methods(FormBuilder::class),
|
||||
];
|
||||
|
||||
foreach ($namespaces as $namespace => $methods) {
|
||||
foreach ($methods as $method) {
|
||||
if (in_array($method, $this->directives)) {
|
||||
$snakeMethod = Str::snake($method);
|
||||
$directive = strtolower($namespace).'_'.$snakeMethod;
|
||||
|
||||
$bladeCompiler->directive($directive, function ($expression) use ($namespace, $method) {
|
||||
return "<?php echo $namespace::$method($expression); ?>";
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*
|
||||
@@ -62,6 +102,6 @@ class HtmlServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return ['html', 'form', 'Collective\Html\HtmlBuilder', 'Collective\Html\FormBuilder'];
|
||||
return ['html', 'form', HtmlBuilder::class, FormBuilder::class];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user