Skip to content

Commit e26683f

Browse files
committed
Servery 0.3.0
1 parent 5d96499 commit e26683f

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Includes the following helpers:
1515
- [Matcher](https://github.com/nabeghe/matcher-php)<small> v1.0.0</small>
1616
- [Mem](https://github.com/nabeghe/mem-php) <small>v1.2.0</small>
1717
- [Reflecty](https://github.com/nabeghe/reflecty-php) <small>v0.5.2</small>
18-
- [Servery](https://github.com/nabeghe/servery-php) <small>v0.2.2</small>
18+
- [Servery](https://github.com/nabeghe/servery-php) <small>v0.3.0</small>
1919
- [Shortnum](https://github.com/nabeghe/shortnum-php) <small>v1.0.0</small>
2020
- [SimpleCipher](https://github.com/nabeghe/simple-cipher-php) <small>v1.0.0</small>
2121
- [Stringer](https://github.com/nabeghe/stringer-php) <small>v1.1.4</small>
@@ -40,4 +40,4 @@ composer require nabeghe/helpers
4040

4141
## 📖 License
4242

43-
Licensed under the MIT license, see [LICENSE.md](LICENSE.md) for details.
43+
Licensed under the MIT license, see [LICENSE.md](LICENSE.md) for details.

src/Servery/Servery.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,36 @@ public static function isLocalHost(): bool
5555
return $result = false;
5656
}
5757

58+
/**
59+
* Check if the current execution is in a terminal environment.
60+
*
61+
* @return bool
62+
*/
63+
public static function isTerminal(): bool
64+
{
65+
return in_array(PHP_SAPI, ['cli', 'phpdbg'], true);
66+
}
67+
68+
/**
69+
* Determine if the current execution is handling an HTTP request.
70+
*
71+
* @return bool
72+
*/
73+
public static function isRequest(): bool
74+
{
75+
return !static::isTerminal() && isset($_SERVER['REQUEST_METHOD']) && PHP_SAPI !== 'embed';
76+
}
77+
78+
/**
79+
* Check if the current HTTP request may contain a body.
80+
*
81+
* @return bool
82+
*/
83+
public static function hasRequestBody(): bool
84+
{
85+
return static::isRequest() && in_array(strtoupper($_SERVER['REQUEST_METHOD']), ['POST', 'PUT', 'PATCH'], true);
86+
}
87+
5888
/**
5989
* @return string
6090
*/
@@ -287,7 +317,6 @@ public static function getRequestedUrl(): string
287317
return static::getCurrentUrl();
288318
}
289319

290-
291320
/**
292321
* Returns the requested path, using `$_SERVER['SCRIPT_FILENAME']`.
293322
*
@@ -359,4 +388,4 @@ public static function getUserAgentValue(): string
359388
{
360389
return UserAgent::getCurrentReal();
361390
}
362-
}
391+
}

0 commit comments

Comments
 (0)