Exemple #1
0
 public function registerServices(\Phalcon\DiInterface $di = null)
 {
     /**
      * Read configuration
      */
     $config = (include dirname(dirname(dirname(__DIR__))) . "/apps/config/config.php");
     $di->set('dispatcher', function () use($di) {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers');
         return $dispatcher;
     }, true);
     $di->set('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' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             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) {
         return new DbAdapter(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, 'charset' => 'utf8'));
     };
 }
Exemple #2
0
 /**
  * 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;
 }
Exemple #3
0
 /**
  * Registers services related to the module
  *
  * @param DiInterface $di Dependency Injection Container
  */
 public function registerServices(DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (require __DIR__ . "/config/config.php");
     /**
      * Setting up the view component
      */
     $di->setShared('view', function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setTemplateBefore('main');
         $view->registerEngines([".volt" => function ($view, $di) {
             $volt = new Volt($view, $di);
             $volt->setOptions(['compiledPath' => function ($templatePath) {
                 return realpath(__DIR__ . "/../../var/volt") . '/' . md5($templatePath) . '.php';
             }, 'compiledExtension' => '.php', 'compiledSeparator' => '%']);
             return $volt;
         }]);
         return $view;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di->setShared('db', function () use($config) {
         return new Connection(['host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname]);
     });
 }
 private function setView($manager, $theme)
 {
     /* ==================================================
      * ตั้งค่าเรียกใช้งานไฟล์ View ทั้งหมด
      * Setting up the view component
      * ================================================== */
     $manager->set('view', function () use($theme) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         /* ตำแหน่งเก็บไฟล์ views ทั้งหมด */
         $view->setLayoutsDir(sprintf('%s/%s/', $this->config->theme->themesDir, $theme));
         /* ตำแหน่งเก็บไฟล์ layouts ทั้งหมด */
         $view->setTemplateAfter('layouts/' . $this->layoutName);
         /* เลือกไฟล์ layout เริ่มต้น*/
         /* สร้างโฟล์เดอร์เก็บไฟล์ cache */
         $cacheDir = sprintf('%s/%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir, $this->moduleName);
         if (!is_dir($cacheDir)) {
             mkdir($cacheDir);
         }
         $view->registerEngines(array('.phtml' => function ($view, $di) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => sprintf('%s/%s/%s/', APPLICATION_PATH, $this->config->application->cacheDir, $this->moduleName), 'compiledSeparator' => '_'));
             return $volt;
         }));
         return $view;
     });
 }
 /**
  * Register specific services for the module
  */
 public function registerServices(DiInterface $di)
 {
     // Assign our new tag a definition so we can call it
     $di->set('Utilitarios', function () {
         return new \Ecommerce\Admin\Helpers\UtilitariosHelper();
     });
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Ecommerce\\Admin\\Controllers');
         return $dispatcher;
     });
     // Registering the view component
     $di->set('view', function () {
         $config = (include __DIR__ . "/config/config.php");
         $view = new View();
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         $view->setViewsDir('../apps/admin/views/');
         return $view;
     });
     include "../apps/admin/vendor/autoload.php";
 }
Exemple #6
0
 public function registerServices(DiInterface $di)
 {
     global $config;
     $di->setShared('url', function () use($config) {
         $url = new UrlResolver();
         $url->setBaseUri($config->backend->baseUri);
         return $url;
     });
     $di->setShared('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Multiple\\Backend\\Controllers");
         return $dispatcher;
     });
     $di->setShared('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->backend->viewsDir);
         $view->setLayoutsDir('layouts/');
         $view->setPartialsDir('partials/');
         $view->registerEngines(array('.phtml' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->backend->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.volt' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     });
 }
 /**
  * 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);
     }
 }
 /**
  * Register specific services for the module
  */
 public function registerServices(DiInterface $di)
 {
     $config = $di->get('config');
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace("Promoziti\\Modules\\Business\\Controllers");
         return $dispatcher;
     });
     $di->set('view', function () {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(array('.volt' => function ($view, $di) {
             $volt = new VoltEngine($view, $di);
             $config = $di->get('config');
             $volt->setOptions(array('compileAlways' => true, 'compiledPath' => $config->application->cache_dir . "volt/", 'compiledSeparator' => '_'));
             return $volt;
         }));
         return $view;
     });
     $di->set('aws_s3', function () use($config) {
         //version 2.7 style
         $s3 = \Aws\S3\S3Client::factory(array('key' => $config->application->security->aws->key, 'secret' => $config->application->security->aws->secret, 'region' => 'us-west-2', 'version' => '2006-03-01'));
         return $s3;
     });
 }
