| 1 |
<?php |
| 2 |
/** |
| 3 |
* Creates a header instance with response headers. |
| 4 |
* |
| 5 |
* @since 1.0.0 |
| 6 |
* |
| 7 |
* @package SolidWP\Performance |
| 8 |
*/ |
| 9 |
|
| 10 |
declare( strict_types=1 ); |
| 11 |
|
| 12 |
namespace SolidWP\Performance\Http; |
| 13 |
|
| 14 |
use SolidWP\Performance\Container; |
| 15 |
|
| 16 |
/** |
| 17 |
* Creates a header instance using response headers. |
| 18 |
* |
| 19 |
* @since 1.0.0 |
| 20 |
* |
| 21 |
* @package SolidWP\Performance |
| 22 |
*/ |
| 23 |
class Header_Factory { |
| 24 |
|
| 25 |
/** |
| 26 |
* @var Container |
| 27 |
*/ |
| 28 |
private Container $container; |
| 29 |
|
| 30 |
/** |
| 31 |
* @param Container $container The container. |
| 32 |
*/ |
| 33 |
public function __construct( Container $container ) { |
| 34 |
$this->container = $container; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Make a header instance using response headers. |
| 39 |
* |
| 40 |
* @note headers_list() does not work in CLI. |
| 41 |
* |
| 42 |
* @return Header |
| 43 |
*/ |
| 44 |
public function make(): Header { |
| 45 |
$headers = headers_list(); |
| 46 |
|
| 47 |
$this->container->when( Header::class ) |
| 48 |
->needs( '$headers' ) |
| 49 |
->give( static fn(): array => $headers ); |
| 50 |
|
| 51 |
$header = $this->container->get( Header::class ); |
| 52 |
|
| 53 |
$this->container->singleton( Header::class, $header ); |
| 54 |
|
| 55 |
return $header; |
| 56 |
} |
| 57 |
} |
| 58 |
|