Supports blade directives
Now creates a collection of blade directives for available html, and form methods
This commit is contained in:
1 parent
02c75dff24
commit
e9d7084769
1 file changed
+35
@@ -2,10 +2,19 @@
|
|||||||
|
|
||||||
namespace Collective\Html;
|
namespace Collective\Html;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Support\Facades\Blade;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class HtmlServiceProvider extends ServiceProvider
|
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.
|
* Indicates if loading of the provider is deferred.
|
||||||
@@ -27,6 +36,9 @@ class HtmlServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
$this->app->alias('html', 'Collective\Html\HtmlBuilder');
|
$this->app->alias('html', 'Collective\Html\HtmlBuilder');
|
||||||
$this->app->alias('form', 'Collective\Html\FormBuilder');
|
$this->app->alias('form', 'Collective\Html\FormBuilder');
|
||||||
|
|
||||||
|
$this->setBladeDirectives('Html', get_class_methods(HtmlBuilder::class));
|
||||||
|
$this->setBladeDirectives('Form', get_class_methods(FormBuilder::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -55,6 +67,29 @@ class HtmlServiceProvider extends ServiceProvider
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set blade directives
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param array $methods
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function setBladeDirectives($namespace, $methods)
|
||||||
|
{
|
||||||
|
foreach ($methods as $method) {
|
||||||
|
if (in_array($method, $this->directives)) {
|
||||||
|
|
||||||
|
$snakeMethod = Str::snake($method);
|
||||||
|
$directive = strtolower($namespace).'_'.$snakeMethod;
|
||||||
|
|
||||||
|
Blade::directive($directive, function($expression) use ($namespace, $method) {
|
||||||
|
return "<?php echo $namespace::$method$expression; ?>";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the services provided by the provider.
|
* Get the services provided by the provider.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in new issue
Block a user