aboutsummaryrefslogtreecommitdiff
path: root/src/URL.php
diff options
context:
space:
mode:
authorpolo <ordipolo@gmx.fr>2026-03-24 22:39:29 +0100
committerpolo <ordipolo@gmx.fr>2026-03-24 22:40:33 +0100
commit3b369122645b07b290f7fcc7bccb4787745cd5ea (patch)
tree3f9c2d1fbd5fe8b26162202e9b1e6cd5c8a940f6 /src/URL.php
parenta70dee9b5021a137ae07041c38921553442b0c11 (diff)
downloadcms-3b369122645b07b290f7fcc7bccb4787745cd5ea.tar.gz
cms-3b369122645b07b290f7fcc7bccb4787745cd5ea.tar.bz2
cms-3b369122645b07b290f7fcc7bccb4787745cd5ea.zip
mode maintenance, optimisation moins de contrôles en mode run, dossier service et déplacement fichiers, sessions et entité User préparées à l'implémentation hypothétique des rôles, entité AppMetadata, meilleure sécurité de fillStartingDatabase
Diffstat (limited to 'src/URL.php')
-rw-r--r--src/URL.php88
1 files changed, 0 insertions, 88 deletions
diff --git a/src/URL.php b/src/URL.php
deleted file mode 100644
index a6d6379..0000000
--- a/src/URL.php
+++ /dev/null
@@ -1,88 +0,0 @@
1<?php
2// src/URL.php
3
4declare(strict_types=1);
5
6class URL implements Stringable
7{
8 static private string $protocol = 'http://';
9 static private string $host = '';
10 static private string $port;
11 static private string $path = '/index.php';
12 private array $params;
13 private string $anchor = '';
14
15 public function __construct(array $gets = [], string $anchor = ''){
16 $this->params = $gets;
17 if($anchor != ''){
18 $this->setAnchor($anchor);
19 }
20 }
21
22 // setters statiques
23 static public function setProtocol(string $protocol = 'http'): void
24 {
25 self::$protocol = $protocol === 'https' ? 'https://' : 'http://';
26 }
27 static public function setPort(int|string $port = 80): void
28 {
29 if((int)$port === 443){
30 self::$protocol = 'https://';
31 self::$port = '';
32 }
33 elseif((int)$port === 80){
34 self::$protocol = 'http://';
35 self::$port = '';
36 }
37 else{
38 self::$port = ':' . (string)$port;
39 }
40 }
41 static public function setHost(string $host): void
42 {
43 self::$host = $host;
44 }
45 static public function setPath(string $path): void
46 {
47 self::$path = '/' . ltrim($path, '/');
48 }
49
50 //setters normaux
51 public function addParams(array $gets): void
52 {
53 // array_merge est préféré à l'opérateur d'union +, si une clé existe déjà la valeur est écrasée
54 $this->params = array_merge($this->params, $gets);
55 }
56 public function setAnchor(string $anchor = ''): void
57 {
58 if($anchor != ''){
59 $this->anchor = '#' . ltrim($anchor, '#');
60 }
61 else{
62 $this->anchor = '';
63 }
64 }
65
66 private function makeParams(): string
67 {
68 $output = '';
69 $first = true;
70
71 foreach($this->params as $key => $value) {
72 if($first){
73 $output .= '?';
74 $first = false;
75 }
76 else{
77 $output .= '&';
78 }
79 $output .= $key . '=' . $value;
80 }
81 return $output;
82 }
83
84 public function __toString(): string
85 {
86 return self::$protocol . self::$host . self::$port . self::$path . $this->makeParams() . $this->anchor;
87 }
88} \ No newline at end of file