作者:denners77
项目:api-phalco
/**
* Register specific services for the module
* @param \Phalcon\DiInterface $di
*/
public function registerServices(DiInterface $di)
{
$config = $this->_config;
//Registering a dispatcher
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Imports');
return $dispatcher;
});
//Registering the view component
$vDI = $di;
$di->set('volt', function ($view, $vDI) use($config) {
$volt = new Volt($view, $vDI);
$volt->setOptions(array('compiledPath' => APP_PATH . $config->volt->path, 'compiledExtension' => $config->volt->extension, 'compiledSeparator' => $config->volt->separator, 'stat' => (bool) $config->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(APP_PATH . $config->application->viewsDir);
$view->registerEngines(array('.volt' => 'volt'));
return $view;
});
return $di;
}
作者:phil-schreibe
项目:messewebsit
/**
* 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);
}
作者:maniole
项目:vegase
/**
* {@inheritdoc}
* @see http://docs.phalconphp.com/pl/latest/reference/odm.html
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function () use($di) {
$mongoConfig = $di->get('config')->mongo->toArray();
if (isset($mongoConfig['dsn'])) {
$hostname = $mongoConfig['dsn'];
unset($mongoConfig['dsn']);
} else {
//obtains hostname
if (isset($mongoConfig['host'])) {
$hostname = 'mongodb://' . $mongoConfig['host'];
} else {
$hostname = 'mongodb://localhost';
}
if (isset($mongoConfig['port'])) {
$hostname .= ':' . $mongoConfig['port'];
}
//removes options that are not allowed in MongoClient constructor
unset($mongoConfig['host']);
unset($mongoConfig['port']);
}
$dbName = $mongoConfig['dbname'];
unset($mongoConfig['dbname']);
$mongo = new \MongoClient($hostname, $mongoConfig);
return $mongo->selectDb($dbName);
}, true);
}
作者:logikostec
项目:cor
public static function defineRoutes(DiInterface $di)
{
/* @var $router \Phalcon\Mvc\Router */
$router = $di->get('router');
$default = $router->getDefaults()['module'];
$router->add("/customroute/foo/:params", array('module' => self::$modname, 'controller' => 'index', 'action' => 'foo', 'params' => 1))->setName(self::$modname . '_foo');
}
作者:nicklos1
项目:littlemal
/**
* 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 () {
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
return $view;
};
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di['db'] = function () use($config) {
return new Mysql(array("host" => $config->database->host, "username" => $config->database->username, "password" => $config->database->password, "dbname" => $config->database->dbname, "options" => array(\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'", \PDO::ATTR_CASE => \PDO::CASE_LOWER, \PDO::ATTR_EMULATE_PREPARES => false)));
};
$di->set('dispatcher', function () {
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->setDefaultNamespace("Mall\\Admin\\Controllers");
return $dispatcher;
});
$di->set('cookies', function () {
$cookies = new \Phalcon\Http\Response\Cookies();
$cookies->useEncryption(false);
return $cookies;
});
}
作者: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";
}
作者:vegas-cm
项目:profile
/**
* {@inheritdoc}
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function () use($di) {
$session = new Vegas\Session($di->get('session'));
return $session;
}, true);
}
作者:sidrobert
项目:phalcon-applicatio
/**
* @param \Phalcon\DiInterface $di
*
* @return \Phalcon\Cli\Console
*/
protected function getConsole(\Phalcon\DiInterface $di)
{
if (!$di->has("console")) {
return $this->getDefaultConsole($di);
}
return $di->get("console");
}
作者:vegas-cm
项目:profile
/**
* {@inheritdoc}
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function () use($di) {
$mongo = new \MongoClient();
return $mongo->selectDb($di->get('config')->mongo->db);
}, true);
}
作者: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);
}
作者:sidrobert
项目:phalcon-applicatio
/**
* @param \Phalcon\DiInterface $di
*
* @return \Phalcon\Mvc\Application
*/
protected function getApplication(\Phalcon\DiInterface $di)
{
if (!$di->has("application")) {
return $this->getDefaultApplication($di);
}
return $di->get("application");
}
作者:logikostec
项目:cor
public function setDI(DiInterface $di)
{
$di->setShared('config', static::$config);
$this->initEventsManager($di);
parent::setDI($di);
Di::setDefault($di);
}
作者:cengizcosku
项目:phoneboo
/**
* Register specific services for the module
*
* @package base-app
* @version 2.0
*
* @param object $di dependency Injector
*
* @return void
*/
public function registerServices(\Phalcon\DiInterface $di)
{
//Registering a dispatcher
$di->set('dispatcher', function () {
//Create/Get an EventManager
$eventsManager = new \Phalcon\Events\Manager();
//Attach a listener
$eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
//controller or action doesn't exist
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array('controller' => 'index', 'action' => 'notFound'));
return false;
}
}
});
$dispatcher = new \Phalcon\Mvc\Dispatcher();
//Set default namespace to documentation module
$dispatcher->setDefaultNamespace("Baseapp\\Documentation\\Controllers");
//Bind the EventsManager to the dispatcher
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
//Registering the view component
$di->set('view', function () use($di) {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir(__DIR__ . '/views/');
$view->registerEngines(\Baseapp\Library\Tool::registerEngines($view, $di));
return $view;
});
}
作者: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'));
};
}
作者:noiki
项目:publi
/**
* 注册服务
* @param type $di
*/
public function registerServices(\Phalcon\DiInterface $di = NULL)
{
$config = \TConfig::instance()->getModule($this->moduleId);
if (php_sapi_name() == 'cli') {
//处理CLI模式
$di['dispatcher'] = function () use($config) {
$dispatcher = new \Phalcon\Cli\Dispatcher();
if (isset($config['defaultNamespace']) && isset($config['defaultNamespace']['task'])) {
$dispatcher->setDefaultNamespace($config['defaultNamespace']);
}
return $dispatcher;
};
} else {
//处理WEB模式
$di['dispatcher'] = function () use($config) {
$dispatcher = new \Phalcon\Mvc\Dispatcher();
if (isset($config['defaultNamespace']) && isset($config['defaultNamespace']['controller'])) {
$dispatcher->setDefaultNamespace($config['defaultNamespace']['controller']);
}
return $dispatcher;
};
//添加视图
$di->set('view', function () use($config) {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir($config['autoloadDir']['view']);
$view->registerEngines(array('.html' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
return $view;
});
}
}
作者:maniole
项目:vegase
/**
* {@inheritdoc}
* @see http://docs.phalconphp.com/en/latest/api/Phalcon_Db_Adapter_Pdo_Postgresql.html
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function () use($di) {
$config = $di->get('config');
return new Phalcon\Db\Adapter\Pdo\Postgresql(["host" => $config->db->host, "dbname" => $config->db->dbname, "port" => $config->db->port, "username" => $config->db->username, "password" => $config->db->password]);
}, true);
}
作者: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;
});
}
作者:vegas-cm
项目:ac
/**
* {@inheritdoc}
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function () use($di) {
$arrayConfig = $di->get('config')->db->toArray();
return new \Phalcon\Db\Adapter\Pdo\Mysql($arrayConfig);
}, true);
}
作者: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]);
});
}
作者:ylh99083577
项目:phalcon_ydj
/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* 获取全局配置
*/
$config = $di->has('config') ? $di->getShared('config') : null;
/**
* 各模块可自定义config文件并替换全局的config配置
*/
if (file_exists($this->modulePath . '/config/config.php')) {
$override = new Config(include $this->modulePath . '/config/config.php');
if ($config instanceof Config) {
$config->merge($override);
} else {
$config = $override;
}
}
//重置全局配置
$di->setShared('config', $config);
/**
* 设置各个模块的视图目录
*/
$view = new View();
//$view->setViewsDir($this->modulePath . '/views/default/');
$view->setViewsDir(FRONTEND_PUBLIC_PATH . 'views/default/');
$view->registerEngines(['.volt' => 'volt', '.php' => 'volt', '.html' => 'volt']);
$di->set('view', $view);
}