当前位置: 首页>>代码示例>>PHP>>正文


PHP Volt::getCompiler方法代码示例

本文整理汇总了PHP中Phalcon\Mvc\View\Engine\Volt::getCompiler方法的典型用法代码示例。如果您正苦于以下问题:PHP Volt::getCompiler方法的具体用法?PHP Volt::getCompiler怎么用?PHP Volt::getCompiler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\Mvc\View\Engine\Volt的用法示例。


在下文中一共展示了Volt::getCompiler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: registerServices

 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices(\Phalcon\DiInterface $di)
 {
     /**
      * Read configuration
      */
     /**
      * Setting up the view component
      */
     $config = $this->config;
     $di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->application->backendViewsDir);
         $view->registerEngines(array(".volt" => 'volt'));
         return $view;
     }, true);
     /**
      * Setting up volt
      */
     $di->set('volt', function ($view, $di) use($config) {
         $volt = new Volt($view, $di);
         $volt->setOptions(array("compiledPath" => APP_PATH . "/app/cache/volt/", "compiledSeparator" => "_", "compileAlways" => $config->application->debug));
         $volt->getCompiler()->addFunction('tr', function ($key) {
             return "messetool\\Modules\\Modules\\Backend\\Controllers\\ControllerBase::translate({$key})";
         });
         $volt->getCompiler()->addFunction('number_format', function ($resolvedArgs) {
             return 'number_format(' . $resolvedArgs . ')';
         });
         $volt->getCompiler()->addFunction('linkAllowed', function ($args) {
             return "messetool\\Acl\\Acl::linkAllowed({$args})";
         });
         return $volt;
     }, true);
 }
开发者ID:phil-schreiber,项目名称:messewebsite,代码行数:38,代码来源:Module.php

示例2: addFunction

 public function addFunction(Extension\ExFunction $extension)
 {
     $this->volt->getCompiler()->addFunction($extension->getName(), function () use($extension) {
         $this->view->setVar('func_extension_' . $extension->getName(), $extension);
         $extension->setParams(func_get_args());
         return '$this->getView()->getVar(\'func_extension_' . $extension->getName() . '\')->call();';
     });
 }
开发者ID:mirobrando,项目名称:ng-phalcon,代码行数:8,代码来源:RegisterView.php

示例3: registerServices

 /**
  * Register specific services for the module
  * @param \Phalcon\DiInterface $di
  */
 public function registerServices(DiInterface $di)
 {
     $config = $this->_config;
     $configShared = $di->get('config');
     $vDI = $di;
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Cnab');
         return $dispatcher;
     });
     //Registering the view component
     $di->set('volt', function ($view, $vDI) use($config, $configShared) {
         $volt = new Volt($view, $vDI);
         $volt->setOptions(array('compiledPath' => $configShared->volt->path, 'compiledExtension' => $configShared->volt->extension, 'compiledSeparator' => $configShared->volt->separator, 'stat' => (bool) $configShared->volt->stat));
         $compiler = $volt->getCompiler();
         //Add funcao
         $compiler->addFunction('is_a', 'is_a');
         return $volt;
     });
     /**
      * Configura o serviço de view
      */
     $di->set('view', function () use($config, $vDI) {
         $view = new View();
         $view->setViewsDir($config->application->viewsDir);
         $view->registerEngines(array('.volt' => 'volt'));
         return $view;
     });
     return $di;
 }
开发者ID:denners777,项目名称:api-phalcon,代码行数:35,代码来源:Module.php

示例4: factory

 /**
  * Create view instance.
  * If no events manager provided - events would not be attached.
  *
  * @param DIBehaviour  $di             DI.
  * @param Config       $config         Configuration.
  * @param string|null  $viewsDirectory Views directory location.
  * @param Manager|null $em             Events manager.
  *
  * @return View
  */
 public static function factory($di, $config, $viewsDirectory = null, $em = null)
 {
     $view = new View();
     $volt = new Volt($view, $di);
     $volt->setOptions(["compiledPath" => $config->application->view->compiledPath, "compiledExtension" => $config->application->view->compiledExtension, 'compiledSeparator' => $config->application->view->compiledSeparator, 'compileAlways' => $config->application->debug && $config->application->view->compileAlways]);
     $compiler = $volt->getCompiler();
     $compiler->addExtension(new Extension());
     $view->registerEngines([".volt" => $volt])->setRenderLevel(View::LEVEL_ACTION_VIEW)->restoreViewDir();
     if (!$viewsDirectory) {
         $view->setViewsDir($viewsDirectory);
     }
     // Attach a listener for type "view".
     if ($em) {
         $em->attach("view", function ($event, $view) use($di, $config) {
             if ($config->application->profiler && $di->has('profiler')) {
                 if ($event->getType() == 'beforeRender') {
                     $di->get('profiler')->start();
                 }
                 if ($event->getType() == 'afterRender') {
                     $di->get('profiler')->stop($view->getActiveRenderPath(), 'view');
                 }
             }
             if ($event->getType() == 'notFoundView') {
                 throw new Exception('View not found - "' . $view->getActiveRenderPath() . '"');
             }
         });
         $view->setEventsManager($em);
     }
     return $view;
 }
