Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ## Remember to define the debug constant accordingly
- ## For dev and local enviroments:
- define('API_DEBUG_MODE', TRUE);
- ## For live environments DO NOT DEFINE THE CONSTANT
- /**
- * Reducing code smells and making more readable;
- * Usage:
- * Replace
- * if($value === false){ ... }
- * with
- * if(isFalse($value)){ ... }
- *
- * @param mixed $value
- * @author Shaun B
- * @date 4 Jul 2018 16:28:20
- * @return bool
- */
- function isFalse($value = false): bool
- {
- return (bool) ($value === FALSE) ? 1 : 0;
- }
- /**
- * Reducing code smells and making more readable;
- * Usage:
- * Replace
- * if($value === true){ ... }
- * with
- * if(isTrue($value)){ ... }
- *
- * @param mixed $value
- * @author Shaun B
- * @date 4 Jul 2018 16:29:27
- * @return boolean
- */
- function isTrue($value = true): bool
- {
- return (bool) ($value === TRUE) ? 1 : 0;
- }
- /**
- * Generic debug to see the contents of an object, resource or scalar
- * Not intended to be deployed live
- *
- * @param mixed $value
- * @param bool $die
- * @param string $message
- * @param string $file
- * @param string $line
- * @param string $header
- * @author Shaun B
- * @date 3 Apr 2018 13:37:42
- * @return void
- */
- function debug($value = null, bool $die = false, string $message = null, string $file = null, string $line = null, string $header = null): void
- {
- if (isTrue(defined('API_DEBUG_MODE'))) {
- $openDiv = '<div>';
- $closeDiv = '</div>';
- $openPre = '<pre>';
- $closePre = '</pre>';
- echo (strlen($header) > 0) ? "{$openDiv}<h1>{$header}</h1>" : "";
- echo $openPre . print_r($value, true) . $closePre;
- echo (! empty($file)) ? $openPre . 'File: ' . print_r($file, true) . $closePre : "";
- echo (! empty($line)) ? $openPre . 'Line: ' . print_r($line, true) . $closePre : "";
- echo (strlen($header) > 0) ? "{$closeDiv}" : "";
- if ($die === true) {
- die($message ?? '');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement