static function register($class, $view_path) { if (!is_a($class, Widget::class, true)) { throw new \Exception('Не является наследником класса ' . Widget::class); } $widget_name = $class::widget_name(); if ($view_path) { Boot::register_view_path($view_path, $widget_name); } Twig::register_function($widget_name, function ($instance = null) use($class) { return $class::instance($instance); }); }
/** * Добавление в Twig всех зарегистрированных функций, фильтров и тестов */ static function apply() { foreach (self::$filters as $name => $callback) { \Twig::addFilter(new \Twig_SimpleFilter($name, $callback)); } foreach (self::$functions as $name => $callback) { \Twig::addFunction(new \Twig_SimpleFunction($name, $callback)); } foreach (self::$tests as $name => $callback) { \Twig::addTest(new \Twig_SimpleTest($name, $callback)); } foreach (self::$extensions as $name) { \Twig::addExtension(new $name()); } foreach (self::$globals as $k => $v) { \Twig::addGlobal($k, $v); } }
Larakit\Boot::register_alias('LaraPageHead', 'Larakit\\Page\\Facade\\PageHead'); //\Larakit\Widget\ManagerWidget::register(\Larakit\Widget\WidgetBreadcrumbs::class,''); \Larakit\Twig::register_function('larakit_page_h1', function ($route = null) { return LaraPage::pageH1($route); }); \Larakit\Twig::register_function('larakit_page_h1_ext', function ($route = null) { return LaraPage::pageH1Ext($route); }); \Larakit\Twig::register_function('larakit_page_title', function () { return LaraPage::getTitle(); }); \Larakit\Twig::register_function('larakit_page_breadcrumbs', function () { return LaraPage::getBreadCrumbs(); }); \Larakit\Twig::register_function('larakit_route_icons', function ($route = null) { return Larakit\Route\Route::routeIcons($route); }); //TITLE для страниц сайта //\Larakit\Event\Event::listener('lk-page::titles', function($event, $titles){ // return array_merge($titles, (array)trans('page.titles')); //}); //if(!function_exists('larakit_page_head')) { // function larakit_page_head() { // $ret = []; // return ' ' . implode(PHP_EOL . ' ', $ret); // $ret[] = PHP_EOL.sprintf(' <title>%s</title>',\Larakit\Page\Page::getTitle()); // $ret[] = (string) \Larakit\Page\Page::base(); // foreach(\Larakit\Page\PageMeta::$meta_plain as $k => $v) { // $ret[] = (string) HtmlMeta::setAttribute($k, $v); // } // $ret[] = '';
<?php \Larakit\Twig::register_function('crud_row', function ($model, $name = 'admin', $tpl = null) { return new \Larakit\CRUD\CrudRow($model, $name, $tpl); });
<?php //регистрируем функцию Twig \Larakit\Twig::register_function('larahtml', function ($element, $content = '') { $element = '\\Html' . \Illuminate\Support\Str::studly($element); return $element::setContent($content); });
Larakit\Twig::register_function('substr', function ($text, $start, $length) { return mb_substr($text, $start, $length); }); Larakit\Twig::register_function('arr_get', function ($arr, $key, $default = null) { return \Illuminate\Support\Arr::get($arr, $key, $default); }); Larakit\Twig::register_function('widget', function ($class, $name = 'default') { if (false === mb_strpos($class, '\\')) { $class = '\\Larakit\\Widget\\Widget' . studly_case($class); } return $class::factory($name); }); \Larakit\Twig::register_function('request_is', function () { $args = func_get_args(); $args = array_map(function ($item) { return '*' . trim($item, '/') . '*'; }, $args); return call_user_func_array(['Request', 'is'], $args); }); Larakit\Twig::register_function('config_get', function ($key, $default = null) { return \Config::get($key, $default); }); Larakit\Twig::register_function('current_route_name', function () { return \Route::currentRouteName(); }); Larakit\Twig::register_function('route_csrf', function () { try { $args = func_get_args(); $route = array_shift($args); $args = \Illuminate\Support\Arr::get($args, 0, []); $args['_token'] = csrf_token();
<?php if (!function_exists('laralang')) { function laralang($key, $replace = [], $locale = null) { $ret = Lang::get($key, $replace, $locale); return $ret != $key ? $ret : (\Config::get('app.debug') ? $key : ''); } } \Larakit\Twig::register_function('laralang', function ($key, $replace = [], $locale = null) { return Lang::get($key, $replace, $locale); });
public function handle($request, \Closure $next) { \Larakit\Twig::apply(); return $next($request); }
<?php Larakit\Boot::register_provider(\Larakit\Makeup\LarakitServiceProvider::class); Larakit\Boot::register_middleware(\Larakit\Makeup\MakeupMiddleware::class); \Larakit\StaticFiles\Manager::package('larakit/lk-makeup')->usePackage('larakit/sf-bootstrap')->jsPackage('js/makeup.js')->cssPackage('css/makeup.css')->setSourceDir('public')->addExclude('*')->addExclude('makeup/frame*')->addInclude('makeup*'); \Larakit\Twig::register_global('MAKEUP_URL', env('MAKEUPDIR', '!/makeup'));
<?php /** * Created by Larakit. * Link: http://github.com/larakit * User: Alexey Berdnikov * Date: 29.06.16 * Time: 9:37 */ \Larakit\Twig::register_function('icon_by_route', function ($route_name) { return \Larakit\Route\Route::routeIcons($route_name); });
return faker_rus()->userAgent; }); \Larakit\Twig::register_function('faker_image', function ($width = 640, $height = 480, $cat = 'business') { if (!isset(\Larakit\Makeup\Manager::$lorempixel[$width . 'x' . $height])) { \Larakit\Makeup\Manager::$lorempixel[$width . 'x' . $height] = 0; } return URL::route('lorempixel', ['w' => $width, 'h' => $height, 'cat' => $cat, 'number' => ++\Larakit\Makeup\Manager::$lorempixel[$width . 'x' . $height]]); }); \Larakit\Twig::register_function('makeup_pages', function ($width = 640, $height = 480, $cat = null) { return \Larakit\Makeup\Manager::$pages; }); \Larakit\Twig::register_function('makeup_blocks', function ($width = 640, $height = 480, $cat = null) { return \Larakit\Makeup\Manager::$blocks; }); \Larakit\Twig::register_function('makeup_block', function ($name, $params = []) { return \Larakit\Makeup\Manager::block($name)->setParams($params) . ''; }); View::composer('lk-makeup::!.layouts.page', function ($view) { $view->with('theme', Request::input('theme')); $view->with('breakpoint', Request::input('breakpoint')); $view->with('path', Request::path()); }); View::composer('lk-makeup::!.layouts.block', function ($view) { $view->with('theme', Request::input('theme')); $view->with('breakpoint', Request::input('breakpoint')); $view->with('path', Request::path()); }); View::composer('lk-makeup::!.partials.dispatcher', function ($view) { $view->with('theme', Request::input('theme')); $view->with('breakpoint', Request::input('breakpoint')); $view->with('path', Request::path());