Skip to content

Commit

Permalink
constants, log etc
Browse files Browse the repository at this point in the history
  • Loading branch information
raghuveer committed Feb 25, 2024
1 parent ebb2e0e commit c203c12
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Other/EAConstants.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);

namespace EaseAppPHP\Other;

use \Illuminate\Container\Container;

use \Monolog\Logger;
use \Monolog\Handler\StreamHandler;
use \Monolog\Handler\FirePHPHandler;

/**
* EAConstants Class
*/

final class EAConstants
{
// see https://tldp.org/LDP/abs/html/exitcodes.html
public const CLI_RESPONSE_SUCCESS = 0;
public const CLI_RESPONSE_FAILURE = 1;
public const CLI_RESPONSE_INVALID = 2;
}
196 changes: 196 additions & 0 deletions src/Other/Log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<?php
declare(strict_types=1);

namespace EaseAppPHP\Other;

use \Illuminate\Container\Container;

use \Monolog\Logger;
use \Monolog\Handler\StreamHandler;
use \Monolog\Handler\FirePHPHandler;

/**
* Log Class
* Sample Usage:
* Log::channel($container, 'single')->info('Something happened!');
*/

class Log
{
protected static $container;
protected static $config;
protected static $logger;
protected $response;

/**
* Write Log to specific channel
*
*/
public static function channel(Container $container, $channel)
{
self::$container = $container;
self::$config = self::$container->get('config');

foreach (self::$config as $key => $value)
{
if ($key == "logging") {

foreach ($value as $key1 => $value1)
{
if ($key1 == "channels") {

foreach ($value1 as $key2 => $value2)
{

if ($key2 == $channel) {

// Create some handlers
$stream = new StreamHandler($value2["path"], Logger::DEBUG);
$firephp = new FirePHPHandler();

// Create the main logger of the app
self::$logger = new Logger($channel);
self::$logger->pushHandler($stream);
self::$logger->pushHandler($firephp);

}
}

}
}

}
}

return new self;

}

/**
* Write Log to on-demand channel stack
*
*/
/* public static function stack()
{
self::$container = $container;
self::$config = self::$container->get('config');
foreach (self::$config as $key => $value)
{
if ($key == "logging") {
foreach ($value as $key1 => $value1)
{
if ($key1 == "channels") {
foreach ($value1 as $key2 => $value2)
{
if (($key2 == "stack") && ($key2 == $channel)) {
foreach ($value2 as $key3 => $value3)
{
if ($key3 == "channels") {
var_dump($value3);
}
}
}
}
}
}
}
}
return new self;
} */

/**
* Write Log to on-demand channel configuration at runtime
*
*/
/* public static function build()
{
} */

/**
* Writes message to logging destination
*
*/
public static function debug($message)
{
self::$logger->debug($message);
}

/**
* Writes message to logging destination
*
*/
public static function info($message)
{
self::$logger->info($message);
}

/**
* Writes message to logging destination
*
*/
public static function notice($message)
{
self::$logger->notice($message);
}

/**
* Writes message to logging destination
*
*/
public static function warning($message)
{
self::$logger->warning($message);
}

/**
* Writes message to logging destination
*
*/
public static function error($message)
{
self::$logger->error($message);
}

/**
* Writes message to logging destination
*
*/
public static function critical($message)
{
self::$logger->critical($message);
}

/**
* Writes message to logging destination
*
*/
public static function alert($message)
{
self::$logger->alert($message);
}

/**
* Writes message to logging destination
*
*/
public static function emergency($message)
{
self::$logger->emergency($message);
}

}
1 change: 1 addition & 0 deletions src/Other/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><title></title>

0 comments on commit c203c12

Please sign in to comment.