Пример #1
0
 /**
  * Makes the instance of Es\Http\Uri.
  *
  * @param array $server Optional; null by default or empty array means
  *                      global $_SERVER. The source data
  *
  * @return \Es\Http\Uri The instance of Uri
  */
 public static function make(array $server = null)
 {
     $scheme = UriSchemeFactory::make($server);
     $host = UriHostFactory::make($server);
     $port = UriPortFactory::make($server);
     $path = UriPathFactory::make($server);
     $query = UriQueryFactory::make($server);
     $url = '';
     if ($host) {
         $url .= $scheme . '://' . $host . ':' . $port;
         $path = '/' . ltrim($path, '/');
     }
     $url .= $path;
     if ($query) {
         $url .= '?' . $query;
     }
     $uri = new Uri($url);
     if ($host) {
         return $uri;
     }
     return $uri->withScheme($scheme)->withPort($port);
 }
Пример #2
0
 /**
  * Compiles route.
  */
 protected function compile()
 {
     $this->parts = $parts = preg_split('#\\/#', $this->path, -1, PREG_SPLIT_NO_EMPTY);
     $regex = '';
     foreach ($parts as &$part) {
         $control = substr($part, 0, 2);
         if (false !== strpos($control, ':')) {
             if (!preg_match('#\\A(~)?(:){1}[a-zA-Z0-9]+\\Z#', $part)) {
                 throw new InvalidArgumentException(sprintf('Invalid placeholder name "%s" provided; must contain ' . 'only english alphanumeric characters.', $part));
             }
         } elseif (preg_match('/[\\#\\?]+/', $part)) {
             throw new InvalidArgumentException(sprintf('The segment "%s" of path "%s" contains illegal characters.', $part, $this->path));
         }
         if ('~:' === substr($part, 0, 2)) {
             $part = ltrim($part, '~:');
             $regex .= '\\/?(?P<' . $part . '>';
             if (isset($this->constraints[$part])) {
                 $regex .= $this->constraints[$part] . ')';
             } else {
                 $regex .= '[^\\/]*)';
             }
         } elseif (':' === substr($part, 0, 1)) {
             $part = ltrim($part, ':');
             $regex .= '\\/(?P<' . $part . '>';
             if (isset($this->constraints[$part])) {
                 $regex .= $this->constraints[$part] . ')';
             } else {
                 $regex .= '[^\\/]+)';
             }
         } elseif ('~' === substr($part, 0, 1)) {
             $part = ltrim($part, '~');
             $regex .= '\\/?(' . preg_quote(Uri::encode($part)) . ')?';
         } else {
             $part = $part;
             $regex .= '\\/' . preg_quote(Uri::encode($part));
         }
     }
     $this->compiled = '#\\A' . $regex . '\\Z#';
 }
Пример #3
0
 public function testGetFragment()
 {
     $uri = new Uri();
     $this->assertSame('', $uri->getFragment());
 }