renaming for composer

This commit is contained in:
Administrator
2024-08-09 04:08:24 +00:00
parent bfe714b179
commit 8f140bee75
7 changed files with 4 additions and 4 deletions

119
Classes/Logger.php Normal file
View File

@ -0,0 +1,119 @@
<?php
/**
* logger.php
*
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
*/
namespace TheTempusProject\Canary\Classes;
class Logger {
public $file;
public $logDirectory;
public $logFilePath;
public function __construct() {
$this->setupLogFile();
$this->file = fopen( $this->logFilePath, 'a' );
fwrite( $this->file, '===================------++++++++++------===================' . PHP_EOL );
}
public function setupLogFile() {
$this->logDirectory = rtrim( CANARY_DEBUG_DIRECTORY, DIRECTORY_SEPARATOR );
if ( ! is_dir( $this->logDirectory ) ) {
mkdir( $this->logDirectory, 0777, true );
}
$currentFile = date('m-d-Y') . '.log';
$this->logFilePath = $this->logDirectory . DIRECTORY_SEPARATOR . $currentFile;
if ( ! file_exists( $this->logFilePath ) ) {
touch( $this->logFilePath );
chmod( $this->logFilePath, 0777 );
}
}
public function __destruct() {
fwrite( $this->file, '============================================================' . PHP_EOL );
fclose( $this->file );
}
public function addLog( $type = 'log', $log ) {
switch ( CANARY_DEBUG_TO_FILE_LEVEL ) {
case CANARY_DEBUG_LEVEL_ERROR:
$acceptableLoggingLevels = [
CANARY_DEBUG_LEVEL_ERROR,
];
if (! in_array( $type, $acceptableLoggingLevels )) {
return;
}
break;
case CANARY_DEBUG_LEVEL_WARN:
$acceptableLoggingLevels = [
CANARY_DEBUG_LEVEL_ERROR,
CANARY_DEBUG_LEVEL_WARN,
];
if (! in_array( $type, $acceptableLoggingLevels )) {
return;
}
break;
case CANARY_DEBUG_LEVEL_INFO:
$acceptableLoggingLevels = [
CANARY_DEBUG_LEVEL_ERROR,
CANARY_DEBUG_LEVEL_WARN,
CANARY_DEBUG_LEVEL_INFO,
];
if (! in_array( $type, $acceptableLoggingLevels )) {
return;
}
break;
case CANARY_DEBUG_LEVEL_LOG:
$acceptableLoggingLevels = [
CANARY_DEBUG_LEVEL_ERROR,
CANARY_DEBUG_LEVEL_WARN,
CANARY_DEBUG_LEVEL_INFO,
CANARY_DEBUG_LEVEL_LOG,
];
if (! in_array( $type, $acceptableLoggingLevels )) {
return;
}
break;
case CANARY_DEBUG_LEVEL_DEBUG:
$acceptableLoggingLevels = [
CANARY_DEBUG_LEVEL_ERROR,
CANARY_DEBUG_LEVEL_WARN,
CANARY_DEBUG_LEVEL_INFO,
CANARY_DEBUG_LEVEL_LOG,
CANARY_DEBUG_LEVEL_DEBUG,
];
if (! in_array( $type, $acceptableLoggingLevels )) {
return;
}
break;
default:
return;
}
$formattedMessage = $this->timestamp() . $this->typestamp( $type ) . $log . PHP_EOL;
fwrite( $this->file, $formattedMessage );
}
private function timestamp() {
$dateString = self::getReadableDate( time() );
return '['.$dateString.'] - ';
}
private function typestamp( $type ) {
$dateString = self::getReadableDate( time() );
return '[' . strtoupper( $type ) . '] - ';
}
public static function getReadableDate( $timestamp, $with_timezone = false ) {
if ( $with_timezone ) {
$date = new \DateTime();
$date->setTimestamp( $timestamp );
$timezone = new \DateTimeZone( self::getTimezone() );
$date->setTimezone( $timezone );
$formattedDate = $date->format('Y-m-d H:i:s');
return $formattedDate;
}
return date( 'Y-m-d H:i:s', $timestamp );
}
}

1130
Classes/TempusDebugger.php Normal file

File diff suppressed because it is too large Load Diff

213
Classes/TempusTools.php Normal file
View File

