Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to php 7.4 #1

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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