Esempio n. 1
0
 /**
  * Creates a new URI instance from the global variables.
  *
  * @return \Elegant\Http\Message\Uri
  */
 public static final function createFromGlobals()
 {
     $scheme = empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off' ? 'http' : 'https';
     $host = '';
     $port = null;
     if (isset($_SERVER['HTTP_HOST'])) {
         if (Str::contains($_SERVER['HTTP_HOST'], ':')) {
             list($host, $port) = explode(':', $_SERVER['HTTP_HOST'], 2);
         } else {
             $host = $_SERVER['HTTP_HOST'];
         }
     } else {
         if (isset($_SERVER['SERVER_NAME'])) {
             $host = $_SERVER['SERVER_NAME'];
         }
         if (isset($_SERVER['SERVER_PORT'])) {
             $port = $_SERVER['SERVER_PORT'];
         }
     }
     if (isset($_SERVER['SCRIPT_NAME'])) {
         $basePath .= dirname($_SERVER['SCRIPT_NAME']);
     } else {
         $basePath = '/';
     }
     $path = '';
     if (isset($_SERVER['PATH_INFO'])) {
         $path = $_SERVER['PATH_INFO'];
     } elseif (isset($_SERVER['REQUEST_URI'])) {
         if ($p = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)) {
             if (Str::icontains($p, $basePath)) {
                 $path = mb_substr($p, mb_strlen($basePath));
             } else {
                 $path = $p;
             }
         }
     }
     $query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
     $user = isset($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
     $password = isset($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : null;
     $uri = $this->create();
     $uri = $uri->withScheme($scheme);
     $uri = $uri->withHost($host);
     $uri = $uri->withPort($port);
     $uri = $uri->withBasePath($basePath);
     $uri = $uri->withPath($path);
     $uri = $uri->withQuery($query);
     $uri = $uri->withUserInfo($user, $password);
     return $uri;
 }
Esempio n. 2
0
 protected function column($column)
 {
     if ($column instanceof Aggregate) {
         return $this->aggregate($column);
     }
     if ($column instanceof Raw) {
         return $this->raw($column);
     }
     if ($column instanceof Query) {
         return $this->query($column);
     }
     if (Str::icontains('->', $column)) {
         return $this->json(explode('->', $column));
     }
     $wrapped = [];
     $segments = explode('.', $column);
     if (1 < count($segments)) {
         $wrapped[] = $this->table(array_unshift($segments));
     }
     foreach ($segments as $key => $segment) {
         if ($segment === '*') {
             $wrapped[] = $segment;
         } else {
             $wrapped[] = $this->id($segment);
         }
     }
     return implode('.', $wrapped);
 }