Debug log updates, error message updates on curl failure
Config setup works with null data if no data is set. Debugger is now launched in the AamzonIncentive class at the beginning Debugger id/debug flag set is now one static call Debugger methods all have proper PHPdoc documentationn added Fixed Client/Curl error messages to include the original error message too. Also made sure that a possible null endpoint is not throwing errors
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
// simple write all into an array that we can poll in the return group
|
||||
// to activate AmazonDebug::setDebug(true) must be called once
|
||||
|
||||
namespace Amazon\Debug;
|
||||
|
||||
@@ -10,11 +11,15 @@ class AmazonDebug
|
||||
private static $debug = false;
|
||||
private static $id = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public static function setId(?string $id = null): void
|
||||
/**
|
||||
* set the ID for current run
|
||||
* if debug is off, nothing will be set and id is null
|
||||
* This is run on setFlag, if debug is true
|
||||
*
|
||||
* @param string|null $id If not set, will default to uniqid() call
|
||||
* @return void
|
||||
*/
|
||||
private static function setId(?string $id = null): void
|
||||
{
|
||||
if (self::$debug === false) {
|
||||
return;
|
||||
@@ -25,24 +30,69 @@ class AmazonDebug
|
||||
self::$id = $id;
|
||||
}
|
||||
|
||||
public static function getId(): string
|
||||
/**
|
||||
* set the debug flag.
|
||||
* This is automatically run in Amazon\AmazonIncentives::__construct
|
||||
* No need to run manuall
|
||||
*
|
||||
* @param boolean $debug Can only be True or False
|
||||
* @param string|null $id If not set, will default to uniqid() call
|
||||
* @return void
|
||||
*/
|
||||
public static function setDebug(bool $debug, ?string $id = null): void
|
||||
{
|
||||
self::$debug = $debug;
|
||||
if (self::$debug === false) {
|
||||
return;
|
||||
}
|
||||
self::setId($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns current debug flag status
|
||||
*
|
||||
* @return boolean True if debug is on, False if debug is off
|
||||
*/
|
||||
public static function getDebug(): bool
|
||||
{
|
||||
return self::$debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the current set ID, can return null if debug is off
|
||||
*
|
||||
* @return string|null Current set ID for this log run
|
||||
*/
|
||||
public static function getId(): ?string
|
||||
{
|
||||
return self::$id;
|
||||
}
|
||||
|
||||
public static function setFlag(bool $debug): void
|
||||
{
|
||||
self::$debug = $debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* write a log entry
|
||||
* Data is as array key -> value
|
||||
* Will be pushed as new array entry int log
|
||||
* Main key is the set Id for this run
|
||||
*
|
||||
* @param array $data Any array data to store in the log
|
||||
* @return void
|
||||
*/
|
||||
public static function writeLog(array $data): void
|
||||
{
|
||||
if (self::$debug === false) {
|
||||
return;
|
||||
}
|
||||
self::$log[self::$id][] = $data;
|
||||
self::$log[self::getId()][] = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* get all logs written since first class run
|
||||
* or get all log entries for given ID
|
||||
*
|
||||
* @param string|null $id If set returns only this id logs
|
||||
* or empty array if not found
|
||||
* @return array Always array, empty if not data or not found
|
||||
*/
|
||||
public static function getLog(?string $id = null): array
|
||||
{
|
||||
if ($id === null) {
|
||||
|
||||
Reference in New Issue
Block a user