本文整理汇总了PHP中Phalcon\Di::setShared方法的典型用法代码示例。如果您正苦于以下问题:PHP Di::setShared方法的具体用法?PHP Di::setShared怎么用?PHP Di::setShared使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Di
的用法示例。
在下文中一共展示了Di::setShared方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: attachResponseService
public function attachResponseService()
{
$this->_di->setShared('response', function () {
$response = new \Phalcon\Http\Response();
$response->setHeader('X-Frame-Options', 'SAMEORIGIN');
$response->setHeader('X-Content-Type-Options', 'nosniff');
$response->setHeader('X-XSS-Protection', '1; mode=block');
$response->setHeader('X-Download-Options', 'noopen');
return $response;
});
return $this;
}
示例2: getFlash
/**
* Return flash instance
*/
protected function getFlash()
{
$flash = new Session($this->classes);
$di = new Di();
$di->setShared('session', new PhalconMemorySession());
$di->setShared('escaper', new Escaper());
$flash->setDI($di);
return $flash;
}
示例3: _before
/**
* executed before each test
*/
protected function _before()
{
$this->previousDependencyInjector = Di::getDefault();
$di = new Di();
$di->setShared('modelsMetadata', new Metadata\Memory());
$di->setShared('modelsManager', new Manager());
$di->setShared('db', function () {
return new Mysql(['host' => TEST_DB_HOST, 'port' => TEST_DB_PORT, 'username' => TEST_DB_USER, 'password' => TEST_DB_PASSWD, 'dbname' => TEST_DB_NAME, 'charset' => TEST_DB_CHARSET]);
});
if ($this->previousDependencyInjector instanceof DiInterface) {
Di::setDefault($di);
}
}
示例4: _before
/**
* executed before each test
*/
protected function _before()
{
$this->previousDependencyInjector = Di::getDefault();
$di = new Di();
$di->setShared('modelsMetadata', new Memory());
$di->setShared('modelsManager', new Manager());
$di->setShared('db', function () {
return new Mysql(['host' => 'localhost', 'port' => '3306', 'username' => 'root', 'password' => '', 'dbname' => 'incubator_tests', 'charset' => 'utf8mb4']);
});
if ($this->previousDependencyInjector instanceof DiInterface) {
Di::setDefault($di);
}
}
示例5: register
public static function register(Di $di)
{
static::$di = $di;
static::$config = Config::get('auth');
$di->setShared('auth', function () {
$di = static::$di;
$config = static::$config;
$class = $config['adapter'];
$options = $config['options'];
strpos($class, '\\') === false and $class = 'Phwoolcon\\Auth\\Adapter\\' . $class;
if ($di->has($class)) {
$class = $di->getRaw($class);
}
if (!class_exists($class)) {
throw new Exception('Admin auth adapter class should implement ' . AdapterInterface::class);
}
/* @var Security $hasher */
$hasher = static::$di->getShared('security');
$hasher->setDefaultHash($options['security']['default_hash']);
$hasher->setWorkFactor($options['security']['work_factor']);
$adapter = new $class($options, $hasher, $di);
if (!$adapter instanceof AdapterInterface) {
throw new Exception('Auth adapter class should implement ' . AdapterInterface::class);
}
return $adapter;
});
static::addPhwoolconJsOptions();
}
示例6: register
public static function register(Di $di)
{
$environment = isset($_SERVER['PHWOOLCON_ENV']) ? $_SERVER['PHWOOLCON_ENV'] : 'production';
// @codeCoverageIgnoreStart
if (is_file($cacheFile = storagePath('cache/config-' . $environment . '.php'))) {
static::$config = (include $cacheFile);
Config::get('app.cache_config') or static::clearCache();
return;
}
// @codeCoverageIgnoreEnd
$defaultFiles = glob($_SERVER['PHWOOLCON_CONFIG_PATH'] . '/*.php');
$environmentFiles = glob($_SERVER['PHWOOLCON_CONFIG_PATH'] . '/' . $environment . '/*.php');
$config = new PhalconConfig(static::loadFiles($defaultFiles));
$environmentSettings = static::loadFiles($environmentFiles);
$environmentSettings['environment'] = $environment;
$environmentConfig = new PhalconConfig($environmentSettings);
$config->merge($environmentConfig);
$di->remove('config');
$di->setShared('config', $config);
static::$config = $config->toArray();
Config::get('database.default') and static::loadDb($config);
// @codeCoverageIgnoreStart
if (Config::get('app.cache_config')) {
is_dir($cacheDir = dirname($cacheFile)) or mkdir($cacheDir, 0777, true);
fileSaveArray($cacheFile, static::$config, function ($content) {
$replacement = <<<'EOF'
$_SERVER['PHWOOLCON_ROOT_PATH'] . '
EOF;
return str_replace("'{$_SERVER['PHWOOLCON_ROOT_PATH']}", $replacement, $content);
});
}
// @codeCoverageIgnoreEnd
}
示例7: register
public static function register(Di $di)
{
static::$di = $di;
$di->remove('payment');
static::$instance = null;
$di->setShared('payment', function () {
return new static(Config::get('payment'));
});
}
示例8: injectTo
public static function injectTo(Di $di)
{
$di->setShared('logger', function () use($di) {
$logger = new Multiple();
$config = $di->get('config')['loggers'];
foreach ($config as $logConfig) {
$adapter = $logConfig['adapter'];
$options = isset($logConfig['options']) ? $logConfig['options'] : null;
$logger->push(new $adapter($logConfig['name'], $options));
}
return $logger;
});
}
示例9: register
public static function register(Di $di)
{
static::$di = $di;
$di->remove('counter');
static::$adapter = null;
$di->setShared('counter', function () {
$default = Config::get('counter.default');
$config = Config::get('counter.drivers.' . $default);
$class = $config['adapter'];
$options = $config['options'];
strpos($class, '\\') === false and $class = 'Phwoolcon\\Util\\Counter\\' . $class;
return new $class($options);
});
}
示例10: register
public static function register(Di $di)
{
static::$hostname = gethostname();
$di->remove('log');
static::$logger = null;
$di->setShared('log', function () {
$filePath = storagePath('logs');
is_dir($filePath) or mkdir($filePath, 0777, true);
$filePath .= '/' . Config::get('app.log.file', 'phwoolcon.log');
$logger = new File($filePath);
$formatter = $logger->getFormatter();
if ($formatter instanceof Line) {
$formatter->setDateFormat('Y-m-d H:i:s');
$formatter->setFormat('[%date%]{host}[%type%] {request} %message%');
}
return $logger;
});
}
示例11: register
public static function register(Di $di)
{
static::$di = $di;
$di->remove('cache');
static::$cache = null;
$di->setShared('cache', function () {
$frontend = new Data(['lifetime' => static::TTL_ONE_DAY]);
$default = Config::get('cache.default');
$config = Config::get('cache.drivers.' . $default);
$class = $config['adapter'];
$options = $config['options'];
strpos($class, '\\') === false and $class = 'Phalcon\\Cache\\Backend\\' . $class;
isset($options['cacheDir']) and $options['cacheDir'] = storagePath($options['cacheDir']) . '/';
/* @var Backend $backend */
$backend = new $class($frontend, $options);
return $backend;
});
}
示例12: register
public static function register(Di $di)
{
static::$di = $di;
$di->setShared('i18n', function () {
return new static(Config::get('i18n'));
});
Events::attach('view:generatePhwoolconJsOptions', function (Event $event) {
$options = $event->getData() ?: [];
$options['locale'] = static::getCurrentLocale();
$event->setData($options);
return $options;
});
}
示例13: register
public static function register(Di $di)
{
static::$di = $di;
ini_set('session.use_cookies', 0);
ini_set('session.cache_limiter', '');
$di->remove('session');
static::$session = null;
$di->setShared('session', function () {
$default = Config::get('session.default');
$config = Config::get('session.drivers.' . $default);
$class = $config['adapter'];
$options = $config['options'];
$options += Config::get('session.options');
$options['cookies'] += Config::get('cookies');
session_name($options['cookies']['name']);
strpos($class, '\\') === false and $class = 'Phwoolcon\\Session\\Adapter\\' . $class;
$session = new $class($options);
// @codeCoverageIgnoreStart
if (!$session instanceof AdapterInterface) {
throw new SessionException('Session class should implement ' . AdapterInterface::class);
}
// @codeCoverageIgnoreEnd
return $session;
});
}
示例14: register
public static function register(Di $di)
{
static::$di = $di;
$di->remove('router');
$di->setShared('router', function () {
return new static();
});
}
示例15: injectTo
public static function injectTo(Di $di)
{
$di->setShared('logger', $di->get('config')['logger']);
}