开发者ID:phalconeye,项目名称:framework,代码行数:41,代码来源:View.php

示例5: getCompiler

 public function getCompiler()
 {
     // Load macros:
     if (empty($this->_compiler)) {
         parent::getCompiler();
         $this->partial('macros');
     }
     $compiler = parent::getCompiler();
     // View filters:
     $compiler->addFilter('merge', 'array_merge');
     $compiler->addFilter('md5', 'md5');
     $compiler->addFilter('split', function ($resolvedArgs, $exprArgs) {
         $a = explode(',', $resolvedArgs);
         $cmd = 'explode(' . trim($a[1]) . ', ' . $a[0] . ')';
         return $cmd;
     });
     $compiler->addFilter('trans', function ($resolvedArgs, $exprArgs) {
         $a = explode(',', $resolvedArgs);
         return '$this->di->getTrans()->query(' . $a[0] . (count($a) > 1 ? ',' . $a[1] : '') . ')';
     });
     $compiler->addFilter('date', function ($resolvedArgs, $exprArgs) {
         $a = explode(',', $resolvedArgs);
         return 'date(' . $a[1] . ', strtotime(' . $a[0] . '))';
     });
     $compiler->addFunction('is_granted', function ($args) {
         return '$this->di->getUser()->isGranted(' . $args . ')';
     });
     $compiler->addFunction('render', function ($args) {
         return 'file_get_contents(sprintf(\'%s://%s\', $_SERVER[\'REQUEST_SCHEME\'], $_SERVER[\'HTTP_HOST\']).' . $args . ')';
     });
     $compiler->addFunction('square', function ($arg) {
         return $arg . ' * ' . $arg;
     });
     return $compiler;
 }
开发者ID:siciarek,项目名称:suggester,代码行数:35,代码来源:view.php

示例6: registerViewFunctions

 /**
  * register custom volt function to use in frontend
  *
  * @param $view
  * @param array $functions
  */
 public static function registerViewFunctions(Volt &$view, array $functions = [])
 {
     $compiler = $view->getCompiler();
     foreach ($functions as $name => $body) {
         $compiler->addFunction($name, $body);
     }
 }
开发者ID:adrianeavaz,项目名称:manager.io,代码行数:13,代码来源:VoltHelper.php

示例7: factory

 /**
  * Create view instance.
  * If no events manager provided - events would not be attached.
  *
  * @param DIBehaviour  $di             DI.
  * @param Config       $config         Configuration.
  * @param string       $viewsDirectory Views directory location.
  * @param Manager|null $em             Events manager.
  *
  * @return View
  */
 public static function factory($di, $config, $viewsDirectory, $em = null)
 {
     $view = new PhView();
     $volt = new PhVolt($view, $di);
     $volt->setOptions(["compiledPath" => $config->global->view->compiledPath, "compiledExtension" => $config->global->view->compiledExtension, 'compiledSeparator' => $config->global->view->compiledSeparator, 'compileAlways' => $config->global->view->compileAlways]);
     $compiler = $volt->getCompiler();
     $compiler->addExtension(new EnViewExtension());
     $compiler->addFilter('floor', 'floor');
     $compiler->addFunction('range', 'range');
     $compiler->addFunction('in_array', 'in_array');
     $compiler->addFunction('count', 'count');
     $compiler->addFunction('str_repeat', 'str_repeat');
     $view->registerEngines(['.volt' => $volt])->setRenderLevel(PhView::LEVEL_ACTION_VIEW)->setViewsDir($viewsDirectory);
     // Attach a listener for type "view".
     if ($em) {
         $em->attach("view", function ($event, $view) use($di, $config) {
             if ($config->global->profiler && $di->has('profiler')) {
                 if ($event->getType() == 'beforeRender') {
                     $di->get('profiler')->start();
                 }
                 if ($event->getType() == 'afterRender') {
                     $di->get('profiler')->stop($view->getActiveRenderPath(), 'view');
                 }
             }
             if ($event->getType() == 'notFoundView') {
                 throw new Exception('View not found - "' . $view->getActiveRenderPath() . '"');
             }
         });
         $view->setEventsManager($em);
     }
     $di->set('view', $view);
     return $view;
 }