@ -0,0 +1,213 @@
<?php
/**
* tempus_tools.php
*
* This is an interface for the Tempus Debugger to interact with TempusTools
*
* @version 3.0
* @author Joey Kimsey <Joey@thetempusproject.com>
* @link https://TheTempusProject.com/TempusDebugger
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
namespace TheTempusProject\Canary\Classes;
if ( !class_exists( 'TempusDebugger', false ) ) {
require_once 'tempus_debugger.php';
}
/**
* Sends the given data to the TempusTools Chrome Extension.
* The data can be displayed in devtools.
*
* @param mixed $Object
* @return true
* @throws Exception
*/
function tt() {
$instance = TempusDebugger::getInstance( true );
$args = func_get_args();
return call_user_func_array( [ $instance, 'tt' ], $args );
}
class TempusTools {
/**
* Set an Insight console to direct all logging calls to
*
* @param object $console The console object to log to
* @return void
*/
public static function setLogToInsightConsole( $console ) {
TempusDebugger::getInstance( true )->setLogToInsightConsole( $console );
}
/**
* Enable and disable logging to TempusTools
*
* @param boolean $enabled TRUE to enable, FALSE to disable
* @return void
*/
public static function setEnabled( $enabled ) {
TempusDebugger::getInstance( true )->setEnabled( $enabled );
}
/**
* Check if logging is enabled
*
* @return boolean TRUE if enabled
*/
public static function getEnabled() {
return TempusDebugger::getInstance( true )->getEnabled();
}
/**
* Specify a filter to be used when encoding an object
*
* Filters are used to exclude object members.
*
* @param string $class The class name of the object
* @param array $filter An array or members to exclude
* @return void
*/
public static function setObjectFilter( $class, $filter ) {
TempusDebugger::getInstance( true )->setObjectFilter( $class, $filter );
}
/**
* Set some options for the library
*
* @param array $options The options to be set
* @return void
*/
public static function setOptions( $options ) {
TempusDebugger::getInstance( true )->setOptions( $options );
}
/**
* Get options for the library
*
* @return array The options
*/
public static function getOptions() {
return TempusDebugger::getInstance( true )->getOptions();
}
/**
* Log object to console
*
* @param mixed $object
* @return true
* @throws Exception
*/
public static function send() {
$args = func_get_args();
return call_user_func_array( [ TempusDebugger::getInstance( true ), 'tt' ], $args );
}
/**
* Start a group for following messages
*
* Options:
* Collapsed: [true|false]
* Color: [#RRGGBB|ColorName]
*
* @param string $name
* @param array $options OPTIONAL Instructions on how to log the group
* @return true
*/
public static function group( $name, $options = null ) {
return TempusDebugger::getInstance( true )->group( $name, $options );
}
/**
* Ends a group you have started before
*
* @return true
* @throws Exception
*/
public static function groupEnd() {
return self::send( null, null, TempusDebugger::GROUP_END );
}
/**
* Log object with label to the console
*
* @param mixes $object
* @param string $label
* @return true
* @throws Exception
*/
public static function log( $object, $label = null ) {
return self::send( $object, $label, TempusDebugger::LOG );
}
/**
* Log object with label to the console
*
* @param mixes $object
* @param string $label
* @return true
* @throws Exception
*/
public static function info( $object, $label = null ) {
return self::send( $object, $label, TempusDebugger::INFO );
}
/**
* Log object with label to the console
*
* @param mixes $object
* @param string $label
* @return true
* @throws Exception
*/
public static function warn( $object, $label = null ) {
return self::send( $object, $label, TempusDebugger::WARN );
}
/**
* Log object with label to the console
*
* @param mixes $object
* @param string $label
* @return true
* @throws Exception
*/
public static function error( $object, $label = null ) {
return self::send( $object, $label, TempusDebugger::ERROR );
}
/**
* Dumps key and variable to console
*
* @param string $key
* @param mixed $variable
* @return true
* @throws Exception
*/
public static function dump( $key, $variable ) {
return self::send( $variable, $key, TempusDebugger::DUMP );
}
/**
* Log a trace in the console
*
* @param string $label
* @return true
* @throws Exception
*/
public static function trace( $label ) {
return self::send( $label, TempusDebugger::TRACE );
}
/**
* Log a table in the console
*
* @param string $label
* @param string $table
* @return true
* @throws Exception
*/
public static function table( $label, $table ) {
return self::send( $table, $label, TempusDebugger::TABLE );
}
}