Move utility functions to the utility class, fix #351

This commit is contained in:
Denis Sokolov
2015-12-20 18:44:38 +02:00
parent eb1ce6439d
commit 083d5a674e
4 changed files with 23 additions and 35 deletions
+1 -4
View File
@@ -25,10 +25,7 @@
"autoload": {
"psr-4": {
"Whoops\\": "src/Whoops/"
},
"files": [
"src/Whoops/functions.php"
]
}
},
"extra": {
"branch-alias": {
+6 -6
View File
@@ -13,8 +13,8 @@
- [`Whoops\Handler\PrettyPageHandler`](#handler-pretty) - Outputs a detailed, fancy error page
### Core Functions:
- [`Whoops\isAjaxRequest()`](#fn-ajax) - Determines whether the current request was triggered by XMLHttpRequest
- [`Whoops\isCommandLine()`](#fn-cli) - Determines whether the current request was triggered via php commandline interface (CLI)
- [`Whoops\Util\Misc::isAjaxRequest()`](#fn-ajax) - Determines whether the current request was triggered by XMLHttpRequest
- [`Whoops\Util\Misc::isCommandLine()`](#fn-cli) - Determines whether the current request was triggered via php commandline interface (CLI)
# Core Classes:
@@ -407,22 +407,22 @@ PrettyPageHandler::handle()
# Core Functions:
## <a name="fn-ajax"></a> `Whoops\isAjaxRequest()`
## <a name="fn-ajax"></a> `Whoops\Util\Misc::isAjaxRequest()`
#=> boolean
```php
// Use a certain handler only in AJAX triggered requests
if (Whoops\isAjaxRequest()){
if (Whoops\Util\Misc::isAjaxRequest()){
$run->addHandler($myHandler)
}
```
## <a name="fn-cli"></a> `Whoops\isCommandLine()`
## <a name="fn-cli"></a> `Whoops\Util\Misc::isCommandLine()`
#=> boolean
```php
// Use a certain handler only in php cli
if (Whoops\isCommandLine()){
if (Whoops\Util\Misc::isCommandLine()){
$run->addHandler($myHandler)
}
```
+16
View File
@@ -23,6 +23,22 @@ class Misc
return isset($_SERVER["REQUEST_URI"]) && !headers_sent();
}
public static function isAjaxRequest()
{
return (
!empty($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
}
/**
* Check, if possible, that this execution was triggered by a command line.
* @return bool
*/
public static function isCommandLine()
{
return PHP_SAPI == 'cli';
}
/**
* Translate ErrorException code into the represented constant.
*
-25
View File
@@ -1,25 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: staabm
* Date: 21.11.2015
* Time: 16:08
*/
namespace Whoops;
function isAjaxRequest()
{
return (
!empty($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
}
/**
* Check, if possible, that this execution was triggered by a command line.
* @return bool
*/
function isCommandLine()
{
return PHP_SAPI == 'cli';
}