Skip to content

Commit

Permalink
fix PHP 7.x compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Jul 18, 2023
1 parent b0e5c8b commit e6f13d7
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 44 deletions.
37 changes: 9 additions & 28 deletions src/PsrLogger.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
<?php

namespace yii1tech\psr\log;
/**
* Splits actual class declaration into 2 separated branches, allowing support both PHP 8.x and PHP 7.x.
* This is necessary since {@see \Psr\Log\LoggerInterface} changes signature over different PHP versions.
*
* @author Paul Klimov <[email protected]>
* @since 1.0
*/

if (version_compare(phpversion(), '8.0', '>=')) {
/**
* {@inheritdoc}
*/
class PsrLogger extends AbstractPsrLogger
{
/**
* {@inheritdoc}
*/
public function log($level, string|\Stringable $message, array $context = []): void
{
$this->writeLog($level, $message, $context);
}
}
require __DIR__ . '/compatibility/PsrLogger.v8.php';
} else {
/**
* {@inheritdoc}
*/
class PsrLogger extends AbstractPsrLogger
{
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = []): void
{
$this->writeLog($level, $message, $context);
}
}
require __DIR__ . '/compatibility/PsrLogger.v7.php';
}
17 changes: 17 additions & 0 deletions src/compatibility/PsrLogger.v7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace yii1tech\psr\log;

/**
* {@inheritdoc}
*/
class PsrLogger extends AbstractPsrLogger
{
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = []): void
{
$this->writeLog($level, $message, $context);
}
}
17 changes: 17 additions & 0 deletions src/compatibility/PsrLogger.v8.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace yii1tech\psr\log;

/**
* {@inheritdoc}
*/
class PsrLogger extends AbstractPsrLogger
{
/**
* {@inheritdoc}
*/
public function log($level, string|\Stringable $message, array $context = []): void
{
$this->writeLog($level, $message, $context);
}
}
18 changes: 2 additions & 16 deletions tests/support/ArrayLogger.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
<?php

namespace yii1tech\psr\log\test\support;

if (version_compare(phpversion(), '8.0', '>=')) {
class ArrayLogger extends AbstractArrayLogger
{
public function log($level, string|\Stringable $message, array $context = []): void
{
$this->writeLog($level, $message, $context);
}
}
require __DIR__ . '/compatibility/ArrayLogger.v8.php';
} else {
class ArrayLogger extends AbstractArrayLogger
{
public function log($level, $message, array $context = []): void
{
$this->writeLog($level, $message, $context);
}
}
require __DIR__ . '/compatibility/ArrayLogger.v7.php';
}
19 changes: 19 additions & 0 deletions tests/support/compatibility/ArrayLogger.v7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace yii1tech\psr\log\test\support;

use yii1tech\psr\log\test\support\AbstractArrayLogger;

/**
* {@inheritdoc}
*/
class ArrayLogger extends AbstractArrayLogger
{
/**
* {@inheritdoc}
*/
public function log($level, $message, array $context = []): void
{
$this->writeLog($level, $message, $context);
}
}
19 changes: 19 additions & 0 deletions tests/support/compatibility/ArrayLogger.v8.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace yii1tech\psr\log\test\support;

use yii1tech\psr\log\test\support\AbstractArrayLogger;

/**
* {@inheritdoc}
*/
class ArrayLogger extends AbstractArrayLogger
{
/**
* {@inheritdoc}
*/
public function log($level, string|\Stringable $message, array $context = []): void
{
$this->writeLog($level, $message, $context);
}
}

0 comments on commit e6f13d7

Please sign in to comment.