Skip to content

Instantly share code, notes, and snippets.

@clsource
Created Dec 8, 2015
Embed
What would you like to do?
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