2017-07-03 20:28:17 +03:00
|
|
|
<?php
|
|
|
|
namespace GraphQL\Error;
|
|
|
|
|
|
|
|
final class Warning
|
|
|
|
{
|
2017-07-04 13:10:55 +03:00
|
|
|
const NAME_WARNING = 1;
|
|
|
|
const ASSIGN_WARNING = 2;
|
|
|
|
const CONFIG_WARNING = 4;
|
|
|
|
|
2017-07-04 18:18:55 +03:00
|
|
|
const ALL = 7;
|
2017-07-04 13:10:55 +03:00
|
|
|
|
|
|
|
static $enableWarnings = self::ALL;
|
2017-07-03 20:28:17 +03:00
|
|
|
|
|
|
|
static $warned = [];
|
|
|
|
|
2017-07-04 13:10:55 +03:00
|
|
|
static function suppress($suppress = true)
|
2017-07-03 20:28:17 +03:00
|
|
|
{
|
2017-07-04 13:10:55 +03:00
|
|
|
if (true === $suppress) {
|
|
|
|
self::$enableWarnings = 0;
|
|
|
|
} else if (false === $suppress) {
|
|
|
|
self::$enableWarnings = self::ALL;
|
|
|
|
} else {
|
|
|
|
$suppress = (int) $suppress;
|
|
|
|
self::$enableWarnings &= ~$suppress;
|
|
|
|
}
|
2017-07-03 20:28:17 +03:00
|
|
|
}
|
|
|
|
|
2017-07-04 13:10:55 +03:00
|
|
|
static function warnOnce($errorMessage, $warningId)
|
2017-07-03 20:28:17 +03:00
|
|
|
{
|
2017-07-04 13:10:55 +03:00
|
|
|
if ((self::$enableWarnings & $warningId) > 0 && !isset(self::$warned[$warningId])) {
|
|
|
|
self::$warned[$warningId] = true;
|
|
|
|
trigger_error($errorMessage, E_USER_WARNING);
|
|
|
|
}
|
|
|
|
}
|
2017-07-03 20:28:17 +03:00
|
|
|
|
2017-07-04 13:10:55 +03:00
|
|
|
static function warn($errorMessage, $warningId)
|
|
|
|
{
|
|
|
|
if ((self::$enableWarnings & $warningId) > 0) {
|
2017-07-03 20:28:17 +03:00
|
|
|
trigger_error($errorMessage, E_USER_WARNING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|