开发者ID:nguyenducduy,项目名称:phblog,代码行数:44,代码来源:View.php

示例8: getCompiler

 public function getCompiler()
 {
     if (empty($this->_compiler)) {
         parent::getCompiler();
         // add macros that need initialized before parse time
         $this->partial("macros/url");
     }
     return parent::getCompiler();
 }
开发者ID:vlad6085,项目名称:projectstorage,代码行数:9,代码来源:VoltC.php

示例9: registerVolt

 private function registerVolt(&$view, $di, $config)
 {
     $view->registerEngines([".volt" => function ($view, $di) use($config) {
         $volt = new VoltEngine($view, $di);
         $options = ['compileAlways' => $this->getConfig('app')->debug, 'compiledPath' => $config['engine']['volt']['cache'], 'compiledSeparator' => '_'];
         $volt->setOptions($options);
         $compiler = $volt->getCompiler();
         return $volt;
     }]);
     return;
 }
开发者ID:broklyngagah,项目名称:orbit,代码行数:11,代码来源:ViewServiceProvider.php

示例10: registerServices

 /**
  * Registers services related to the module
  *
  * @param DiInterface $di
  */
 public function registerServices(DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (include APP_PATH . "/apps/backend/config/config.php");
     /**
      * Setting up the view component
      */
     $di['view'] = function () use($config) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => __DIR__ . '/cache/', 'compiledSeparator' => '_'));
             $compiler = $volt->getCompiler();
             // format number
             $compiler->addFilter('number', function ($resolvedArgs) {
                 return 'Helpers::number(' . $resolvedArgs . ');';
             });
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     };
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di['db'] = function () use($config) {
         $config = $config->database->toArray();
         $dbAdapter = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $config['adapter'];
         unset($config['adapter']);
         return new $dbAdapter($config);
     };
     /**
      * Logger service
      */
     $di->set('logger', function ($filename = null, $format = null) use($config) {
         $format = $format ?: $config->get('logger')->format;
         $filename = trim($filename ?: $config->get('logger')->filename, '\\/');
         $path = rtrim($config->get('logger')->path, '\\/') . DIRECTORY_SEPARATOR;
         $formatter = new FormatterLine($format, $config->get('logger')->date);
         $logger = new FileLogger($path . $filename);
         $logger->setFormatter($formatter);
         $logger->setLogLevel($config->get('logger')->logLevel);
         return $logger;
     });
     $di->set('url', function () use($config) {
         $url = new UrlResolver();
         $url->setBaseUri("/backend/");
         return $url;
     });
 }
开发者ID:vietdh85,项目名称:product-vh,代码行数:57,代码来源:Module.php

示例11: register

 /**
  * Initializes Volt engine
  */
 public function register()
 {
     $di = $this->getDi();
     $eventsManager = $this->getEventsManager();
     $config = $this->_config;
     $di->set('viewEngine', function ($view, $di) use($config) {
         $volt = new ViewEngine($view, $di);
         $volt->setOptions(["compiledPath" => $config->application->view->compiledPath, "compiledExtension" => $config->application->view->compiledExtension, 'compiledSeparator' => $config->application->view->compiledSeparator, 'compileAlways' => $config->application->view->compileAlways]);
         $compiler = $volt->getCompiler();
         $compiler->addFilter('dump', function ($resolvedArgs) {
             return 'var_dump(' . $resolvedArgs . ')';
         });
         return $volt;
     });
 }
开发者ID:tashik,项目名称:phalcon_core,代码行数:18,代码来源:Volt.php

示例12: boot

 /**
  * @param $container
  */
 public function boot(Container $container)
 {
     $container->setShared('view', function () {
         $view = new PhalconView();
         $view->setEventsManager($this->getShared('eventsManager'));
         $view->setViewsDir($this->path('views'));
         $view->registerEngines(['.volt' => 'volt', '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']);
         return $view;
     });
     $container->setShared('volt', function () {
         $volt = new Volt($this->get('view'));
         $volt->setOptions(['compiledPath' => $this->tmpPath() . '/cache/volt/', 'compiledSeparator' => '_', 'compileAlways' => true]);
         $volt->getCompiler()->addExtension(new \Pails\Extensions\Volt());
         return $volt;
     });
 }
开发者ID:xueron,项目名称:pails,代码行数:19,代码来源:View.php

