Exemple #1
0
 /**
  * Create a URI builder from the given URI.
  * 
  * @param string $uri The base URI for this builder.
  * @param string $path An optional path pattern to be appended to the base path from the URI.
  */
 public function __construct($uri, $path = NULL)
 {
     if (!$uri instanceof Uri) {
         $uri = new Uri($uri);
     }
     $this->uri = str_ireplace(['%7B', '%7D'], ['{', '}'], $uri->toString(Uri::TO_PATH));
     if ($path !== NULL) {
         $this->uri = rtrim($this->uri, '/') . '/' . ltrim($path, '/');
     }
     $m = NULL;
     preg_match_all("'\\{(?:(?>[^\\{\\}]+)|(?R))+\\}'S", $this->uri, $m);
     $this->pathParamNames = [];
     $replacements = [];
     foreach ($m[0] as $match) {
         if (false === ($index = stripos($match, '%3A'))) {
             $name = trim($match, '{}');
         } else {
             $name = substr($match, 1, $index - 1);
         }
         $replacements[$match] = '{' . $name . '}';
         if (false !== ($index = strpos($name, '.'))) {
             $name = substr($name, 0, $index);
         }
         if (!in_array($name, $this->pathParamNames)) {
             $this->pathParamNames[] = $name;
         }
     }
     $this->uri = str_replace('/./', '/', strtr($this->uri, $replacements));
     while (preg_match("'/([^/]+/\\.\\./)'", $this->uri, $m)) {
         $this->uri = str_replace($m[1], '', $this->uri);
     }
     $this->uri = rtrim($this->uri, '/');
     $this->path = [];
     $this->query = [];
 }
Exemple #2
0
 /**
  * Get the base URI of the front controller.
  * 
  * @return Uri
  */
 public function getBaseUri()
 {
     return new Uri($this->uri->toString(Uri::TO_HOST) . $this->pathBase);
 }