本文整理汇总了PHP中Blade::directive方法的典型用法代码示例。如果您正苦于以下问题:PHP Blade::directive方法的具体用法?PHP Blade::directive怎么用?PHP Blade::directive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blade
的用法示例。
在下文中一共展示了Blade::directive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Bootstrap any application services.
*/
public function boot()
{
\Blade::directive('macro', function ($expression) {
$pattern = '/(\\([\'|\\"](\\w+)[\'|\\"],\\s*(([^\\@])+|(.*))\\))/xim';
$matches = [];
preg_match_all($pattern, $expression, $matches);
if (!isset($matches[3][0])) {
throw new \InvalidArgumentException(sprintf('Invalid arguments in blade: macro%s', $expression));
}
return sprintf("<?php \$___tiny['%s']=function(%s){ ob_start(); ?>\n", $matches[2][0], $matches[3][0]);
});
\Blade::directive('endmacro', function ($expression) {
return "\n<?php return ob_get_clean();} ?>\n";
});
\Blade::directive('usemacro', function ($expression) {
$pattern = '/(\\([\'|\\"](\\w+)[\'|\\"],\\s*(([^\\@])+|(.*))\\))/xim';
$matches = [];
preg_match_all($pattern, $expression, $matches);
if (!isset($matches[3][0])) {
throw new \InvalidArgumentException(sprintf('Invalid arguments in blade: usemacro%s', $expression));
}
return sprintf("<?php echo \$___tiny['%s'](%s); ?>\n", $matches[2][0], $matches[3][0]);
});
\Blade::directive('permission', function ($expression) {
return "<?php if(Auth::user()->permission{$expression}): ?>";
});
\Blade::directive('endpermission', function ($expression) {
return '<?php endif; ?>';
});
}
示例2: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
app()->booted(function () {
if (!defined('LARAVEL_BOOTED')) {
define('LARAVEL_BOOTED', microtime(true));
}
});
// \View::composer('*', function($view)
// {
// // prifile views?
// });
\Blade::directive('li', function ($args) {
$args = explode(',', str_replace(["(", ")"], '', $args));
$cmd = str_replace(["'", '"'], '', $args[0]);
array_shift($args);
$args = implode(',', $args);
return "<?php li()->{$cmd}({$args}); ?>";
});
if (\DB::connection()->getDatabaseName()) {
\DB::listen(function ($sql) {
\Lsrur\Inspector\Facade\Inspector::addSql($sql);
});
}
if (is_dir(base_path() . '/resources/views/packages/lsrur/inspector')) {
$this->loadViewsFrom(base_path() . '/resources/views/packages/lsrur/inspector', 'inspector');
} else {
// The package views have not been published. Use the defaults.
$this->loadViewsFrom(__DIR__ . '/views', 'inspector');
}
$kernel = $this->app->make('Illuminate\\Contracts\\Http\\Kernel');
$kernel->pushMiddleware('Lsrur\\Inspector\\Middleware\\Inspector');
$this->publishes([__DIR__ . '/config/inspector.php' => config_path('inspector.php')], 'config');
$this->mergeConfigFrom(__DIR__ . '/config/inspector.php', 'inspector');
}
示例3: bladeDirectives
/**
* Register the blade directives
*
* @return void
*/
private function bladeDirectives()
{
if (!class_exists('\\Blade')) {
return;
}
// Call to Entrust::hasRole
\Blade::directive('role', function ($expression) {
return "<?php if (\\Entrust::hasRole{$expression}) : ?>";
});
\Blade::directive('endrole', function ($expression) {
return "<?php endif; // Entrust::hasRole ?>";
});
// Call to Entrust::can
\Blade::directive('permission', function ($expression) {
return "<?php if (\\Entrust::can{$expression}) : ?>";
});
\Blade::directive('endpermission', function ($expression) {
return "<?php endif; // Entrust::can ?>";
});
// Call to Entrust::ability
\Blade::directive('ability', function ($expression) {
return "<?php if (\\Entrust::ability{$expression}) : ?>";
});
\Blade::directive('endability', function ($expression) {
return "<?php endif; // Entrust::ability ?>";
});
}
示例4: loadZezont4BladeDirectives
public function loadZezont4BladeDirectives()
{
\Blade::directive('hasRole', function ($role_slug) {
return "<?php if (auth()->check()) :\n\t\t\t\tif (auth()->user()->hasRole{$role_slug}) : ?>";
});
\Blade::directive('endhasRole', function () {
return "<?php endif; endif; ?>";
});
}
示例5: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\Blade::directive('combine', function ($expr) {
return \Blade::compileString("implode(' ', with{$expr})");
});
\Blade::directive('capitalize', function ($expr) {
return \Blade::compileString("ucfirst(with{$expr})");
});
}
示例6: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
\Blade::directive('asset_build', function ($expression) {
return "<?php echo app(\\Ree\\Services\\CocktailService::class)->resolveBuildAsset{$expression} ?>";
});
\Blade::directive('asset_theme', function ($expression) {
return "<?php echo app(\\Ree\\Services\\CocktailService::class)->resolveThemeAsset{$expression} ?>";
});
$this->app->make(ThemeConfiguration::class)->setThemeName('default');
}
示例7: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// Set UUID for Monitors on create
Monitor::creating(function (Monitor $monitor) {
$monitor->uuid = Uuid::generate(4);
});
\Blade::directive('datediff', function ($carbon) {
return "<?php echo '<span title=\"'\n .with{$carbon}->format('Y-m-d H:i:s').'\">'.with{$carbon}->diffForHumans().'</span>'; ?>";
});
}
示例8: number
/**
* quick output number format
*/
private function number()
{
\Blade::directive('number', function ($number, $separator = 0, $lang = 'vn') {
if ($lang == 'vn') {
return "<?php echo number_format({$number}, {$separator}, ',', '.') ?>";
} else {
return "<?php echo number_format({$number}, {$separator}, '.', ',')?>";
}
});
}
示例9: boot
public function boot()
{
if (!file_exists(resource_path('i18n'))) {
mkdir(resource_path('i18n'), 0755);
}
I18n::$dir = resource_path('i18n');
I18n::$locale = env('I18N');
\Blade::directive('lang', function ($expression) {
return "<?php echo __{$expression}; ?>";
});
}
示例10: macro
/**
* Register a custom macro(directive).
*
* @param string $name
* @param callable $macro
* @param null $prefix
*/
public static function macro($name, callable $macro, $prefix = null)
{
if (empty($prefix)) {
$prefix = self::$macroName;
}
\Blade::directive($prefix . ucwords($name), function ($argsString = '()') use($macro) {
$args = [];
eval('$args = \\Rtler\\BladeMacro\\BladeMacro::argsToArray' . $argsString . ';');
return call_user_func_array($macro, $args);
});
}
示例11: boot
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
\Blade::directive('activeCheck', function ($expression) {
return "<?php echo Active::check{$expression} ; ?>";
});
\Blade::directive('ifActiveUrl', function ($expression) {
return "<?php if(Active::checkBoolean{$expression}): ?>";
});
\Blade::directive('endIfActiveUrl', function ($expression) {
return '<?php endif; ?>';
});
$this->publishes([__DIR__ . '/config/active.php' => config_path('active.php')]);
}
示例12: bladeDirectives
/**
* Register the blade directives
*
* @return void
*/
private function bladeDirectives()
{
// Call to Rbac::hasRole
\Blade::directive('role', function ($expression) {
return "<?php if (\\Rbac::hasRole({$expression})) : ?>";
});
\Blade::directive('endrole', function ($expression) {
return "<?php endif; // Rbac::hasRole ?>";
});
// Call to Rbac::can
\Blade::directive('permission', function ($expression) {
return "<?php if (\\Rbac::can({$expression})) : ?>";
});
\Blade::directive('endpermission', function ($expression) {
return "<?php endif; // Rbac::can ?>";
});
// Call to Rbac::ability
\Blade::directive('ability', function ($expression) {
return "<?php if (\\Rbac::ability({$expression})) : ?>";
});
\Blade::directive('endability', function ($expression) {
return "<?php endif; // Rbac::ability ?>";
});
}
示例13: function
Blade::directive('route', function ($expression) {
return "<?php if (Route::currentRouteName() == {$expression}) : ?>";
});
Blade::directive('elseifroute', function ($expression) {
return "<?php elseif (Route::currentRouteName() == {$expression}) : ?>";
});
Blade::directive('endroute', function ($expression) {
return "<?php endif; ?>";
});
/**
* Custom blade tag to set variables
* Usage: @title('Page Title')
*/
Blade::directive('set', function ($expression) {
// $pattern = '#@set\(\s*[\'|"]([a-zA-Z_0-9]+)[\'|"]\s*,\s*(.*)\s*\)#';
return "<?php {$expression}; ?>";
});
/**
* Custom blade tag to render a ReactJS component
* Usage: @react('ComponentName', $arguments))
*/
Blade::directive('react', function ($expression) {
$expression = substr($expression, 1);
$expression = substr($expression, 0, -1);
$expressionParts = explode(',', $expression, 2);
$componentName = $expressionParts[0];
$componentName = trim($componentName, '\'"');
$componentId = $componentName . '_' . str_random();
$arguments = isset($expressionParts[1]) ? $expressionParts[1] : '[]';
return "\n<div id=\"{$componentId}\"></div>\n <script>\n ReactDOM.render(\n React.createElement({$componentName}, <?php echo json_encode({$arguments}) ?>),\n document.getElementById('{$componentId}')\n );\n </script>\n ";
});
示例14: extendBladeTags
private function extendBladeTags()
{
\Blade::directive('can', function ($expression) {
return "<?php if (app('backend.gate')->check{$expression}): ?>";
});
\Blade::directive('elsecan', function ($expression) {
return "<?php elseif (app('backend.gate')->check{$expression}): ?>";
});
\Blade::directive('cannot', function ($expression) {
return "<?php if (app('backend.gate')->denies{$expression}): ?>";
});
\Blade::directive('elsecannot', function ($expression) {
return "<?php elseif (app('backend.gate')->denies{$expression}): ?>";
});
}
示例15: function
Route::post('plan/action/date', 'ActionsController@postDate');
Route::post('plan/action/department', 'ActionsController@postDepartment');
Route::post('plan/action/lead', 'ActionsController@postLead');
Route::post('plan/action/status', 'ActionsController@postStatus');
Route::post('plan/task/success', 'TasksController@postSuccess');
Route::post('plan/task/description', 'TasksController@postTask');
Route::post('plan/task/date', 'TasksController@postTaskDate');
Route::post('plan/task/department', 'TasksController@postDepartment');
Route::post('plan/task/lead', 'TasksController@postLead');
Route::post('plan/task/status', 'TasksController@postStatus');
//MyWork editing
Route::get('mywork/edit', 'MyWorkController@edit');
Route::post('mywork/action/lead', 'ActionsController@postLead');
Route::post('mywork/action/collab', 'ActionsController@postCollab');
Route::post('mywork/task/lead', 'TasksController@postLead');
Route::post('mywork/task/collab', 'TasksController@postCollab');
//BLADE ROLE AND PERMISSION DIRECTIVES
// role
Blade::directive('role', function ($expression) {
return "<?php if (Auth::check() && Auth::User()->is{$expression}): ?>";
});
Blade::directive('endrole', function () {
return "<?php endif; ?>";
});
// permission
Blade::directive('permission', function ($expression) {
return "<?php if (Auth::check() && Auth::User()->can{$expression}): ?>";
});
Blade::directive('endpermission', function () {
return "<?php endif; ?>";
});