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; }); }
/** * 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); }); }
/** * Bootstrap any application services. * * @return void */ public function boot() { /* @eval($var++) */ \Blade::extend(function ($view) { return preg_replace('/\\@eval\\((.+)\\)/', '<?php ${1}; ?>', $view); }); }
/** * Bootstrap any application services. * * @return void */ public function boot() { \Blade::extend(function ($value) { $value = preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value); return $value; }); }
/** * 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); }); }
public function boot() { //@define $i = 'whatever' \Blade::extend(function ($value) { return preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value); }); }
/** * 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); }); }
/** * 引导任何应用服务。 * * @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; }); }
public static function register() { foreach (static::$compiles as $function) { if (!method_exists(__CLASS__, $function = 'compile_' . $function)) { continue; } \Blade::extend(function ($view, $compiler) use($function) { return call_user_func([__CLASS__, $function], $view, $compiler); }); } }
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); }); }
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() { /* |-------------------------------------------------------------------------- | Extend blade so we can define a variable | <code> | @define $variable = "whatever" | </code> |-------------------------------------------------------------------------- */ \Blade::extend(function ($value) { return preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value); }); }
public function boot() { \Blade::extend(function ($view, $compiler) { $pattern = $compiler->createOpenMatcher('tab'); return str_replace('-Ab-', '<a href="chords.php" class="Ab">Ab</a>', $view); }); \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); }); }
/** * Bootstrap any application services. * * @return void */ public function boot() { \HTML::macro('activeClass', function ($path, $active = 'active') { if (Request::is($path . "*")) { return $active; } return ''; }); \Validator::resolver(function ($translator, $data, $rules, $messages) { return new CustomValidator($translator, $data, $rules, $messages); }); \Blade::extend(function ($value) { return preg_replace('/\\@define(.+)/', '<?php ${1}; ?>', $value); }); }
public function registerBladeExtensions() { \Blade::extend(function ($view, $compiler) { $pattern = '/@content\\(\'(.*?)\'\\)(.*?)@endcontent/is'; preg_match_all($pattern, $view, $result); if (is_array($result)) { for ($i = 0; count($result[1]) > $i; $i++) { $replace = $result[0][$i]; $key = $result[1][$i]; $value = $result[2][$i]; if ($key && $value) { $o = \KSPM\LCMS\Model\Content::where('key', '=', $key)->first(); if (!$o) { $o = \KSPM\LCMS\Model\Content::create(array('key' => $key, 'value' => $value)); } $o = "<?php echo \\KSPM\\LCMS\\Model\\Content::where('key', '=', '{$key}')->first()->value; ?>"; $view = str_replace($replace, $o, $view); } } } $pattern = '/@editable_content\\(\'(.*?)\'\\)(.*?)@endeditable_content/is'; preg_match_all($pattern, $view, $result); $cmswrapper = '<div class="laikacms-editable" data-id="%%%oid%%%">%%%php%%%</div>'; if (is_array($result)) { for ($i = 0; count($result[1]) > $i; $i++) { $replace = $result[0][$i]; $key = $result[1][$i]; $value = $result[2][$i]; if ($key && $value) { $o = \KSPM\LCMS\Model\Content::where('key', '=', $key)->first(); if (!$o) { $o = \KSPM\LCMS\Model\Content::create(array('key' => $key, 'value' => $value)); } $o = "<?php \$c = \\KSPM\\LCMS\\Model\\Content::where('key', '=', '{$key}')->first()->value; echo str_replace('%%%oid%%%','{$o->id}', str_replace('%%%php%%%', \$c, '{$cmswrapper}')); ?>"; $view = str_replace($replace, $o, $view); } } } return $view; }); }
public function boot() { $this->publishes([__DIR__ . '/../../../database/migrations/' => database_path('/migrations')], 'migrations'); $this->publishes([__DIR__ . '/../../../config/' => config_path()], 'config'); \Blade::extend(function ($view, $compiler) { $pattern = "/(?<!\\w)(\\s*)@olink\\(\\s*(.*?)\\)/"; return preg_replace($pattern, '$1' . '<?php if($auth->admin || $auth->staff || $auth->id == $2->user_id || ($2->user && $auth->id == $2->user->referral_id) || ($2->user && $auth->id == $2->user->new_referral_id) || $auth->premium) {?>' . PHP_EOL . '<a href="/order-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); }); SiteConfig::macro('show_products', function () { return config('order.show_products'); }); SiteConfig::macro('allow_multiple_products', function () { return config('order.allow_multiple_products'); }); SiteConfig::macro('allow_quantity', function () { return config('order.allow_quantity'); }); SiteConfig::macro('allow_other_product', function () { return config('order.allow_other_product'); }); }
/** * Boot the package. */ public function boot() { $this->package('fojuth/plupload'); // Load package routes include __DIR__ . '/../../routes.php'; // Extend Blade (sic!) \Blade::extend(function ($view) { $pattern = '/@plupload\\((?:\\s?[\'\\"](.*)[\'\\"]\\s?(?:,\\s?[\'\\"](.*)[\'\\"]\\s?(?:,\\s?[\'\\"](.*)[\'\\"])?)?)?\\s?\\)/U'; $replacement = '<?php $view_var = (string) \'$1\'; $prefix_var = (string) \'$2\'; $browse_button_var = (string) \'$3\'; $view = (true === empty($view_var)) ? \\Config::get(\'plupload::plupload.view\') : $view_var; $prefix = (true === empty($prefix_var)) ? \'plupload_\'.uniqid() : $prefix_var; $browse_button = (true === empty($browse_button_var)) ? $prefix.\'_browse\' : $browse_button_var; ?> @include($view, array(\'upload_handler\' => \\Config::get(\'plupload::plupload.upload_handler\'),\'browse_button_id\' => $browse_button,\'prefix\' => $prefix,\'handler_gate\' => \\Config::get(\'plupload::plupload.upload_handler_gate\'),\'max_file_size\' => \\Config::get(\'plupload::plupload.max_file_size\')))'; return preg_replace($pattern, $replacement, $view); }); }
| Register The Laravel Class Loader |-------------------------------------------------------------------------- | | In addition to using Composer, you may use the Laravel class loader to | load your controllers and models. This is useful for keeping all of | your classes in the "global" namespace without Composer updating. | */ ClassLoader::addDirectories(array(app_path() . '/commands', app_path() . '/controllers', app_path() . '/models', app_path() . '/libraries', app_path() . '/database/seeds')); /** * <code> * {? $old_section = "whatever" ?} * </code> */ Blade::extend(function ($value) { return preg_replace('/\\{\\?(.+)\\?\\}/', '<?php ${1} ?>', $value); }); /* |-------------------------------------------------------------------------- | Application Error Logger |-------------------------------------------------------------------------- | | Here we will configure the error logger setup for the application which | is built on top of the wonderful Monolog library. By default we will | build a basic log file setup which creates a single file for logs. | */ Log::useFiles(storage_path() . '/logs/laravel.log'); /* |-------------------------------------------------------------------------- | Application Error Handler
}); Validator::register('valid_datetime', function ($attribute, $value, $parameters) { //match the format of the date if (!empty($value)) { $d = DateTime::createFromFormat(GET_DATETIME(), $value); return !$d ? false : true; } return false; }); Validator::register('valid_date', function ($attribute, $value, $parameters) { //match the format of the date if (!empty($value)) { $d = DateTime::createFromFormat(GET_DATETIME(false), $value); return !$d ? false : true; } return false; }); // BLADE MODIFICATION Blade::extend(function ($value) { return preg_replace('/\\{\\{([^\\-].+?)\\}\\}/s', '<?php echo $1; ?>', $value); }); //BUNDLE CONSTANTS define('USERNAME', Session::get('USERNAME')); define('AUTHORID', Session::get('AUTHORID')); define('ROLE', Session::get('ROLE', 0)); define('LANG', Session::get('LANG', Config::get('cms::settings.language'))); define('CMSLANG', Session::get('CMSLANG', Config::get('cms::settings.language'))); define('CACHE', Config::get('cms::settings.cache_engine')); define('BASE', Config::get('application.url')); //BUNDLE REQUIREMENTS require path('bundle') . 'cms/libraries/helpers' . EXT;
/** * Bootstrap the application services. * * @return void */ public function boot() { \Blade::extend(function ($value, $compiler) { return preg_replace("/@set\\('(.*?)'\\,(.*)\\)/", '<?php $$1 = $2; ?>', $value); }); }
$pattern = $compiler->createMatcher('css'); return preg_replace($pattern, '$1<?php echo HTML::style$2; ?>', $view); }); /** * SCRIPT extension */ Blade::extend(function ($view, BladeCompiler $compiler) { $pattern = $compiler->createMatcher('script'); return preg_replace($pattern, '$1<?php echo HTML::script$2; ?>', $view); }); /** * RESOURCE extension */ Blade::extend(function ($view, BladeCompiler $compiler) { $pattern = $compiler->createMatcher('resource'); return preg_replace($pattern, '$1<?php Resource::add$2; ?>', $view); }); /** * RESOURCE SCRIPTS extension */ Blade::extend(function ($view, BladeCompiler $compiler) { $pattern = $compiler->createPlainMatcher('injectScripts'); return preg_replace($pattern, '$1<?php echo Resource::scripts(); ?>', $view); }); /** * ENVIRONMENT extension */ Blade::extend(function ($view, BladeCompiler $compiler) { $pattern = $compiler->createPlainMatcher('env'); return preg_replace($pattern, '$1<?php echo App::environment(); ?>', $view); });
<?php Blade::extend(function ($view, $compiler) { $pattern = '/(?<!\\w)(\\s*)@ko:text\\s*\\((.*?)\\)/'; return preg_replace($pattern, '$1<!--ko text: $2--><!--/ko-->', $view); }); Blade::extend(function ($view, $compiler) { $pattern = '/(?<!\\w)(\\s*)@ko:html\\s*\\((.*?)\\)/'; return preg_replace($pattern, '$1<!--ko html: $2--><!--/ko-->', $view); }); Blade::extend(function ($view, $compiler) { $pattern = '/(?<!\\w)(\\s*)@ko:each\\s*\\((.*?)\\)/'; return preg_replace($pattern, '$1<!--ko foreach: $2-->', $view); }); Blade::extend(function ($view, $compiler) { $pattern = '/(?<!\\w)(\\s*)@ko:if\\s*\\((.*?)\\)/'; return preg_replace($pattern, '$1<!--ko if: $2-->', $view); }); Blade::extend(function ($view, $compiler) { $pattern = '/(?<!\\w)(\\s*)@ko:unless\\s*\\((.*?)\\)/'; return preg_replace($pattern, '$1<!--ko ifnot: $2-->', $view); }); Blade::extend(function ($view, $compiler) { $pattern = '/(?<!\\w)(\\s*)@ko:with\\s*\\((.*?)\\)/'; return preg_replace($pattern, '$1<!--ko with: $2-->', $view); }); Blade::extend(function ($view, $compiler) { $pattern = '/(?<!\\w)(\\s*)@ko:end\\s*(\\((.*?)\\))?/'; return preg_replace($pattern, '$1<!--/ko-->', $view); });
<?php /* |-------------------------------------------------------------------------- | @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 \\Kiwina\\Menu\\Builder::mergeStatic(ob_get_clean(), $lm_attrs); ?>$2', $view); });
/** * Registers @php and @endphp recognition to blade * * @return void */ private function registerPhpBladeExtensions() { \Blade::extend(function ($view, $compiler) { $pattern = $this->createPlainMatcher('php'); return preg_replace($pattern, "<?php\n", $view); }); \Blade::extend(function ($view, $compiler) { $pattern = $this->createPlainMatcher('endphp'); return preg_replace($pattern, "\n?>", $view); }); }
/** * Register the view environment. */ public function registerBladeTemplate() { \Blade::extend(function ($view, $compiler) { return preg_replace('/\\{\\?(.+)\\?\\}/', '<?php ${1} ?>', $view); }); }
| to the user if maintenance mode is in effect for the application. | */ App::down(function () { return Response::make("Be right back!", 503); }); /* |-------------------------------------------------------------------------- | Require The Filters File |-------------------------------------------------------------------------- | | Next we will load the filters file for the application. This gives us | a nice separate location to store our route and application filter | definitions instead of putting them all in the main routes file. | */ require app_path() . '/filters.php'; // common variables require app_path() . '/constants.php'; // common functions require app_path() . '/helpers.php'; // custom validation require app_path() . '/validators.php'; // for variable assignment Blade::extend(function ($value) { return preg_replace('/\\{\\?(.+)\\?\\}/', '<?php ${1} ?>', $value); }); // for break and continue usage Blade::extend(function ($value) { return preg_replace('/(\\s*)@(break|continue)(\\s*)/', '$1<?php $2; ?>$3', $value); });
<?php Blade::extend(function ($view, $compiler) { $pattern = $compiler->createPlainMatcher('meta'); return preg_replace($pattern, '<?php echo Meta::render();?>', $view); });
* Create a folder named 'widgets' into your views directory * Use this extension by * @widget('NameOfYourWidget') */ Blade::extend(function ($view, $compiler) { $pattern = '/(?<!\\w)(\\s*)@widget\\(\'(.*)\\)/'; $replace = '$1<?php echo $__env->make(\'widgets.$2, array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>'; return preg_replace($pattern, $replace, $view); }); /** * Blade extension for Templates * Create a folder named 'templates' into your views directory * Use this extension by * @template('NameOfTheTemplate') */ Blade::extend(function ($view, $compiler) { $pattern = '/(?<!\\w)(\\s*)@template\\(\'(.*)\\)/'; $replace = '$1<?php echo $__env->make(\'templates.$2, array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>'; return preg_replace($pattern, $replace, $view); }); /** * Blade extension for Partials * Create a folder named 'partials' into your views directory * Use this extension by * @partial('NameOfTheTemplate') */ Blade::extend(function ($view, $compiler) { $pattern = '/(?<!\\w)(\\s*)@partial\\(\'(.*)\\)/'; $replace = '$1<?php echo $__env->make(\'partials.$2, array_except(get_defined_vars(), array(\'__data\', \'__path\')))->render(); ?>'; return preg_replace($pattern, $replace, $view); });
}); // INFO Blade::extend(function ($value) { return preg_replace("/<info>/", "<?php echo '<div class=\"alert alert-info\">' ?>", $value); }); Blade::extend(function ($value) { return preg_replace("/<info closable>/", "<?php echo '<div class=\"alert alert-info alert-dismissible\" role=\"alert\"> <button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button>' ?>", $value); }); Blade::extend(function ($value) { return preg_replace("/<\\/info>/", "<?php echo '</div>' ?>", $value); }); // WARNING Blade::extend(function ($value) { return preg_replace("/<warning>/", "<?php echo '<div class=\"alert alert-warning\">' ?>", $value); }); Blade::extend(function ($value) { return preg_replace("/<warning closable>/", "<?php echo '<div class=\"alert alert-warning alert-dismissible\" role=\"alert\"> <button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button>' ?>", $value); }); Blade::extend(function ($value) { return preg_replace("/<\\/warning>/", "<?php echo '</div>' ?>", $value); }); // DANGER Blade::extend(function ($value) { return preg_replace("/<danger>/", "<?php echo '<div class=\"alert alert-danger\">' ?>", $value); }); Blade::extend(function ($value) { return preg_replace("/<danger closable>/", "<?php echo '<div class=\"alert alert-danger alert-dismissible\" role=\"alert\"> <button type=\"button\" class=\"close\" data-dismiss=\"alert\">×</button>' ?>", $value); }); Blade::extend(function ($value) { return preg_replace("/<\\/danger>/", "<?php echo '</div>' ?>", $value); });
/** * Register blade extensions */ protected function registerBladeExtensions() { // Potion asset url \Blade::extend(function ($view, $compiler) { $pattern = $this->createBladeMatcher('potion_asset_url'); return preg_replace($pattern, '$1<?php echo(\\ClassyGeeks\\Potion\\BladeHelpers::assetUrl$2); ?>', $view); }); // Potion Css \Blade::extend(function ($view, $compiler) { $pattern = $this->createBladeMatcher('potion_asset_css'); return preg_replace($pattern, '$1<?php echo(\\ClassyGeeks\\Potion\\BladeHelpers::assetCss$2); ?>', $view); }); // Potion Js \Blade::extend(function ($view, $compiler) { $pattern = $this->createBladeMatcher('potion_asset_js'); return preg_replace($pattern, '$1<?php echo(\\ClassyGeeks\\Potion\\BladeHelpers::assetJs$2); ?>', $view); }); // Potion Img \Blade::extend(function ($view, $compiler) { $pattern = $this->createBladeMatcher('potion_asset_img'); return preg_replace($pattern, '$1<?php echo(\\ClassyGeeks\\Potion\\BladeHelpers::assetImg$2); ?>', $view); }); }