示例13: registerServices

 /**
  * Registers an autoloader related to the module
  *
  * @param \Phalcon\DiInterface $dependencyInjector
  */
 public function registerServices(\Phalcon\DiInterface $dependencyInjector)
 {
     $config = $this->config;
     /**
      * Setting up the view component
      */
     $dependencyInjector['view'] = function () use($config) {
         $view = new View();
         $viewDir = $this::DIR . '/views/';
         if ($config->offsetExists('application') && $config->application->offsetExists('viewsDir') && $config->application->offsetExists('viewsDir')) {
             $viewDir = $config->application->viewsDir;
         }
         $view->setViewsDir($viewDir);
         $cacheDir = $this::DIR . '/cache/';
         if ($config->offsetExists('application') && $config->application->offsetExists('cacheDir') && $config->application->offsetExists('cacheDir')) {
             $cacheDir = $config->application->cacheDir;
         }
         $view->registerEngines(array('.volt' => function ($view, $di) use($config, $cacheDir) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(['compiledPath' => $cacheDir, 'compiledExtension' => ".compiled", 'compiledSeparator' => '_', 'compileAlways' => APP_ENV == 'product' ? false : true]);
             $compiler = $volt->getCompiler();
             $compiler->addExtension(new \PhalconPlus\Volt\Extension\PhpFunction());
             $funcList = $this->getVoltCompileFunction($di);
             foreach ($funcList as $k => $v) {
                 $compiler->addFunction($k, $v);
             }
             $filterList = $this->getVoltCompileFilter($di);
             foreach ($filterList as $k => $v) {
                 $compiler->addFilter($k, $v);
             }
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     };
     if ($config->offsetExists('application') && $config->application->offsetExists('baseUri')) {
         $dependencyInjector['url'] = function () use($config) {
             $url = new \Phalcon\Mvc\Url();
             $url->setBaseUri($config->application->baseUri);
             return $url;
         };
     }
     $dependencyInjector['moduleConfig'] = function () use($config) {
         return $config;
     };
 }
开发者ID:fu-tao,项目名称:meelier_c,代码行数:50,代码来源:BaseModule.php

示例14: initialize

 /**
  * @param \Phalcon\DiInterface $di
  * @return mixed
  */
 public function initialize(\Phalcon\DiInterface $di)
 {
     /** @var \Phalcon\Config $config */
     $config = $di->get('config');
     $viewConfig = isset($config->application->view) ? $config->application->view->toArray() : [];
     if ($di->has('view')) {
         /** @var \Phalcon\Mvc\View $view */
         $view = $di->get('view');
         $viewEngines = $view->getRegisteredEngines();
         if (!$viewEngines) {
             $viewEngines = [];
         }
         $viewEngines['.volt'] = function ($this, $di) use($viewConfig) {
             $volt = new VoltEngine($this, $di);
             $volt->setOptions($viewConfig);
             $volt->getCompiler()->addFilter('toString', (new ToStringFilter())->getFilter());
             return $volt;
         };
         $view->registerEngines($viewEngines);
     }
 }
开发者ID:vegas-cmf,项目名称:mvc,代码行数:25,代码来源:Volt.php

示例15: register

 public function register()
 {
     $view = new PhalconView();
     $view->setViewsDir(config()->path->views);
     $view->registerEngines(['.volt' => function ($view, $di) {
         $volt = new PhalconVoltEngine($view, $di);
         $volt->setOptions(['compiledPath' => config()->path->storage_views, 'compiledSeparator' => '_']);
         $compiler = $volt->getCompiler();
         # others
         $compiler->addFunction('di', 'di');
         $compiler->addFunction('env', 'env');
         $compiler->addFunction('echo_pre', 'echo_pre');
         $compiler->addFunction('csrf_field', 'csrf_field');
         $compiler->addFunction('dd', 'dd');
         $compiler->addFunction('config', 'config');
         # facade
         $compiler->addFunction('security', 'security');
         $compiler->addFunction('tag', 'tag');
         $compiler->addFunction('route', 'route');
         $compiler->addFunction('response', 'response');
         $compiler->addFunction('view', 'view');
         $compiler->addFunction('config', 'config');
         $compiler->addFunction('url', 'url');
         $compiler->addFunction('request', 'request');
         # paths
         $compiler->addFunction('base_uri', 'base_uri');
         return $volt;
     }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php', '.blade.php' => 'Bootstrap\\Adapters\\Blade\\BladeAdapter']);
     # ---- instatiate a new event manager
     $event_manager = new EventsManager();
     # ---- after rendering the view
     # by default, we should destroy the flash
     $event_manager->attach("view:afterRender", function ($event, $dispatcher, $exception) {
         # - this should destroy the flash
         $flash = $dispatcher->getDI()->get('flash');
         $flash->destroy();
     });
     $view->setEventsManager($event_manager);
     return $view;
 }
开发者ID:philippgerard,项目名称:slayer,代码行数:40,代码来源:View.php


注:本文中的Phalcon\Mvc\View\Engine\Volt::getCompiler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。