本文整理汇总了PHP中Phalcon\DiInterface::getShared方法的典型用法代码示例。如果您正苦于以下问题:PHP DiInterface::getShared方法的具体用法?PHP DiInterface::getShared怎么用?PHP DiInterface::getShared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\DiInterface
的用法示例。
在下文中一共展示了DiInterface::getShared方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerServices
/**
* 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);
}
示例2: registerServices
/**
* Registers the module-only services
*
* @param \Phalcon\DiInterface $di
*/
public function registerServices($di)
{
/**
* Read application wide and module only configurations
*/
$appConfig = $di->get('config');
$moduleConfig = (include __DIR__ . '/config/config.php');
$di->set('moduleConfig', $moduleConfig);
/**
* The URL component is used to generate all kind of urls in the application
*/
$di->set('url', function () use($appConfig) {
$url = new UrlResolver();
$url->setBaseUri($appConfig->application->baseUri);
return $url;
});
/**
* Module specific dispatcher
*/
$di->set('dispatcher', function () use($di) {
$dispatcher = new Dispatcher();
$dispatcher->setEventsManager($di->getShared('eventsManager'));
$dispatcher->setDefaultNamespace('App\\Modules\\Oauth\\');
return $dispatcher;
});
/**
* Module specific database connection
*/
$di->set('db', function () use($appConfig) {
return new DbAdapter(['host' => $moduleConfig->database->host, 'username' => $moduleConfig->database->username, 'password' => $moduleConfig->database->password, 'dbname' => $moduleConfig->database->name]);
});
}
示例3: registerServices
/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* Read common configuration
*/
$config = $di->has('config') ? $di->getShared('config') : null;
/**
* Try to load local configuration
*/
if (file_exists(__DIR__ . '/config/config.php')) {
$override = new Config(include __DIR__ . '/config/config.php');
if ($config instanceof Config) {
$config->merge($override);
} else {
$config = $override;
}
}
/**
* Setting up the view component
*/
$view = $di->get('view');
$view->setViewsDir($config->get('application')->viewsDir);
$di->set('view', $view);
// add default namespace
$dispatcher = $di->get('dispatcher');
$dispatcher->setDefaultNamespace("Application\\Frontend\\Controllers");
$di->set('dispatcher', $dispatcher);
}
示例4: registerServices
/**
* 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);
}
示例5: initLoader
/**
* Initialize the Loader.
*
* Adds all required namespaces.
*/
protected function initLoader()
{
$config = $this->di->getShared('config');
$loader = new Loader();
$loader->registerNamespaces(['Phosphorum\\Models' => $config->get('application')->modelsDir, 'Phosphorum\\Controllers' => $config->get('application')->controllersDir, 'Phosphorum' => $config->get('application')->libraryDir]);
$loader->register();
$this->di->setShared('loader', $loader);
}
示例6: registerAutoloaders
public function registerAutoloaders(DiInterface $di = null)
{
$path = $di->getShared('config')->modules->poll->path;
$path = str_replace('Module.php', '', $path);
$loader = new Loader();
$loader->registerNamespaces(array('Socialveo\\Poll\\Models' => $path . 'models/', 'Socialveo\\Poll\\Controllers' => $path . 'controllers/', 'Socialveo\\Poll\\Plugins' => $path . 'plugins/'));
$loader->register();
}
示例7: register
/**
* {@inheritdoc}
*/
public function register(DiInterface $di)
{
$di->set(self::SERVICE_NAME, function () use($di) {
$arrayConfig = (array) $di->get('config')->{self::SERVICE_NAME};
$db = new \Phalcon\Db\Adapter\Pdo\Sqlite($arrayConfig);
$db->setEventsManager($di->getShared('eventsManager'));
return $db;
}, true);
}
示例8: getSessionToken
/**
* Returns the value of the CSRF token in session
*
* @return string
* @throws FlashException
*/
public function getSessionToken()
{
if (is_object($this->_dependencyInjector) === false) {
throw new FlashException('A dependency injection container is required to access the \'session\' service');
}
$session = $this->_dependencyInjector->getShared('session');
if (is_object($session) === false || $session instanceof SessionAdapterInterface === false) {
throw new FlashException('Session service is unavailable.');
}
return $session->get('$PHALCON/CSRF$');
}
示例9: delete
/**
* Deletes the cookie by setting an expire time in the past
*
* @throws Exception
*/
public function delete()
{
if (is_object($this->_dependencyInjector) === true) {
$session = $this->_dependencyInjector->getShared('session');
if ($session instanceof SessionInterface === false) {
throw new Exception('Wrong session service.');
}
$session->remove('_PHCOOKIE_' . $this->_name);
}
$this->_value = null;
//@note use the type 'boolean' for the last two parameters
setcookie((string) $this->_name, null, time() - 691200, (string) $this->_path, (string) $this->_domain, (bool) $this->_secure, (bool) $this->_httpOnly);
}
示例10: createFrom
/**
* @param array $config
* @param DiInterface $di
* @return MvcView
*/
public static function createFrom(array $config, DiInterface $di) : MvcView
{
$view = new MvcView();
if (isset($config['templatePath'])) {
$view->setViewsDir($config['templatePath']);
/** @var MvcDispatcher $dispatcher */
$dispatcher = $di->getShared('dispatcher');
$dispatcher->getEventsManager()->attach('dispatch', new self());
} else {
$view->disable();
}
return $view;
}
示例11: initDispatcher
/**
* Registers default dispatcher
*/
public function initDispatcher()
{
$this->di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
/**
* @var \Phalcon\Events\Manager $eventsManager
*/
$eventsManager = $this->di->getShared('eventsManager');
$eventsManager->attach('dispatch:beforeException', (new ExceptionListener())->beforeException());
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
}
示例12: registerServices
/**
* Register the services here to make them general or register in the ModuleDefinition to make them module-specific
*/
public function registerServices(DiInterface $di)
{
//Registering a dispatcher
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace(__NAMESPACE__ . '\\Controllers\\');
return $dispatcher;
});
//Registering the view component
$view = $di->getShared('view');
$view->setViewsDir(APP_PATH . '/modules/' . __NAMESPACE__ . '/view');
$view->setLayoutsDir('layout/');
$view->setTemplateAfter('main');
$view->setVar('menu', new MenuHelper($di));
}
示例13: _setSessionMessages
/**
* Stores the messages in session
*
* @param array $messages
* @throws Exception
* @return array
*/
protected function _setSessionMessages($messages)
{
if (is_array($messages) === false) {
throw new Exception('Invalid parameter type.');
}
if (is_object($this->_dependencyInjector) === false) {
throw new Exception('A dependency injection container is required to access the \'session\' service');
}
$session = $this->_dependencyInjector->getShared('session');
if (is_object($session) === false || $session instanceof SessionAdapterInterface === false) {
throw new Exception('Session service is unavailable.');
}
$session->set('_flashMessages', $messages);
return $messages;
}
示例14: registerServices
/**
* Registers services related to the module
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
/**
* Read common configuration
*/
$config = $di->has('config') ? $di->getShared('config') : null;
/**
* Try to load local configuration
*/
if (file_exists(__DIR__ . '/config/config.php')) {
$override = new Config(include __DIR__ . '/config/config.php');
if ($config instanceof Config) {
$config->merge($override);
} else {
$config = $override;
}
}
/**
* Setting up the view component
*/
$view = $di->get('view');
$view->setViewsDir($config->get('application')->viewsDir);
$di->set('view', $view);
// register helper
$di->setShared('adminHelper', function () {
return new \Application\Admin\Librarys\voltHelper();
});
/**
* 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);
};
// add default namespace
$dispatcher = $di->get('dispatcher');
$dispatcher->setDefaultNamespace("Application\\Admin\\Controllers");
$di->set('dispatcher', $dispatcher);
// register menu
$di->set('AdminMenus', function () {
return require __DIR__ . '/config/menus.php';
});
}
示例15: getToken
/**
* Generates a pseudo random token value to be used as input's value in a CSRF check
*
* @param int|null $numberBytes
* @return string
* @throws Exception
*/
public function getToken($numberBytes = null)
{
if (is_null($numberBytes)) {
$numberBytes = 12;
} elseif (!is_int($numberBytes)) {
throw new Exception('Invalid parameter type.');
}
if (!function_exists('openssl_random_pseudo_bytes')) {
throw new SecException('Openssl extension must be loaded');
}
$token = self::filterAlnum(base64_encode(openssl_random_pseudo_bytes($numberBytes)));
if (!is_object($this->_dependencyInjector)) {
throw new Exception('A dependency injection container is required to access the \'session\' service');
}
$session = $this->_dependencyInjector->getShared('session');
$session->set($this->_tokenValueSessionID, $token);
return $token;
}