Ejemplo n.º 1
0
 /**
  * @param \Demo\Domain\ValueObjects\Url $url
  *
  * @return \Demo\Domain\ValueObjects\Url
  */
 public static function normalize(Url $url)
 {
     $path = $url->getPath();
     //Replace // with /
     $path = preg_replace('%/{2,}%', '/', $path);
     //Replace /./ with /
     $path = preg_replace('%/\\./%', '/', $path);
     //Replace /path/../ with /
     $path = preg_replace('%/[^/|\\.\\.]+/../%', '/', $path);
     //Replace ^/../ with /
     $path = preg_replace('%^/../%', '/', $path);
     if (substr_count($path, '/../') || substr_count($path, '//') || substr_count($path, '/./')) {
         //Call recursively if still need further normalization
         return self::normalize(new Url(str_replace($url->getPath(), $path, (string) $url)));
     }
     //Otherwise return the normalized path
     return new Url(str_replace($url->getPath(), $path, (string) $url));
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider validUrlProvider
  *
  * @param string $urlString
  * @param array $expectedResult
  */
 public function testGetFragment($urlString, array $expectedResult)
 {
     $url = new Url($urlString);
     $this->assertEquals(array_key_exists('fragment', $expectedResult) ? $expectedResult['fragment'] : null, $url->getFragment());
 }
Ejemplo n.º 3
0
 /**
  * @return null|string
  */
 public function getFragment()
 {
     return $this->url->getFragment();
 }