Skip to content

Commit

Permalink
Merge pull request #1 from p4it-kft/php74update
Browse files Browse the repository at this point in the history
update to php 7.4
  • Loading branch information
papppeter authored Mar 19, 2021
2 parents 2ebd36a + 75d860b commit 1623ba3
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 235 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ return [
'stream' => '/runtime/app.log',
'formatter' => 'Monolog\Formatter\LineFormatter',
],
static function () {
/** @var StreamHandler $stream */
$stream = Yii::createComponent([
'class' => RotatingFileHandler::class,
],
Yii::app()->runtimePath.'/application.log', 10);

$formatter = Yii::createComponent([
'class' => LineFormatter::class,
]);

$stream->setFormatter($formatter);

return $stream;
}
],
'processors' => [
'Monolog\Processor\ProcessIdProcessor',
Expand Down
17 changes: 12 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "fidelize/yii-monolog",
"name": "p4it-kft/yii-monolog",
"description": "Extension for using monolog with yii 1.x",
"keywords": ["monolog", "yii", "log", "error", "exception", "debug", "monitoring"],
"type": "package",
Expand All @@ -24,15 +24,22 @@
"name": "Leonardo Gomes",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "P4IT Kft",
"homepage": "https://www.p4it.hu",
"role": "Company"
},
{
"name": "Papp Péter",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": ">=5.4",
"php": ">=7.4",
"monolog/monolog": "*"
},
"require-dev": {
"phpunit/phpunit": "*"
},
"autoload": {
"psr-4": {
"YiiMonolog\\": "src"
Expand Down
82 changes: 45 additions & 37 deletions src/MonologComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@

namespace YiiMonolog;

use CApplicationComponent;
use CException;
use Closure;
use Exception;
use Monolog\Formatter\FormatterInterface;
use Monolog\Handler\HandlerInterface;
use Monolog\Logger;
use Monolog\Registry;
use Monolog\Handler\HandlerInterface;
use Monolog\Formatter\FormatterInterface;
use RuntimeException;
use Yii;

class MonologComponent extends \CApplicationComponent
class MonologComponent extends CApplicationComponent
{
/** @var string */
public $name = 'application';
/** @var string */
public $loggerName = 'main';
/** @var array */
public $handlers = [];
/** @var array */
public $processors = [];
public string $name = 'application';
public string $loggerName = 'main';
public array $handlers = [];
public array $processors = [];

/**
* @inheritdoc
* @throws RuntimeException
* @throws RuntimeException|CException
*/
public function init()
{
Expand All @@ -40,13 +42,17 @@ public function init()
}

/**
* @param string|array $config
* @param string|array $config
*
* @throws RuntimeException
* @return HandlerInterface
* @throws RuntimeException|CException
*/
protected function createHandler($config)
protected function createHandler($config): HandlerInterface
{
if ($config instanceof Closure) {
return $config();
}

if (isset($config['formatter'])) {
$formatterConfig = $config['formatter'];
unset($config['formatter']);
Expand All @@ -56,7 +62,7 @@ protected function createHandler($config)
if (is_array($config)) {
$instance = call_user_func_array(['Yii', 'createComponent'], $config);
} else {
$instance = \Yii::createComponent($config);
$instance = Yii::createComponent($config);
}

if (isset($formatterConfig)) {
Expand All @@ -68,42 +74,44 @@ protected function createHandler($config)
}

/**
* @param array|string $config
* @param string|array $config
*
* @return FormatterInterface
* @throws CException
*/
protected function createFormatter($config): FormatterInterface
{
if (is_array($config)) {
$instance = call_user_func_array(['Yii', 'createComponent'], $config);
} else {
$instance = Yii::createComponent($config);
}

return $instance;
}

/**
* @param array|string $config
*
* @throws RuntimeException
* @return Closure
* @throws RuntimeException
*/
protected function createProcessor($config)
protected function createProcessor($config): callable
{
try {
if (is_array($config)) {
$instance = call_user_func_array(['Yii', 'createComponent'], $config);
} else {
$instance = \Yii::createComponent($config);
$instance = Yii::createComponent($config);
}
if (is_callable($instance)) {
return $instance;
}
} catch(Exception $exception) {}
} catch (Exception $exception) {
}

throw new RuntimeException(
'Unknown processor type, must be a Closure or a valid config for an invokable component'
);
}

/**
* @param string|array $config
*
* @return FormatterInterface
*/
protected function createFormatter($config)
{
if (is_array($config)) {
$instance = call_user_func_array(['Yii', 'createComponent'], $config);
} else {
$instance = \Yii::createComponent($config);
}

return $instance;
}
}
12 changes: 5 additions & 7 deletions src/MonologErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace YiiMonolog;

use Monolog\Registry;
use CErrorHandler;
use Monolog\ErrorHandler;
use Monolog\Registry;

class MonologErrorHandler extends \CErrorHandler
class MonologErrorHandler extends CErrorHandler
{
/** @var string */
public $loggerName = 'main';
/** @var Monolog\ErrorHandler */
protected $errorHandler;
public string $loggerName = 'main';
protected ErrorHandler $errorHandler;

/**
* @inheritdoc
Expand All @@ -30,7 +29,6 @@ public function init()
*/
protected function handleException($e)
{
$this->errorHandler->handleException($e);
parent::handleException($e);
}

Expand Down
Loading

0 comments on commit 1623ba3

Please sign in to comment.