Exemple #9
0
 /**
  * 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;
 }
Exemple #10
0
 /**
  * Registers services related to the module
  *
  * @param DiInterface $di
  */
 public function registerServices(DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (include APP_PATH . "/apps/frontend/config/config.php");
     /**
      * Setting up the view component
      */
     $di['view'] = function () use($config) {
         $view = new View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(array('.html' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }));
         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);
     };
     $di['wechat'] = 'App\\Libs\\Wechat';
     $di['config'] = $config;
 }
Exemple #11
0
 /**
  * Register specific services for the module
  */
 function registerServices(\Phalcon\DiInterface $di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Modules\\Frontend\\Controllers');
         return $dispatcher;
     });
     $config = $di->getShared('config');
     $di->set('view', function () use($config, $di) {
         $view = new View();
         $router = $di->getShared('router');
         /*
          * @todo 给layouts等目录统一变量
          * */
         $view->setViewsDir(__DIR__ . '/views/');
         $view->setLayoutsDir('/../../../layouts/');
         // 多模块的话, 可能会有多个风格,所以需要切换layout,这里的Path是根据当前module的Path向上走的
         $view->setLayout('index');
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         return $view;
     }, true);
 }
Exemple #12
0
 /**
  * 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;
 }
 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();';
     });
 }
Exemple #14
0
 /**
  * Register services
  */
 public function register()
 {
     $this->container->set('volt', function ($view, $di) {
         $volt = new VoltEngine($view, $di);
         $volt->setOptions($this->config->volt->toArray());
         return $volt;
     });
 }
Exemple #15
0
 /**
  * Constructor
  * Initializes simple view
  *
  * @param null $options
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     $this->registerEngines(array('.volt' => function ($this, $di) use($options) {
         $volt = new PhalconView\Engine\Volt($this, $di);
         $volt->setOptions(array('compiledPath' => $options['cacheDir'], 'compiledSeparator' => '_'));
         return $volt;
     }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
 }
 public function attachVoltService($voltCacheDir)
 {
     $this->_di->set('voltService', function ($view, $di) use($voltCacheDir) {
         $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
         $volt->setOptions(['compiledPath' => $voltCacheDir, 'compiledSeparator' => '_', 'compiledExtension' => '.compiled']);
         return $volt;
     });
     return $this;
 }
 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;
 }
Exemple #18
0
 /**
  * Register services used by the backend application
  *
  * @param $di
  */
 public function registerServices($di)
 {
     $config = $this->config();
     /**
      * register the dispatcher
      */
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         /*$eventManager = new Manager();
                     $eventManager->attach('dispatch', new \Acl('backend'));
         
                     $dispatcher->setEventsManager($eventManager);*/
         $dispatcher->setDefaultNamespace('app\\backend\\controllers');
         return $dispatcher;
     });
     /**
      * The URL component is used to generate all kind of urls in the application
      */
     $di->set('url', function () use($config) {
         $url = new UrlResolver();
         $url->setBaseUri($config->application->baseUri);
         return $url;
     }, true);
     $di->setShared('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->application->viewsDir);
         $view->registerEngines(['.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(['compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_']);
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']);
         return $view;
     });
     /**
      * Database connection is created based in the parameters defined in the configuration file
      */
     $di->set('db', function () use($config) {
         return new MysqlAdapter($config->database->toArray());
     });
     /**
      * If the configuration specify the use of metadata adapter use it or use memory otherwise
      */
     $di->set('modelsMetadata', function () {
         return new MetaDataAdapter();
     });
     /**
      * Start the session the first time some component request the session service
      */
     $di->setShared('session', function () {
         $session = new SessionAdapter();
         $session->start();
         return $session;
     });
 }
Exemple #19
0
 /**
  * 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;
     });
 }
Exemple #20
0
 /**
  * Registers the View component in the DI container.
  * 
  * @return void
  */
 public function register()
 {
     $this->di->setShared('view', function () {
         $config = $this->di->get('config');
         $view = new PhalconView();
         $view->setViewsDir($config->paths->views);
         $view->registerEngines(['.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(['compiledPath' => dirPath($config->paths->cache), 'compiledSeparator' => '_', 'compileAlways' => $config->debug]);
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php']);
         return $view;
     });
 }
Exemple #21
0
 /**
  * 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;
     });
 }
Exemple #22
0
 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;
 }
Exemple #23
0
 public function partial($partialPath, $params = array(), $track = false)
 {
     if ($track) {
         UrlTrack::$ns_campaign = UrlTrack::get_conf()->{str_replace("/", ".", $partialPath)};
     }
     parent::partial($partialPath, $params);
 }
Exemple #24
0
 /**
  * @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;
     });
 }
Exemple #25
0
 /**
  * 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;
     };
 }
Exemple #26
0
 public function getCompiler()
 {
     if (empty($this->_compiler)) {
         parent::getCompiler();
         // add macros that need initialized before parse time
         $this->partial("macros/url");
     }
     return parent::getCompiler();
 }
Exemple #27
0
 public function __construct(\Phalcon\Mvc\ViewBaseInterface $view, \Phalcon\DiInterface $di)
 {
     parent::__construct($view, $di);
     require CORE_PATH . 'config/volt.functions.php';
     foreach ($voltFunctions as $macro => $function) {
         $this->getCompiler()->addFunction($macro, $function);
     }
     $this->getCompiler()->setOptions(array('stat' => true, 'compileAlways' => true));
 }
 /**
  * Register specific services for the module
  */
 public function registerServices(DiInterface $di)
 {
     $di->set('dispatcher', function () {
         $dispatcher = new Dispatcher();
         $dispatcher->setDefaultNamespace('Ecommerce\\Loja\\Controllers');
         return $dispatcher;
     });
     // Registering the view component
     $di->set('view', function () {
         $config = (include __DIR__ . "/config/config.php");
         $view = new View();
         $view->registerEngines(array('.volt' => function ($view, $di) use($config) {
             $volt = new VoltEngine($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             return $volt;
         }, '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
         $view->setViewsDir('../apps/loja/views/');
         return $view;
     });
 }
Exemple #29
0
 /**
  * Init view (Phalcon Volt Template)
  *
  * @return View
  */
 private function _initView()
 {
     $view = new View();
     $view->setDI(Di::getDefault());
     $view->registerEngines(['.volt' => function ($view, $di) {
         $volt = new VoltEngine($view, $di);
         $volt->setOptions(['compiledPath' => function ($templatePath) {
             $templatePath = strstr($templatePath, '/app');
             $dirName = dirname($templatePath);
             if (!is_dir(ROOT_PATH . '/cache/volt' . $dirName)) {
                 mkdir(ROOT_PATH . '/cache/volt' . $dirName, 0755, true);
             }
             return ROOT_PATH . '/cache/volt' . $dirName . '/' . basename($templatePath, '.volt') . '.php';
         }, 'compiledSeparator' => '_', 'compileAlways' => true, 'stat' => false]);
         $compiler = $volt->getCompiler();
         $compiler->addFunction('__', '__');
         return $volt;
     }]);
     return $view;
 }
 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices(\Phalcon\DiInterface $di = NULL)
 {
     /**
      * Read configuration
      */
     /**
      * Setting up the view component
      */
     $config = $this->config;
     $di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->application->frontendViewsDir);
         $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 "reportingtool\\Modules\\Modules\\Frontend\\Controllers\\ControllerBase::translate({$key})";
         });
         $volt->getCompiler()->addFunction('roundTwo', function ($resolvedArgs, $exprArgs) {
             return 'reportingtool\\Helper\\Tag::roundTwo(' . $resolvedArgs . ')';
         });
         $volt->getCompiler()->addFunction('arrayKeyExists', function ($resolvedArgs, $exprArgs) {
             return 'reportingtool\\Helper\\Tag::arrayKeyExists(' . $resolvedArgs . ')';
         });
         $volt->getCompiler()->addFunction('isset', 'isset');
         $volt->getCompiler()->addFunction('isempty', 'empty');
         $volt->getCompiler()->addFunction('number_format', function ($resolvedArgs) {
             return 'number_format(' . $resolvedArgs . ')';
         });
         $volt->getCompiler()->addFunction('linkAllowed', function ($args) {
             return "reportingtool\\Acl\\Acl::linkAllowed({$args})";
         });
         return $volt;
     }, true);
 }