Skip to content

Instantly share code, notes, and snippets.

@clsource
Created December 8, 2015 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clsource/ba10c6ea770e520b24bc to your computer and use it in GitHub Desktop.
Save clsource/ba10c6ea770e520b24bc to your computer and use it in GitHub Desktop.
Processwire Debug Helper
<?php
/**
* Copyright (c) 2015 - CLSource
* Helps with the debug log.
* see: https://processwire.com/talk/topic/4550-debugging-tips/
*
* @author : clsource <camilo@ninjas.cl>
* @license : MIT https://opensource.org/licenses/MIT
*
* usage:
*
* ```php
* require_once 'Debug.php';
* Debug::init();
* Debug::log($myVar);
* Debug::log($myArray);
* ```
*/
class Debug {
protected static $name = 'debug';
public static function init() {
if(!file_exists(self::filename())) {
self::log('Debug File Init');
}
}
public static function log($param) {
if (is_array($param)) {
$param = json_encode($param);
}
wire('log')->save(self::$name, $param);
}
public static function filename() {
return wire('log')->getFilename(self::$name);
}
public static function name() {
return self::$name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment