Beispiel #1
0
 /**
  * @return Volt
  */
 protected function registerEngine()
 {
     $config = $this->getConfig();
     $this->volt = new PhalconVolt($this->view, $this->dependencyInjection);
     if (!is_dir($config->view->compiledPath)) {
         mkdir($config->view->compiledPath, 0777, true);
     }
     $this->volt->setOptions(['compiledPath' => $config->view->compiledPath, 'compiledSeparator' => $config->view->compiledSeparator, 'compiledExtension' => $config->view->compiledExtension, 'compileAlways' => $config->view->compileAlways, 'stat' => $config->view->stat]);
     $this->createVoltFunctions();
     $this->createVoltFilters();
     $this->createVoltVars();
     $this->view->registerEngines([".volt" => $this->volt]);
 }
Beispiel #2
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]);
     });
 }
Beispiel #3
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);
 }
 /**
  * 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";
 }
Beispiel #5
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;
 }
Beispiel #6
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;
 }
Beispiel #7
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;
     });
 }
Beispiel #8
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;
 }
Beispiel #9
0
 /**
  * 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);
 }
Beispiel #10
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;
 }
 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;
     });
 }
Beispiel #12
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'));
     };
 }
Beispiel #13
0
 /**
  * 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;
     });
 }
Beispiel #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;
     });
 }
 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;
 }
Beispiel #16
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'));
 }
Beispiel #17
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;
     });
 }
 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;
 }
Beispiel #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;
     });
 }
Beispiel #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;
     });
 }
Beispiel #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;
     });
 }
Beispiel #22
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;
     });
 }
Beispiel #23
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;
     };
 }
Beispiel #24
0
 /**
  * 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;
     });
 }
Beispiel #25
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;
 }
Beispiel #26
0
 /**
  * @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);
     }
 }
Beispiel #27
0
 /**
  * Registers the module-only services
  *
  * @param Phalcon\DI $di
  */
 public function registerServices(\Phalcon\DiInterface $di = null)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/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 View\Engine\Volt($view, $di);
             $volt->setOptions(array('compiledPath' => $config->application->cacheDir, 'compiledSeparator' => '_'));
             $compiler = $volt->getCompiler();
             //Set Function PHP
             $compiler->addFunction('md5', 'md5');
             $compiler->addFunction('base64_encode', 'base64_encode');
             $compiler->addFunction('current', 'current');
             $compiler->addFunction('count', 'count');
             $compiler->addFunction('unserialize', 'unserialize');
             $compiler->addFunction('print_r', 'print_r');
             $compiler->addFunction('var_dump', 'var_dump');
             $compiler->addFunction('number_format', 'number_format');
             $compiler->addFunction('json_decode', 'json_decode');
             $compiler->addFunction('in_array', 'in_array');
             $compiler->addFunction('get_object_vars', 'get_object_vars');
             $compiler->addFunction('strpos', 'strpos');
             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" => $config->database->charset));
     };
 }
Beispiel #28
0
 /**
  * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
  */
 public function registerServices(\Phalcon\DiInterface $di)
 {
     /**
      * Read configuration
      */
     $config = (include __DIR__ . "/config/config.php");
     /**
      * Setting up the view component
      */
     // The URL component is used to generate all kind of urls in the application
     $di->set('url', function () {
         $url = new Url();
         $url->setBaseUri('/');
         return $url;
     });
     /**
      * Setting up the view component
      */
     $di->set('view', function () use($config) {
         $view = new View();
         $view->setViewsDir($config->application->view->viewsDir);
         $view->disableLevel([View::LEVEL_MAIN_LAYOUT => true, View::LEVEL_LAYOUT => true]);
         $view->registerEngines(['.volt' => function () use($view, $config) {
             $volt = new Volt($view);
             $volt->setOptions(['compiledPath' => $config->application->view->compiledPath, 'compiledSeparator' => $config->application->view->compiledSeparator, 'compiledExtension' => $config->application->view->compiledExtension, 'compileAlways' => true]);
             return $volt;
         }]);
         // Create an event manager
         $eventsManager = new EventsManager();
         // Attach a listener for type 'view'
         $eventsManager->attach('view', function ($event, $view) {
             if ($event->getType() == 'notFoundView') {
                 throw new \Exception('View not found!!! (' . $view->getActiveRenderPath() . ')');
             }
         });
         // Bind the eventsManager to the view component
         $view->setEventsManager($eventsManager);
         return $view;
     });
 }
Beispiel #29
0
 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;
 }
Beispiel #30
0
 /**
  * Generate a new View object with preset parameters.
  *
  * @param array $options
  * @param \Phalcon\DiInterface $di
  * @return \Phalcon\Mvc\View
  */
 public static function getView($options = array(), \Phalcon\DiInterface $di = null)
 {
     if ($di == null) {
         $di = \Phalcon\Di::getDefault();
     }
     $defaults = array('base_dir' => FA_INCLUDE_BASE . '/', 'views_dir' => 'modules/frontend/views/scripts/', 'partials_dir' => '', 'layouts_dir' => '../../../../templates/', 'layout' => 'main');
     $options = array_merge($defaults, (array) $options);
     // Temporary fix to force "views_dir" to be the full path, because "base_dir" is not used in some Phalcon calculations.
     $options['views_dir'] = $options['base_dir'] . $options['views_dir'];
     $options['base_dir'] = '';
     $view = new \Phalcon\Mvc\View();
     $view->setDI($di);
     $eventsManager = new \Phalcon\Events\Manager();
     $view->setEventsManager($eventsManager);
     // Base directory from which all views load.
     $view->setBasePath($options['base_dir']);
     $view->setViewsDir($options['views_dir']);
     // Relative path of main templates.
     $view->setLayoutsDir($options['layouts_dir']);
     $view->setTemplateAfter($options['layout']);
     // Use present directory for partials by default.
     $view->setPartialsDir($options['partials_dir']);
     // Register template engines.
     $view->registerEngines(array(".phtml" => 'Phalcon\\Mvc\\View\\Engine\\Php', ".volt" => function ($view, $di) {
         $volt = new Volt($view, $di);
         $volt->setOptions(array('compileAlways' => FA_APPLICATION_ENV == 'development', 'compiledPath' => function ($templatePath) {
             // Clean up the template path and remove non-application folders from path.
             $templatePath = realpath($templatePath);
             $templatePath = ltrim(str_replace(FA_INCLUDE_BASE, '', $templatePath), '/');
             $find_replace = array('/views/scripts/' => '_', '../' => '', '/' => '_', '.volt' => '');
             $templatePath = str_replace(array_keys($find_replace), array_values($find_replace), $templatePath);
             return FA_INCLUDE_CACHE . '/volt_' . $templatePath . '.compiled.php';
         }));
         $compiler = $volt->getCompiler();
         $compiler->addExtension(new \FA\Phalcon\Service\ViewHelper());
         return $volt;
     }));
     return $view;
 }