/** * Метод подключения шаблонов * @param string $view имя шаблона * @param array $params массив параметров * @param boolean $return выводить или возвращать код * @return string сформированный код */ public static function view($template, $params = [], $return = false) { $blade = new Blade(APP . '/views', STORAGE . '/cache'); if ($return) { return $blade->view()->make($template, $params)->render(); } else { echo $blade->view()->make($template, $params)->render(); } }
public function boot() { $directivesDirectory = base_path() . '/resources/views/directives'; // Check if directory exists if (!File::exists($directivesDirectory)) { return; } $directivePaths = File::files($directivesDirectory); // Check if we have at least one file if (empty($directivePaths)) { return; } $regex = $this->buildRegex($directivePaths); \Blade::extend(function ($view) use($regex) { $offset = 0; while (preg_match($regex, $view, $matches, PREG_OFFSET_CAPTURE, $offset)) { // Store directive name $directiveName = $matches[1][0]; // Store start and length of pattern $patternStart = $matches[0][1]; $patternLength = strlen($matches[0][0]); $expressionStart = $matches[2][1]; // Fetch expression $expr = $this->fetchExpression($view, $expressionStart, $patternStart + $patternLength); // Store beginning and end $beginning = substr($view, 0, $patternStart); $end = substr($view, $expressionStart + strlen($expr) + 1); // Construct view $view = $beginning . "@include('directives.{$directiveName}', array('param' => ({$expr})))" . $end; // Compute new offset to search from $offset = $patternStart + strlen($expr); } return $view; }); }
/** * 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; ?>'; }); }
/** * Bootstrap any application services. * * @return void */ public function boot() { \Blade::setContentTags('{{{', '}}}'); \Blade::setEscapedContentTags('{{', '}}'); \Blade::setEchoFormat('nl2br(e(%s))'); \Form::component('checklist', 'components.form.checklist', ['name', 'options']); }
/** * Bootstrap any application services. * * @return void */ public function boot() { \Blade::extend(function ($value) { $value = preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value); return $value; }); }
/** * Register the Blade view engine with Laravel. * * @return void */ public static function sharpen() { Event::listen(View::engine, function ($view) { // The Blade view engine should only handle the rendering of views which // end with the Blade extension. If the given view does not, we will // return false so the View can be rendered as normal. if (!str_contains($view->path, BLADE_EXT)) { //return; } $compiled = Blade::compiled($view->path); // If the view doesn't exist or has been modified since the last time it // was compiled, we will recompile the view into pure PHP from it's // Blade representation, writing it to cached storage. if (!file_exists($compiled) or Blade::expired($view->view, $view->path)) { file_put_contents($compiled, Blade::compile($view)); } $view->mytplengine or $view->mytplengine = new \TemplateEngine(TEMPLATEPATH); //kd($compiled); $compiled = $view->mytplengine->display($compiled, true); $view->path = $compiled; // Once the view has been compiled, we can simply set the path to the // compiled view on the view instance and call the typical "get" // method on the view to evaluate the compiled PHP view. return ltrim($view->get()); }); }
/** * Bootstrap any application services. * * @return void */ public function boot() { \Blade::setContentTags('<%', '%>'); // for variables and all things Blade \Blade::setEscapedContentTags('<%%', '%%>'); // for escaped data }
/** * Register any application services. * * @return void */ public function register() { $this->mergeConfigFrom(__DIR__ . '/../../../config/veer.php', 'veer'); \Blade::setRawTags('{{', '}}'); \Blade::setContentTags('{{{', '}}}'); \Blade::setEscapedContentTags('{{{', '}}}'); }
/** * Register the service provider. * * @return void */ public function register() { $_this =& $this; $this->app->bind('theme.assets', function ($app) { return new \Onefasteuro\Theme\Assets(new \Assetic\AssetManager(), $app); }); $this->app->bind('theme.page', function ($app) { return new Page\StaticPage($app['config'], $app['theme.assets']); }); $this->app->bind('theme.parser', function ($app) use(&$_this) { $parser = Helper::parser($app); $class = new \ReflectionClass("\\Onefasteuro\\Theme\\{$parser}"); $class = $class->newInstance($app['config'], $app['theme.page']); return $class; }); $this->app->booting(function () { $loader = \Illuminate\Foundation\AliasLoader::getInstance(); $loader->alias('Helper', '\\Onefasteuro\\Theme\\Helper'); }); /** blade partials **/ \Blade::extend(function ($view, $compiler) { $pattern = $compiler->createMatcher('partials'); return preg_replace($pattern, '$1<?php echo \\$__env->make("theme.views::".Helper::skin().".partials.".$2, array_except(get_defined_vars(), array("__data", "__path")))->render(); ?>', $view); }); }
/** * 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 ?>"; }); }
/** * 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'); }
/** * Bootstrap any application services. * * @return void */ public function boot() { /* @eval($var++) */ \Blade::extend(function ($view) { return preg_replace('/\\@eval\\((.+)\\)/', '<?php ${1}; ?>', $view); }); }
/** * Register any application services. * * @return void */ public function register() { $this->app->bind('Illuminate\\Contracts\\Auth\\Registrar', 'App\\Services\\Registrar'); \Blade::setRawTags('{{', '}}'); \Blade::setContentTags('{{{', '}}}'); \Blade::setEscapedContentTags('{{{', '}}}'); }
public function boot() { //@define $i = 'whatever' \Blade::extend(function ($value) { return preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value); }); }
/** * Return template for Angular * * @return View */ public function index() { // Change blade tags so they don't clash with Angular Blade::setEscapedContentTags('[[[', ']]]'); Blade::setContentTags('[[', ']]'); return View::make('addressbook'); }
/** * Register the view environment. */ public function registerBladeTemplate() { /* |-------------------------------------------------------------------------- | @lm-attrs |-------------------------------------------------------------------------- | | Buffers the output if there's any. | The output will be passed to mergeStatic() | where it is merged with item's attributes | */ \Blade::extend(function ($view, $compiler) { $pattern = '/(\\s*)@lm-attrs\\s*\\((\\$[^)]+)\\)/'; return preg_replace($pattern, '$1<?php $lm_attrs = $2->attr(); ob_start(); ?>', $view); }); /* |-------------------------------------------------------------------------- | @lm-endattrs |-------------------------------------------------------------------------- | | Reads the buffer data using ob_get_clean() | and passes it to MergeStatic(). | mergeStatic() takes the static string, | converts it into a normal array and merges it with others. | */ \Blade::extend(function ($view, $compiler) { $pattern = $compiler->CreatePlainMatcher('lm-endattrs'); return preg_replace($pattern, '$1<?php echo \\Lavary\\Menu\\Builder::mergeStatic(ob_get_clean(), $lm_attrs); ?>$2', $view); }); }
/** * register `@php()` directive */ public static function registerPHP($tagName = 'php') { \Blade::extend(function ($view, $compiler) use($tagName) { $pattern = $compiler->createMatcher($tagName); $code = "<?php \$2 ?" . ">"; return preg_replace($pattern, $code, $view); }); }
/** * create a new instance and register blade * * @param array $configs */ public function __construct(array $configs = []) { $cache = isset($configs['cache']) ? $configs['cache'] : RESOURCE . 'cache/'; $view = isset($configs['view']) ? $configs['view'] : VIEW; $language = isset($configs['language']) ? $configs['language'] : LANGUAGE; $this->languageManager = new LanguageManager($language); parent::__construct($view, $cache); }
/** * 引导任何应用服务。 * * @return void */ public function boot() { \Blade::extend(function ($view, $compiler) { $this->app->make('phpBlade')->php($view, $compiler); $this->app->make('phpBlade')->endphp($view, $compiler); $this->app->make('phpBlade')->datetime($view, $compiler); return $view; }); }
/** * Bootstrap any application services. * * @return void */ public function boot() { parent::boot(); \Blade::setRawTags("[[", "]]"); \Blade::setContentTags('<%', '%>'); // for variables and all things Blade \Blade::setEscapedContentTags('<%%', '%%>'); // for escaped data }
/** * 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})"); }); }
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; ?>"; }); }
/** * 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}, '.', ',')?>"; } }); }
/** * 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'); }
/** * 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>'; ?>"; }); }
/** * 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); }); }
/** * Register any application services. * * This service provider is a great spot to register your various container * bindings with the application. As you can see, we are registering our * "Registrar" implementation here. You can add your own bindings too! * * @return void */ public function register() { $this->app->bind('Illuminate\\Contracts\\Auth\\Registrar', 'Symposium\\Services\\Registrar'); $this->app->bind('form', function () { return new \Illuminate\Html\FormBuilder($this->app->make('Illuminate\\Html\\HtmlBuilder'), $this->app->make('Illuminate\\Routing\\UrlGenerator'), csrf_token()); }); $this->app->alias('ttwitter', 'Thujohn\\Twitter\\Twitter'); \Blade::setRawTags('{{', '}}'); \Blade::setContentTags('{{{', '}}}'); \Blade::setEscapedContentTags('{{{', '}}}'); }
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}; ?>"; }); }
public function boot() { $this->publishes([__DIR__ . '/../../../database/migrations/' => database_path('/migrations')], 'migrations'); $this->publishes([__DIR__ . '/../../../config/' => config_path()], 'config'); SiteConfig::macro('has_bonus', function () { return config('bonus') != null; }); \Blade::extend(function ($view, $compiler) { $pattern = "/(?<!\\w)(\\s*)@blink\\(\\s*(.*?)\\)/"; return preg_replace($pattern, '$1' . '<?php if($auth->admin || $auth->id == $2->user->id || $auth->id == $2->user->referral_id|| $auth->id == $2->user->new_referral_id) {?>' . PHP_EOL . '<a href="/bonus-management/view/<?php echo $2->id ?>">' . PHP_EOL . '#<?php echo (1024 + $2->id) ?>' . PHP_EOL . '</a>' . PHP_EOL . '<?php } else { ?>' . PHP_EOL . '<?php echo (1024 + $2->id) ?>' . PHP_EOL . '<?php }?>', $view); }); }
public function boot() { /* @datetime($var) */ \Blade::extend(function ($view, $compiler) { $pattern = $compiler->createOpenMatcher('datetime'); return preg_replace($pattern, '$1<?php echo $2->format(\'m/d/Y H:i\')); ?>', $view); }); /* @eval($var++) */ \Blade::extend(function ($view) { return preg_replace('/\\@eval\\((.+)\\)/', '<?php ${1}; ?>', $view); }); }