当前位置: 首页>>代码示例>>PHP>>正文


PHP Di::setShared方法代码示例

本文整理汇总了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;
 }
开发者ID:kengos,项目名称:phalconCart,代码行数:12,代码来源:AbstractInitializer.php

示例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;
 }
开发者ID:phalcon,项目名称:cphalcon,代码行数:12,代码来源:SessionTest.php

示例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);
     }
 }
开发者ID:phalcon,项目名称:incubator,代码行数:16,代码来源:EagerLoadingTest.php

示例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);
     }
 }
开发者ID:lisong,项目名称:incubator,代码行数:16,代码来源:EagerLoadingTest.php

示例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();
 }
开发者ID:phwoolcon,项目名称:auth,代码行数:28,代码来源:Auth.php

示例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
    }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:33,代码来源:Config.php

示例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'));
     });
 }
开发者ID:phwoolcon,项目名称:payment,代码行数:9,代码来源:Processor.php

示例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;
     });
 }
开发者ID:tobeorla,项目名称:phalcon-skeleton,代码行数:13,代码来源:Logger.php

示例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);
     });
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:14,代码来源:Counter.php

示例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;
     });
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:18,代码来源:Log.php

示例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;
     });
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:18,代码来源:Cache.php

示例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;
     });
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:13,代码来源:I18n.php

示例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;
     });
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:25,代码来源:Session.php

示例14: register

 public static function register(Di $di)
 {
     static::$di = $di;
     $di->remove('router');
     $di->setShared('router', function () {
         return new static();
     });
 }
开发者ID:phwoolcon,项目名称:phwoolcon,代码行数:8,代码来源:Router.php

示例15: injectTo

 public static function injectTo(Di $di)
 {
     $di->setShared('logger', $di->get('config')['logger']);
 }
开发者ID:mamuz,项目名称:phalcon-skeleton,代码行数:4,代码来源:Logger.php


注:本文中的Phalcon\Di::setShared方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。