-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponseCurrent.php
More file actions
95 lines (70 loc) · 2.01 KB
/
ResponseCurrent.php
File metadata and controls
95 lines (70 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/main/blob/master/LICENSE
*/
namespace Quid\Main;
use Quid\Base;
// responseCurrent
// class for an object that acts as representation of current response
class ResponseCurrent extends ArrObj
{
// trait
use _inst;
// config
protected static array $config = [];
// construct
// cconstructeur privé, rien ne se passe, objet singleton
final private function __construct() {}
// call
// renvoie vers base/response
// envoie une exception si la méthode statique n'existe pas
final public function __call(string $method,array $args):mixed
{
$return = null;
if(Base\Response::classHasMethod($method))
$return = Base\Response::$method(...$args);
else
static::throw('unknownMethod',$method);
return $return;
}
// arr
// retourne le tableau des en-têtes
final protected function arr():array
{
return $this->headers();
}
// offsetExists
// retourne vrai si le header existe
public function offsetExists($key):bool
{
return $this->headerExists($key);
}
// offsetGet
// retourne la valeur du header
public function offsetGet($key):mixed
{
return ($this->offsetExists($key))? $this->getHeader($key):static::throw($key);
}
// offsetSet
// ajoute ou change la valeur d'un header
public function offsetSet($key,$value):void
{
$this->setHeader($key,$value);
}
// offsetUnset
// enlève un header
public function offsetUnset($key):void
{
($this->offsetExists($key))? $this->unsetHeader($key):static::throw($key);
}
// singleton
// crée ou retourne le singleton de l'objet réponse
final public static function singleton():self
{
return static::instSafe() ?: static::instNew();
}
}
?>