Beispiel #1
0
 /**
  * Constructor
  *
  * @author Art <*****@*****.**>
  *
  * @param int|array $typeOrData The error code or array of error_get_last()
  * @param string    $message    The error message
  * @param string    $file       The error file
  * @param int       $line       The error line
  */
 public function __construct($typeOrData, $message = null, $file = null, $line = null)
 {
     if (empty($typeOrData)) {
         parent::__construct(['type' => null, 'message' => null, 'file' => null, 'line' => null]);
     } else {
         if (is_array($typeOrData)) {
             $message = Alo::get($typeOrData['message']);
             $file = Alo::get($typeOrData['file']);
             $line = Alo::get($typeOrData['line']);
             $typeOrData = Alo::get($typeOrData['type']);
         }
         if (!is_numeric($typeOrData)) {
             $typeOrData = null;
         }
         parent::__construct(['type' => $typeOrData, 'message' => $message, 'file' => $file, 'line' => $line]);
     }
 }
Beispiel #2
0
 /**
  * Formats the timeout
  *
  * @author Art <*****@*****.**>
  *
  * @param int|DateTimeInterface $timeout The timeout
  *
  * @return bool false if an error occurred
  * @since  1.0.2 Uses DateTimeInterface instead of DateTime
  */
 private function formatTimeout(&$timeout = null)
 {
     if ($timeout instanceof DateTimeInterface) {
         $time = time();
         $timeout = $timeout->getTimestamp();
         if ($time > $timeout) {
             trigger_error('The timeout cannot be in the past', E_USER_WARNING);
             //@codeCoverageIgnoreStart
             return false;
             //@codeCoverageIgnoreEnd
         } else {
             $timeout = $timeout - $time;
         }
     } else {
         $timeout = Alo::ifnull($timeout, $this->config->timeout, true);
     }
     return true;
 }
 /**
  * Constructor
  *
  * @author Art <*****@*****.**>
  *
  * @param LoggerInterface $logger If provided, this will be used to log errors and exceptions.
  * @param AbstractConfig  $cfg    The configuration class. Required.
  *
  * @since  1.4 $cfg added. This will become the first parameter in the constructor in 2.0
  */
 public function __construct(LoggerInterface $logger = null, AbstractConfig $cfg = null)
 {
     if (!$logger) {
         $logger = new Log();
     }
     $this->config = Alo::ifnull($cfg, new AbstractConfig());
     $this->logger = $logger;
     $this->isCLI = !$this->config->forceHTML && Alo::isCliRequest();
     $this->initSymfony();
 }
Beispiel #4
0
 /**
  * The error handler
  *
  * @author Art <*****@*****.**>
  *
  * @param int    $errno   The level of the error raised
  * @param string $errstr  The error message
  * @param string $errfile The filename that the error was raised in
  * @param int    $errline The line number the error was raised at
  *
  * @since  1.2 Tracks the last reported error
  * @codeCoverageIgnore
  */
 public function handle($errno, $errstr, $errfile, $errline)
 {
     self::$lastReported = new Error($errno, $errstr, $errfile, $errline);
     $this->injectCSS();
     $type = Alo::ifnull(Error::$map[$errno], $errno);
     $label = 'danger';
     switch ($errno) {
         case E_NOTICE:
         case E_USER_NOTICE:
             $label = 'info';
             break;
         case E_DEPRECATED:
         case E_USER_DEPRECATED:
         case E_WARNING:
         case E_USER_WARNING:
         case E_STRICT:
         case E_CORE_WARNING:
             $label = 'warning';
     }
     $file = implode(DIRECTORY_SEPARATOR, array_slice(explode(DIRECTORY_SEPARATOR, $errfile), -2));
     if (!$errline) {
         $errline = '<<unknown>>';
     }
     if ($this->isCLI) {
         $label = $label == 'danger' ? 'e' : substr($label, 0, 1);
         $this->handleCLI($type, $label, $errno, $errstr, $file, $errline);
     } else {
         $this->handleHTML($type, $label, $errno, $errstr, $file, $errline);
     }
     $this->log($errno, $errstr, $errfile, $errline);
 }
