示例#1
0
 protected function input()
 {
     $this->_config = $this->getInstance('config', 'bConfig');
     $this->_db = $this->getInstance('db', 'bRewrite__bDataMapper');
     $this->_isDisable = $this->_config->getConfig('bRewrite.isDisable');
     $this->_url = parse_url($_SERVER['REQUEST_URI']);
 }
示例#2
0
 /**
  * Setter for  decor rules
  *
  * @param array $list   - decor rules
  */
 public final function setList($list = array())
 {
     // reset storing strategy by default
     $this->_config->setDefault();
     // save list
     $this->_config->setConfig(__CLASS__, $list);
 }
示例#3
0
 /**
  * Get database object
  *
  * @param string $name	- config name
  * @return null|PDO		- database object
  * @throws Exception
  */
 public function getDataBase($name = 'default')
 {
     if (!array_key_exists($name, $this->_db)) {
         // get connections properties
         $config = $this->_config->getConfig(__CLASS__);
         $connections = $config["connections"];
         foreach ($connections as $key => $value) {
             if ($value['name'] === $name) {
                 $connect = $value;
             }
         }
         if (!isset($connect)) {
             throw new Exception('Can`t find connection "' . $name . '" in db configuration');
         }
         $db = array_replace(array('provider' => '', 'host' => '', 'database' => '', 'user' => '', 'password' => '', 'persistent' => false), $connect);
         $dsn = sprintf('%1$s:host=%2$s;dbname=%3$s', $db['provider'], $db['host'], $db['database']);
         $attrs = array();
         if ($db['persistent']) {
             $attrs[PDO::ATTR_PERSISTENT] = true;
         }
         $pdo = new PDO($dsn, $db['user'], $db['password'], $attrs);
         if ($db['provider'] === 'mysql') {
             $pdo->query("SET NAMES utf8");
         }
         $this->_db[$name] = $pdo;
     }
     return $this->_db[$name];
 }
示例#4
0
 /**
  * Get menu from database
  *
  * @param null|int $id  - menu group id
  * @return array        - all menu items included in menu
  */
 public function getMenu($id = null)
 {
     if (!$id) {
         return array();
     }
     // get menu item list
     $menuList = $this->_db->getMenu($id);
     // get config for menu
     $config = $this->_config->getConfig('bMenu.items');
     // serialize menu items by config
     foreach ($menuList as &$item) {
         $item['config'] = isset($config[$item['id']]) ? $config[$item['id']] : array();
     }
     return $menuList;
 }
示例#5
0
文件: bConfig.php 项目: Vitologi/blib
 /**
  * Overload object factory for Singleton
  *
  * @return bConfig|null|static
  */
 public static function create()
 {
     if (self::$_instance === null) {
         self::$_instance = parent::create(func_get_args());
     }
     return self::$_instance;
 }