Example #1
0
 public static function createFromGlobals()
 {
     $ajax = false;
     if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
         $ajax = $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
     }
     $secure = !empty($_SERVER['HTTPS']);
     $request = new self();
     $request->setHost($_SERVER['HTTP_HOST'])->setPath($_SERVER[PROTOCOL])->setSecure($secure)->setMethod($_SERVER['REQUEST_METHOD'])->setAjax($ajax)->setGet($_GET)->setPost($_POST)->setFiles($_FILES);
     return $request;
 }
 /**
  * Factory method to hydrate an instance from serialized options
  *
  * @param array $options
  * @return self
  */
 public static function fromArray(array $options)
 {
     $options = array_replace(['host' => '127.0.0.1', 'port' => 9200, 'index' => '', 'shards' => 3, 'replicas' => 0, 'minScore' => 4, 'highlight' => true], $options);
     $self = new self();
     $self->setHost($options['host']);
     $self->setPort($options['port']);
     $self->setIndexName($options['index']);
     $self->setShards($options['shards']);
     $self->setReplicas($options['replicas']);
     $self->setMinScore($options['minScore']);
     $self->setHighlight($options['highlight']);
     return $self;
 }
Example #3
0
 /**
  * Convert a Windows file path to a valid file:// URL
  * 
  * @param  string $path
  * @return File
  */
 public static function fromWindowsPath($path)
 {
     $url = new self('file:');
     // Convert directory separators
     $path = str_replace(array('/', '\\'), array('%2F', '/'), $path);
     // Is this an absolute path?
     if (preg_match('|^([a-zA-Z]:)?/|', $path)) {
         $url->setHost('');
     }
     $url->setPath($path);
     return $url;
 }
Example #4
0
 public static function host($url)
 {
     $self = new self();
     $self->setHost($url);
     return $self;
 }
Example #5
0
 /**
  * @param wfWAFRequest|null $request
  * @return wfWAFRequest
  */
 public static function createFromGlobals($request = null)
 {
     if ($request === null) {
         if (version_compare(phpversion(), '5.3.0') > 0) {
             $class = get_called_class();
             $request = new $class();
         } else {
             $request = new self();
         }
     }
     $request->setAuth(array());
     $request->setCookies(array());
     $request->setFileNames(array());
     $request->setFiles(array());
     $request->setHeaders(array());
     $request->setHost('');
     $request->setIP('');
     $request->setMethod('');
     $request->setPath('');
     $request->setProtocol('');
     $request->setTimestamp('');
     $request->setURI('');
     $request->setBody(wfWAFUtils::stripMagicQuotes($_POST));
     $request->setQueryString(wfWAFUtils::stripMagicQuotes($_GET));
     $request->setCookies(wfWAFUtils::stripMagicQuotes($_COOKIE));
     $request->setFiles(wfWAFUtils::stripMagicQuotes($_FILES));
     if (!empty($_FILES)) {
         $fileNames = array();
         foreach ($_FILES as $input => $file) {
             $fileNames[$input] = wfWAFUtils::stripMagicQuotes($file['name']);
         }
         $request->setFileNames($fileNames);
     }
     if (is_array($_SERVER)) {
         //All of these depend on $_SERVER being non-null and an array
         $auth = array();
         if (array_key_exists('PHP_AUTH_USER', $_SERVER)) {
             $auth['user'] = wfWAFUtils::stripMagicQuotes($_SERVER['PHP_AUTH_USER']);
         }
         if (array_key_exists('PHP_AUTH_PW', $_SERVER)) {
             $auth['password'] = wfWAFUtils::stripMagicQuotes($_SERVER['PHP_AUTH_PW']);
         }
         $request->setAuth($auth);
         if (array_key_exists('REQUEST_TIME_FLOAT', $_SERVER)) {
             $timestamp = $_SERVER['REQUEST_TIME_FLOAT'];
         } else {
             if (array_key_exists('REQUEST_TIME', $_SERVER)) {
                 $timestamp = $_SERVER['REQUEST_TIME'];
             } else {
                 $timestamp = time();
             }
         }
         $request->setTimestamp($timestamp);
         $headers = array();
         foreach ($_SERVER as $key => $value) {
             if (wfWAFUtils::strpos($key, 'HTTP_') === 0) {
                 $header = wfWAFUtils::substr($key, 5);
                 $header = str_replace(array(' ', '_'), array('', ' '), $header);
                 $header = ucwords(wfWAFUtils::strtolower($header));
                 $header = str_replace(' ', '-', $header);
                 $headers[$header] = wfWAFUtils::stripMagicQuotes($value);
             }
         }
         if (array_key_exists('CONTENT_TYPE', $_SERVER)) {
             $headers['Content-Type'] = wfWAFUtils::stripMagicQuotes($_SERVER['CONTENT_TYPE']);
         }
         if (array_key_exists('CONTENT_LENGTH', $_SERVER)) {
             $headers['Content-Length'] = wfWAFUtils::stripMagicQuotes($_SERVER['CONTENT_LENGTH']);
         }
         $request->setHeaders($headers);
         $host = '';
         if (array_key_exists('Host', $headers)) {
             $host = $headers['Host'];
         } else {
             if (array_key_exists('SERVER_NAME', $_SERVER)) {
                 $host = wfWAFUtils::stripMagicQuotes($_SERVER['SERVER_NAME']);
             }
         }
         $request->setHost($host);
         $request->setMethod(array_key_exists('REQUEST_METHOD', $_SERVER) ? wfWAFUtils::stripMagicQuotes($_SERVER['REQUEST_METHOD']) : 'GET');
         $request->setProtocol(array_key_exists('HTTPS', $_SERVER) && $_SERVER['HTTPS'] && $_SERVER['HTTPS'] !== 'off' ? 'https' : 'http');
         $request->setUri(array_key_exists('REQUEST_URI', $_SERVER) ? wfWAFUtils::stripMagicQuotes($_SERVER['REQUEST_URI']) : '');
         $uri = parse_url($request->getURI());
         if (is_array($uri) && array_key_exists('path', $uri)) {
             $path = $uri['path'];
         } else {
             $path = $request->getURI();
         }
         $request->setPath($path);
     }
     return $request;
 }