Beispiel #5
0
 /**
  * Returns the debug backtrace
  *
  * @author Art <*****@*****.**>
  * @return array
  * @since  1.3
  */
 protected function getBacktrace()
 {
     $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
     if (empty($trace)) {
         // @codeCoverageIgnoreStart
         return [];
         // @codeCoverageIgnoreEnd
     } else {
         foreach ($trace as $k => $v) {
             foreach (self::$ignoredFiles as $i) {
                 if (stripos(Alo::ifnull($v['file'], ''), $i) !== false) {
                     unset($trace[$k]);
                     break;
                 }
             }
         }
     }
     return array_values($trace);
 }
 /**
  * Send our request
  *
  * @author Art <*****@*****.**>
  *
  * @param string $httpMethod The HTTP method to use (GET, POST etc)
  * @param string $url        The URL to call. This is automatically prepended with https:// in this method
  * @param array  $options    Request options
  *
  * @return \GuzzleHttp\Promise\PromiseInterface|\Psr\Http\Message\ResponseInterface The promise interface if
  *                                                                                  async is set to true and the
  *                                                                                  request interface if it is
  *                                                                                  set to false
  * @throws \GuzzleHttp\Exception\ClientException
  */
 protected final function sendAbstract($httpMethod, $url, array $options = [])
 {
     return call_user_func($this->sendCallable, new Request($httpMethod, 'https://' . $url, array_merge(['authorization' => 'Bearer ' . $this->token], Alo::ifnull($options['headers'], [], true)), Alo::nullget($options['body'])));
 }
 /**
  * The shutdown handler
  *
  * @author Art <*****@*****.**>
  * @since  1.2.1 Should now report fatal errors if no errors had been raised beforehand.
  * @codeCoverageIgnore
  */
 public function handle()
 {
     if (ErrorHandler::isRegistered()) {
         $e = new Error(error_get_last());
         if (Error::shouldBeReported($e->getType())) {
             $r = ErrorHandler::getLastReportedError();
             $h = ErrorHandler::getLastRegisteredHandler();
             if (!$e->isEmpty() && $h && ($r ? !$r->isEmpty() && !$r->equals($e) : true)) {
                 $h->handle($e->getType(), Alo::ifnull($e->getMessage(), '<<unknown error>>'), Alo::ifnull($e->getFile(), '<<unknown file>>'), Alo::ifnull($e->getLine(), '<<unknown line>>'));
             }
         }
     }
 }
Beispiel #8
0
 /**
  * Returns a configuration item or NULL if it's not set
  *
  * @author Art <*****@*****.**>
  *
  * @param string $k The configuration item key
  *
  * @return mixed
  */
 public function get($k)
 {
     return Alo::get($this->merged[$k]);
 }
Beispiel #9
0
 /**
  * Gets a token and removes it from the session
  *
  * @author Art <*****@*****.**>
  *
  * @return mixed|null The token
  */
 public function getAndRemove()
 {
     if (!Sess::isActive()) {
         self::sessionRequiredWarning(__METHOD__);
         // @codeCoverageIgnoreStart
         return null;
         // @codeCoverageIgnoreEnd
     }
     $tok = Alo::nullget($_SESSION[$this->tokenKey][$this->name]);
     $this->remove();
     return $tok;
 }
 /**
  * Checks if the session should be saved/written
  *
  * @author Art <*****@*****.**>
  * @return bool
  * @since  1.1
  */
 protected function shouldBeSaved()
 {
     $isCli = Alo::isCliRequest();
     return !$isCli || $isCli && $this->config->saveCLI;
 }
Beispiel #11
0
 /**
  * Offset to retrieve
  *
  * @author Art <*****@*****.**>
  * @see    http://php.net/manual/en/arrayaccess.offsetget.php
  *
  * @param string $offset The offset to retrieve.
  *
  * @return mixed Can return all value types.
  */
 public function offsetGet($offset)
 {
     return Alo::get($this->options[$offset]);
 }
 /**
  * Constructor
  *
  * @author Art <*****@*****.**>
  *
  * @param LoggerInterface $logger If provided, this will be used to log exceptions.
  * @param ExceptionConfig $cfg    The configuration class
  *
  * @since  1.4 $cfg added. This will become the first parameter in the constructor in 2.0
  */
 public function __construct(LoggerInterface $logger = null, ExceptionConfig $cfg = null)
 {
     parent::__construct($logger, Alo::ifnull($cfg, new ExceptionConfig()));
 }