mirror of
https://github.com/filp/whoops.git
synced 2026-09-16 04:36:20 +00:00
Move utility functions to the utility class, fix #351
This commit is contained in:
+1
-4
@@ -25,10 +25,7 @@
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Whoops\\": "src/Whoops/"
|
||||
},
|
||||
"files": [
|
||||
"src/Whoops/functions.php"
|
||||
]
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
```
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
Reference in New Issue
Block a user