Example #6
0
 /**
  *	Returns Data Source Name String.
  *	@access		public
  *	@static
  *	@param		string		$driver			Database Driver (cubrid|dblib|firebird|informix|mysql|mssql|oci|odbc|pgsql|sqlite|sybase)
  *	@param		string		$database		Database Name
  *	@param		string		$host			Host Name or URI
  *	@param		int			$port			Host Port
  *	@param		string		$username		Username
  *	@param		string		$password		Password
  *	@return		string
  */
 public static function renderStatic($driver, $database, $host = NULL, $port = NULL, $username = NULL, $password = NULL)
 {
     $dsn = new self($driver, $database);
     $dsn->setHost($host);
     $dsn->setPort($port);
     $dsn->setUsername($username);
     $dsn->setPassword($password);
     return $dsn->render();
 }
 /**
  * Returns instance containing the host only.
  *
  * <pre>
  *   [scheme]://[username]:[password]@[host]:[port]/[path]?[query_string]#[fragment]
  *                                     ^^^^
  * </pre>
  *
  * @return \Components\Uri
  */
 public function reduceToHost()
 {
     $instance = new self();
     $instance->setHost($this->getHost());
     return $instance;
 }
Example #8
0
 /**
  * @param ShopEntity $shop
  * @return Shop
  */
 public static function createFromShopEntity(ShopEntity $shop)
 {
     $struct = new self();
     $struct->setId($shop->getId());
     $struct->setParentId($shop->getMain() ? $shop->getMain()->getId() : $shop->getId());
     $struct->setIsDefault($shop->getDefault());
     $struct->setName($shop->getName());
     $struct->setHost($shop->getHost());
     $struct->setPath($shop->getBasePath());
     $struct->setUrl($shop->getBaseUrl());
     $struct->setSecure($shop->getSecure());
     $struct->setSecureHost($shop->getSecureHost());
     $struct->setSecurePath($shop->getSecureBasePath());
     if ($shop->getCategory()) {
         $struct->setCategory(Category::createFromCategoryEntity($shop->getCategory()));
     }
     if ($shop->getFallback()) {
         $struct->setFallbackId($shop->getFallback()->getId());
     }
     return $struct;
 }
Example #9
0
 /**
  * @return Url
  */
 public static function current()
 {
     $url = new self($_SERVER['REQUEST_URI']);
     $url->setHost($_SERVER['HTTP_HOST']);
     if (isset($_SERVER['HTTPS'])) {
         $url->setScheme('https');
     } else {
         $url->setScheme('http');
     }
     return $url;
 }