Esempio n. 1
0
 /**
  * Private method for building the URL object
  *
  * @return \r8\URL
  */
 private function buildURL()
 {
     $url = new \r8\URL();
     // Get the url Scheme from the server protocol
     if (self::hasKey($this->server, "SERVER_PROTOCOL")) {
         $url->setScheme(strtolower(strstr($this->server['SERVER_PROTOCOL'], "/", TRUE)));
     }
     // Pull the server host, if it is set
     if (self::hasKey($this->server, 'HTTP_HOST')) {
         $url->setHost($this->server['HTTP_HOST']);
     } else {
         if (self::hasKey($this->server, "SERVER_ADDR")) {
             $url->setHost($this->server['SERVER_ADDR']);
         }
     }
     // Pull the port
     if (self::hasKey($this->server, "SERVER_PORT")) {
         $url->setPort((int) $this->server['SERVER_PORT']);
     }
     // The path and file name
     if (self::hasKey($this->server, 'SCRIPT_NAME')) {
         $url->setPath($this->server['SCRIPT_NAME']);
     }
     // The faux directories
     if (self::hasKey($this->server, 'PATH_INFO')) {
         $url->setFauxDir(\r8\str\head($this->server['PATH_INFO'], "/"));
     }
     // Finally, pull the the URL query
     if (self::hasKey($this->server, 'QUERY_STRING')) {
         $url->setQuery($this->server['QUERY_STRING']);
     }
     return $url;
 }
Esempio n. 2
0
 /**
  * Sets the fauxDir
  *
  * @param String $fauxDir The fauxDir to set
  * @return \r8\URL Returns a self reference
  */
 public function setFauxDir($fauxDir)
 {
     $fauxDir = (string) $fauxDir;
     $this->fauxDir = \r8\isEmpty($fauxDir) ? null : \r8\str\head($fauxDir, "/");
     return $this;
 }
Esempio n. 3
0
/**
 * Ensures that the given string is at the beginning and end of a string
 *
 * @param String $string The string being enclosed
 * @param String $enclose The value to be appended and prepended to the string, it it doesn't already exist
 * @param Boolean $ignoreCase Whether the comparison should be case sensitive
 * @return String Returns the string with the head and tail on it
 */
function enclose($string, $enclose, $ignoreCase = TRUE)
{
    return \r8\str\tail(\r8\str\head($string, $enclose, $ignoreCase), $enclose, $ignoreCase);
}
Esempio n. 4
0
 public function testHead()
 {
     $this->assertEquals('headstring', \r8\str\head('string', 'head'));
     $this->assertEquals('headstring', \r8\str\head('headstring', 'head'));
     $this->assertEquals('headstring', \r8\str\head('string', 'head', TRUE));
     $this->assertEquals('headstring', \r8\str\head('headstring', 'head', TRUE));
     $this->assertEquals('headstring', \r8\str\head('string', 'head', FALSE));
     $this->assertEquals('headstring', \r8\str\head('headstring', 'head', FALSE));
     $this->assertEquals('Headheadstring', \r8\str\head('headstring', 'Head', FALSE));
     $this->assertEquals('Headstring', \r8\str\head('Headstring', 'Head', FALSE));
 }
Esempio n. 5
0
 /**
  * Resolves a path relative to this namespace
  *
  * @param String $path
  * @return String
  */
 public function resolve($path)
 {
     $path = (string) $path;
     // If the path is global, no resolution necessary
     if (\substr($path, 0, 1) === '\\') {
         return $path;
     }
     // if the first part of the namespace is registered as a namespace,
     // then resolve it
     $pathParts = explode('\\', $path);
     $firstPart = array_shift($pathParts);
     if (isset($this->aliases[$firstPart])) {
         $path = $this->aliases[$firstPart]->getPath() . '\\' . implode('\\', $pathParts);
     } else {
         if (\substr($path, 0, 1) !== '\\') {
             $path = $this->path . '\\' . $path;
         }
     }
     return \r8\str\head($path, '\\');
 }