Ejemplo n.º 1
0
Archivo: misc.php Proyecto: jasny/Q
/**
 * Turn a multidimensional array into a one dimensional array. 
 *
 * @param array  $array
 * @param string $key    Prefix
 * @param string $glue
 * @return array
 */
function array_combine_assoc(array $array, $key = null, $glue = '.')
{
    $result = array();
    foreach ($array as $k => $value) {
        if (is_array($value)) {
            $result += array_combine_assoc($value, isset($key) ? $key . $glue . $k : $k, $glue);
        } else {
            $result[isset($key) ? $key . $glue . $k : $k] = $value;
        }
    }
    return $result;
}
Ejemplo n.º 2
0
Archivo: Auth.php Proyecto: jasny/Q
 /**
  * Store AUTH info to session data.
  */
 protected function storeInfo()
 {
     $this->info = null;
     if ($this->user) {
         $this->info['uid'] = $this->user->getId();
         $this->info['checksum'] = $this->checksum();
     }
     $matches = null;
     if (is_string($this->store)) {
         $this->store = extract_dsn($this->store);
     }
     switch ($this->store['driver']) {
         case 'none':
             break;
         case 'session':
             session_start();
             $_SESSION['AUTH'] = $this->info;
             break;
         case 'cookie':
             $cookie_params = $this->store + session_get_cookie_params();
             if (!isset($this->info)) {
                 $this->info = array();
                 foreach (array_keys($_COOKIE) as $key) {
                     if (!preg_match('/^AUTH_(.*)$/i', $key, $matches)) {
                         continue;
                     }
                     setcookie($key, null, 1, $cookie_params['path'], $cookie_params['domain'], $cookie_params['secure'], $cookie_params['httponly']);
                     unset($_COOKIE[$key]);
                 }
             } else {
                 foreach (array_combine_assoc($this->info, 'AUTH', '_') as $key => $value) {
                     setcookie($key, $value, ($cookie_params['lifetime'] <= 1 ? 0 : time()) + $cookie_params['lifetime'], $cookie_params['path'], $cookie_params['domain'], $cookie_params['secure'], $cookie_params['httponly']);
                     $_COOKIE[$key] = $value;
                 }
             }
             break;
         case 'request':
             HTTP::addUrlRewriteVar('AUTH', $this->info);
             $_REQUEST['AUTH'] = $this->info;
             break;
         case 'env':
             putenv('AUTH=' . $this->info ? escapeshellarg(implode_assoc(';', $this->info)) : null);
             break;
         default:
             throw new Exception("Invalid option '{$this->store['driver']}' specified for storing info.");
     }
 }