示例#1
0
文件: Config.php 项目: JasonWiki/docs
 /**
  * Gets a value from config. If required is TRUE
  * then get will throw an exception if value cannot
  * be loaded.
  *
  * @param   string       key  the setting to get
  * @param   bool         slash  remove trailing slashes
  * @param   bool         required  is setting required?
  * @return  mixed
  * @access  public
  */
 public function get($key, $slash = FALSE, $required = FALSE)
 {
     // Get the group name from the key
     $group = explode('.', $key, 2);
     $group = $group[0];
     // Check for existing value and load it dynamically if required
     if (!isset($this->config[$group])) {
         $this->config[$group] = $this->load($group, $required);
     }
     // Get the value of the key string
     $value = Kohana::key_string($this->config, $key);
     if ($slash === TRUE and is_string($value) and $value !== '') {
         // Force the value to end with "/"
         $value = rtrim($value, '/') . '/';
     }
     if ($required === TRUE and $value === null) {
         throw new Kohana_Config_Exception('Value not found in config driver');
     }
     $this->loaded = TRUE;
     return $value;
 }
示例#2
0
文件: Session.php 项目: Toushi/flow
 /**
  * Get a variable. Access to sub-arrays is supported with key.subkey.
  *
  * @param   string  variable key
  * @param   mixed   default value returned if variable does not exist
  * @return  mixed   Variable data if key specified, otherwise array containing all session data.
  */
 public function get($key = FALSE, $default = FALSE)
 {
     if (empty($key)) {
         return $_SESSION;
     }
     $result = isset($_SESSION[$key]) ? $_SESSION[$key] : Kohana::key_string($_SESSION, $key);
     return $result === NULL ? $default : $result;
 }
示例#3
0
 /**
  * Fetch a message item.
  *
  * @param   string  language key to fetch
  * @param   array   additional information to insert into the line
  * @return  string  i18n language string, or the requested key if the i18n item is not found
  */
 public static function message($key, $args = array())
 {
     // Extract the main group from the key
     $group = explode('.', $key, 2);
     $group = $group[0];
     if (!isset(Kohana::$internal_cache['messages'][$group])) {
         // Messages for this group
         $messages = array();
         if ($file = Kohana::find_file('messages', $group)) {
             include $file[0];
         }
         if (!isset(Kohana::$write_cache['messages'])) {
             // Write language cache
             Kohana::$write_cache['messages'] = TRUE;
         }
         Kohana::$internal_cache['messages'][$group] = $messages;
     }
     // Get the line from cache
     $line = Kohana::key_string(Kohana::$internal_cache['messages'], $key);
     if ($line === NULL) {
         Kohana_Log::add('error', 'Missing messages entry ' . $key . ' for message ' . $group);
         // Return the key string as fallback
         return $key;
     }
     if (is_string($line) and func_num_args() > 1) {
         $args = array_slice(func_get_args(), 1);
         // Add the arguments into the line
         $line = vsprintf($line, is_array($args[0]) ? $args[0] : $args);
     }
     return $line;
 }