예제 #1
0
 public function init($yaf_app)
 {
     static $initialized = false;
     if (!$initialized) {
         $initialized = true;
         \Yaf\Loader::import(YK_CORE_ROOT . '/func.php');
         $config = $yaf_app->getConfig()->toArray();
         \Yaf\Registry::set('_config', $config);
         $level = $config['debug'] ? $config['debug'] == 1 ? E_ERROR : E_ALL : 0;
         define('MAIN_DEBUG', $config['debug']);
         if (MAIN_DEBUG) {
             ini_set('display_error', 'On');
         }
         error_reporting($level);
         define('TIMESTAMP', time());
         \Yaf\Registry::set('_clientip', isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'N/A');
         \Yaf\Registry::set('_clientport', isset($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : 0);
         \Yaf\Registry::set('_gzip', !isset($_SERVER['HTTP_ACCEPT_ENCODING']) || strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === false || !function_exists('ob_gzhandler') ? false : true);
         set_timeoffset($config['timeoffset']);
         //重置视图
         $view = new view();
         \Yaf\Registry::set('_view', $view);
         $yaf_app->getDispatcher()->setView($view);
         define('CHARSET', 'utf-8');
         //end
     }
 }
예제 #2
0
파일: TestCase.php 프로젝트: vzina/yaf-api
 /**
  * 设置application
  */
 public function setApplication()
 {
     $application = null;
     define('APPLICATION_NOT_RUN', true);
     Loader::import(APPLICATION_PATH . 'public/index.php');
     Registry::set('application', $application);
 }
예제 #3
0
파일: Bootstrap.php 프로젝트: eyehere/boom
 /**
  * @brief 把配置信息加载进入注册表
  * @param \Yaf\Dispatcher $dispatcher
  */
 public function _initConfig(\Yaf\Dispatcher $dispatcher)
 {
     $config = \Yaf\Application::app()->getConfig();
     foreach ($config as $section => $arrConf) {
         \Yaf\Registry::set($section, $arrConf);
     }
 }
예제 #4
0
파일: Module.php 프로젝트: huang-sh/yaf.app
 /**
  * yaf路由分发之前触发,完成读取模块自定义配置
  *
  * @access public
  * @param \Yaf\Request_Abstract $request
  * @param \Yaf\Response_Abstract $response
  * @return void
  */
 public function preDispatch(Request_Abstract $request, Response_Abstract $response)
 {
     $module_dir = ROOT_PATH . DS . APP_NAME . DS . 'modules' . DS . $request->module . DS;
     do {
         if (!file_exists($module_dir . 'config' . DS . 'Import.php')) {
             break;
         }
         $module_config = (include $module_dir . 'config' . DS . 'Import.php');
         if (!is_array($module_config)) {
             break;
         }
         $mount = MountManager::getInstance();
         $config = array();
         foreach ($module_config as $name => $option) {
             if (!is_string($option) && !is_callable($option) && !is_object($option)) {
                 $config[$name] = $option;
             } else {
                 if (is_string($option)) {
                     $config[$name] = $option;
                 } else {
                     $mount->mount($name, $option);
                 }
             }
         }
         $simple_config = new Simple($config, true);
         Registry::set("config", $simple_config);
         Registry::set("mount", $mount);
     } while (0);
 }
예제 #5
0
 public static function getInstance()
 {
     if ($instance = \Yaf\Registry::get('ApplicationInit_Medoo')) {
         return $instance;
     }
     $instance = new self();
     \Yaf\Registry::set('ApplicationInit_Medoo', $instance);
     return $instance;
 }
예제 #6
0
 public function key()
 {
     $a = null;
     $start = $this->get_microtime();
     for ($i = 0; $i < 1000; $i++) {
         \Core\KEY::set('test', $i, KEY_STATIC);
         $a = \Core\KEY::get('test', KEY_STATIC);
     }
     $end = $this->get_microtime();
     var_dump($end - $start);
     $start = $this->get_microtime();
     for ($i = 0; $i < 1000; $i++) {
         \Yaf\Registry::set('test', $i);
         $a = \Yaf\Registry::get('test');
     }
     $end = $this->get_microtime();
     var_dump(microtime());
     var_dump($end - $start);
     return FALSE;
 }
예제 #7
0
 public static function set($_key, $_value, $_scope = KEY_REGISTRY, $_prefix = DEFAULT_PREFIX)
 {
     $_result = FALSE;
     $_handle = self::_instance($_scope, $_prefix);
     switch ($_scope) {
         case KEY_STORAGE:
             break;
         case KEY_MEMORY:
             break;
         case KEY_CACHE:
             $_result = $_handle->set($_key, $_value);
             break;
         case KEY_STATIC:
             $_result = $_handle[$_key] = $_value;
             break;
         case KEY_REGISTRY:
         default:
             $_result = \Yaf\Registry::set(REGISTRY_KEY_PREFIX . $_prefix . $_key, $_value);
             self::$_registry_handle[$_prefix][$_key] = TRUE;
             break;
     }
     return $_result;
 }
예제 #8
0
파일: Cache.php 프로젝트: vzina/yaf-api
 public static function instance($name, array $config = array())
 {
     if (empty($name)) {
         $name = '_cache';
     }
     /** 单例*/
     if (Registry::has($name)) {
         return Registry::get($name);
     }
     if (empty($config)) {
         /** @var \Yaf\Config\Ini $_config */
         $_config = Registry::get('config');
         if (!$_config || !($tmp = $_config->get($name))) {
             return false;
         }
         $config = $tmp->toArray();
     }
     if (empty($config['adapter'])) {
         $config['adapter'] = 'file';
     }
     $cache = self::factory($config);
     Registry::set($name, $cache);
     return $cache;
 }
예제 #9
0
파일: Db.php 프로젝트: vzina/yaf-api
 public static function instance($name = null, array $config = array())
 {
     if (empty($name)) {
         $name = '_db';
     }
     /** 单例*/
     if (Registry::has($name)) {
         return Registry::get($name);
     }
     if (empty($config)) {
         /** @var \Yaf\Config\Ini $_config */
         $_config = Registry::get('config');
         if (!$_config || !($tmp = $_config->get($name))) {
             return false;
         }
         $config = $tmp->toArray();
     }
     if (empty($config['adapter'])) {
         $config['adapter'] = 'Pdo\\Mysql';
     }
     $db = Db::factory($config);
     Registry::set($name, $db);
     return $db;
 }
예제 #10
0
 /**
  * 把配置存到注册表
  */
 function _initConfig(\Yaf\Dispatcher $dispatcher)
 {
     $config = \Yaf\Application::app()->getConfig();
     \Yaf\Registry::set("config", $config);
 }
예제 #11
0
 /**
  * setup database connection and create table in memory
  *
  * @throws \ActiveRecord\DatabaseException
  */
 private function __setUpDatabase()
 {
     \ActiveRecord\Config::instance()->set_default_connection("test");
     $tables = $this->getDatabase()->tables();
     foreach ($tables as $table) {
         if ('sqlite_sequence' == $table) {
             continue;
         }
         $this->getDatabase()->query("DROP TABLE {$table}");
     }
     $sqlcontent = file_get_contents(dirname(__FILE__) . '/acceptance/setup/sqlite.sql');
     foreach (explode(";", $sqlcontent) as $sql) {
         if (trim($sql) == '') {
             continue;
         }
         $this->getDatabase()->query(trim($sql));
     }
     \Yaf\Registry::set('ApplicationDbInit', true);
 }
예제 #12
0
 public function _initLayout(Dispatcher $dispatcher)
 {
     /*layout allows boilerplate HTML to live in /views/layout rather than every script*/
     $layout = new LayoutPlugin('layout/layout.html');
     /* Store a reference in the registry so values can be set later.
      * This is a hack to make up for the lack of a getPlugin
      * method in the dispatcher.
      */
     Registry::set('layout', $layout);
     /*add the plugin to the dispatcher*/
     $dispatcher->registerPlugin($layout);
 }
예제 #13
0
 /**
  * Init Doctrine
  *
  */
 protected function _initDoctrine()
 {
     $classLoader = new Doctrine\Common\ClassLoader('Doctrine');
     $classLoader->register();
     $classLoader = new Doctrine\Common\ClassLoader('Symfony');
     $classLoader->register();
     $cache = new Doctrine\Common\Cache\ArrayCache();
     $config = new Doctrine\ORM\Configuration();
     $config->setMetadataCacheImpl($cache);
     $path = APPLICATION_PATH . '/entities/metadata';
     $driverImpl = new Doctrine\ORM\Mapping\Driver\YamlDriver($path);
     $config->setMetadataDriverImpl($driverImpl);
     $config->setQueryCacheImpl($cache);
     $config->setProxyDir(sys_get_temp_dir());
     $config->setAutoGenerateProxyClasses(true);
     // database configuration parameters
     $connOptions = $this->_config->db->toArray();
     $conn = array('driver' => $connOptions['adapter'], 'host' => $connOptions['params']['host'], 'user' => $connOptions['params']['user'], 'password' => $connOptions['params']['password'], 'dbname' => $connOptions['params']['dbname']);
     // obtaining the entity manager
     $entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
     \Yaf\Registry::set('EntityManager', $entityManager);
 }
예제 #14
0
 /**
  * 设置application
  */
 public function setApplication()
 {
     $application = new \Yaf\Application(APPLICATION_PATH . "/conf/application.ini");
     $application->bootstrap();
     \Yaf\Registry::set('application', $application);
 }
예제 #15
0
 /**
  * 注册驱动
  * @param Yaf\Dispatcher $dispatcher 分发对象
  * @return void
  */
 public function _initDriver(Dispatcher $dispatcher)
 {
     if ($drivers = new Ini(sprintf("%sdriver.ini", CONF_PATH))) {
         // 注册数据库
         foreach ($drivers->get('database') as $name => $driver) {
             $database = PDOLib::getInstance($driver->type, $driver->host, $driver->port, $driver->dbname, $driver->charset, $driver->username, $driver->password);
             \Yaf\ENVIRON != 'product' and $database->setDebug();
             Registry::set("database.{$name}", $database);
         }
         // 注册redis
         foreach ($drivers->get('redis') as $name => $driver) {
             // 创建redis对象
             $redis = new \Redis();
             // 持久性连接
             $redis->pconnect($driver->host, $driver->port, (double) $driver->timeout);
             // 选项设置
             foreach ($driver->options as $key => $option) {
                 $redis->setOption(constant(sprintf("\\Redis::OPT_%s", strtoupper($key))), $option);
             }
             // 密码验证
             $driver->auth and $redis->auth($driver->auth);
             // 全局保存
             Registry::set("redis.{$name}", $redis);
         }
     }
 }
예제 #16
0
 /**
  * 注册session对象
  * 根据需要设置
  */
 public function _initSession(\Yaf\Dispatcher $dispatcher)
 {
     $session = \Session::getInstance();
     \Yaf\Registry::set('session', $session);
 }
예제 #17
0
 public function _initConfig()
 {
     $config = \Yaf\Application::app()->getConfig();
     \Yaf\Registry::set("config", $config);
 }
예제 #18
0
 /**
  * 加载项目的配置文件
  */
 public function _initAppConf(\Yaf\Dispatcher $dispatcher)
 {
     $config = new \Yaf\Config\Ini(APPLICATION_PATH . '/conf/common.ini');
     \Yaf\Registry::set('app', $config);
 }
예제 #19
0
 public function _initConfig()
 {
     //把配置保存起来
     $this->_config = Application::app()->getConfig();
     Registry::set('config', $this->_config);
 }
예제 #20
0
 /**
  * 把配置存到注册表
  */
 public function _initConfig()
 {
     $config = \Yaf\Application::app()->getConfig();
     $this->_config = $config;
     \Yaf\Registry::set('config', $config);
 }
 /**
  * 获取安全码配置
  */
 public static function getOauthConfig($conName)
 {
     $recureIni = Registry::get('recure');
     if (!$recureIni instanceof \Yaf\Config\Ini) {
         $recureIni = new \Yaf\Config\Ini(APPLICATION_PATH . '/conf/secure.ini', \Yaf\Application::app()->environ());
         Registry::set('recure', $recureIni);
     }
     return $recureIni->get($conName);
 }