作者:EdgarSM9
项目:phalcon-angula
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'));
};
}
作者:denners77
项目:api-phalco
/**
* 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;
}
作者:aodkrisd
项目:album-o-ram
/**
* 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]);
});
}
作者:drivesoft
项目:phalcon2-app-module
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;
});
}
作者:denners77
项目:phalcon_ecommerc
/**
* 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";
}
作者:lnmtie
项目:phalcon-bas
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;
});
}
作者:adrianeava
项目:manager.i
/**
* 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);
}
}
作者:corzoi
项目:phalcon-boilerplat
/**
* 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;
});
}
作者:phalconey
项目:framewor
/**
* 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;
}
作者:cscl
项目:niure
/**
* 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;
}
作者:justforle
项目:phalcon-cm
/**
* 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);
}
作者:nguyenducdu
项目:phblo
/**
* 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;
}
作者:kachi
项目:phalcon-li
/**
* 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;
});
}
作者:arius8
项目:cor
/**
* 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'));
}
作者:kengo
项目:phalconCar
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;
}
作者:broklyngaga
项目:orbi
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;
}
作者:adrianeava
项目:manager.i
/**
* 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;
});
}
作者:vietdh8
项目:product-v
/**
* 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;
});
}
作者:halfbakedsnee
项目:phalcor
/**
* 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;
});
}
作者:tashi
项目:phalcon_cor
/**
* 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;
});
}