diff options
Diffstat (limited to 'src/Service/URL.php')
| -rw-r--r-- | src/Service/URL.php | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/src/Service/URL.php b/src/Service/URL.php index 035f572..e6f986c 100644 --- a/src/Service/URL.php +++ b/src/Service/URL.php | |||
| @@ -58,33 +58,20 @@ class URL implements \Stringable | |||
| 58 | public function setAnchor(string $anchor = ''): void | 58 | public function setAnchor(string $anchor = ''): void |
| 59 | { | 59 | { |
| 60 | if($anchor != ''){ | 60 | if($anchor != ''){ |
| 61 | $this->anchor = '#' . ltrim($anchor, '#'); | 61 | $this->anchor = '#' . rawurlencode(ltrim($anchor, '#'));// rawurlencode échappe les mêmes caractères |
| 62 | } | 62 | } |
| 63 | else{ | 63 | else{ |
| 64 | $this->anchor = ''; | 64 | $this->anchor = ''; |
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | private function makeParams(): string | ||
| 69 | { | ||
| 70 | $output = ''; | ||
| 71 | $first = true; | ||
| 72 | |||
| 73 | foreach($this->params as $key => $value) { | ||
| 74 | if($first){ | ||
| 75 | $output .= '?'; | ||
| 76 | $first = false; | ||
| 77 | } | ||
| 78 | else{ | ||
| 79 | $output .= '&'; | ||
| 80 | } | ||
| 81 | $output .= $key . '=' . $value; | ||
| 82 | } | ||
| 83 | return $output; | ||
| 84 | } | ||
| 85 | |||
| 86 | public function __toString(): string | 68 | public function __toString(): string |
| 87 | { | 69 | { |
| 88 | return self::$protocol . self::$host . self::$port . self::$path . $this->makeParams() . $this->anchor; | 70 | return self::$protocol . self::$host . self::$port . self::$path |
| 71 | . ($this->params ? '?' . http_build_query($this->params) : '') | ||
| 72 | . $this->anchor; | ||
| 73 | // http_build_query change un tableau comme ['key1' => 'value 1', 'key2' => 'value 2'] | ||
| 74 | // en chaine: key1=value+1&key2=value+2 | ||
| 75 | // les caractères ", ', <, >, &, #, = et espaces sont échappés (comme avec rawurlencode pour les ancres) | ||
| 89 | } | 76 | } |
| 90 | } \ No newline at end of file | 77 | } \ No newline at end of file |
