datatable.directory codebase https://datatable.directory/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
datatable.directory/porklib/Providers/BladeExtensionsProvider.php

74 lines
1.4 KiB

<?php
namespace MightyPork\Providers;
use Blade;
use Illuminate\Support\ServiceProvider;
class BladeExtensionsProvider extends ServiceProvider
{
/**
* Parse argument of a blade directive
*
* @param string $x argument received by a blade directive
* @return array the arguments (strings without quotes)
*/
private static function parseBladeArgs($x)
{
// strip wrapping parens
return array_map('trim', str_getcsv($x));
}
/**
* Add blade directives
*
* @return void
*/
public function boot()
{
// @faker(text, 100)
Blade::directive('faker', function ($x) {
$args = self::parseBladeArgs($x);
$method = $args[0];
$params = count($args) > 1 ? $args[1] : '';
return "<?= e(app()->make('\\Faker\\Generator')->$method($params)) ?>";
});
// json encode
Blade::directive('json', function ($x) {
return "<?= toJSON($x) ?>";
});
// json encode, escaped
Blade::directive('jsone', function ($x) {
return "<?= e(toJSON($x)) ?>";
});
// selected if cond true
Blade::directive('selected', function ($x) {
return "<?= ($x) ? 'selected' : '' ?>";
});
// checked if cond true
Blade::directive('checked', function ($x) {
return "<?= ($x) ? 'checked' : '' ?>";
});
Blade::if('set', function ($x) {
return config($x) != '';
});
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}