Skip to content

Commit

Permalink
HeadersReader 1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeghe committed Dec 19, 2024
1 parent 98aea44 commit decfb6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Includes the following helpers:
- [Cally](https://github.com/nabeghe/cally-php) <small>v0.1.0</small>
- [Colory](https://github.com/nabeghe/colory-php) <small>v0.1.0</small>
- [Dati](https://github.com/nabeghe/dati-php) <small>v0.3.1</small>
- [HeadersReader](https://github.com/nabeghe/headers-reader-php) <small>v1.0.0</small>
- [HeadersReader](https://github.com/nabeghe/headers-reader-php) <small>v1.0.1</small>
- [Levex](https://github.com/nabeghe/levex-php) <small>v1.0.1</small>
- [Matcher](https://github.com/nabeghe/matcher-php)<small> v1.0.0</small>
- [Mem](https://github.com/nabeghe/mem-php) <small>v1.0.0</small>
Expand Down
14 changes: 10 additions & 4 deletions src/HeadersReader/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,38 @@ protected static function init()
{
if (!isset(static::$headers)) {
$headers = getallheaders();
if (!is_array($headers)) {
if (is_array($headers)) {
$headers = array_change_key_case($headers);
} else {
$headers = [];
}

static::$headers = $headers;
}
}

public static function all(): array
{
static::init();

return static::$headers;
}

public static function get($name, $default = null)
{
static::init();

if (isset(static::$headers[$name])) {
return static::$headers[$name];
$lower_name = strtolower($name);

if (isset(static::$headers[$lower_name])) {
return static::$headers[$lower_name];
}

if (func_num_args() > 1) {
return $default;
}

return static::DEFAULTS[$name] ?? static::DEFAULT;
return static::DEFAULTS[$lower_name] ?? static::DEFAULTS[$name] ?? static::DEFAULT;
}

public static function flush()
Expand Down

0 comments on commit decfb6f

Please sign in to comment.