Skip to content

Commit 8e6aedc

Browse files
committed
CE-32868: Fixed the codebase to take a compatibility
1 parent cd42926 commit 8e6aedc

File tree

4 files changed

+56
-61
lines changed

4 files changed

+56
-61
lines changed

app/code/Magento/Developer/Model/Logger/Handler/Debug.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Developer\Model\Logger\Handler;
79

10+
use Exception;
811
use Magento\Config\Setup\ConfigOptionsList;
9-
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\App\DeploymentConfig;
1013
use Magento\Framework\App\State;
14+
use Magento\Framework\Exception\FileSystemException;
15+
use Magento\Framework\Exception\RuntimeException;
1116
use Magento\Framework\Filesystem\DriverInterface;
12-
use Magento\Framework\App\DeploymentConfig;
17+
use Magento\Framework\Logger\Handler\Debug as DebugHandler;
1318

1419
/**
1520
* Enable/disable debug logging based on the store config setting
1621
*/
17-
class Debug extends \Magento\Framework\Logger\Handler\Debug
22+
class Debug extends DebugHandler
1823
{
1924
/**
2025
* @var State
@@ -30,14 +35,14 @@ class Debug extends \Magento\Framework\Logger\Handler\Debug
3035
* @param DriverInterface $filesystem
3136
* @param State $state
3237
* @param DeploymentConfig $deploymentConfig
33-
* @param string $filePath
34-
* @throws \Exception
38+
* @param string|null $filePath
39+
* @throws Exception
3540
*/
3641
public function __construct(
3742
DriverInterface $filesystem,
3843
State $state,
3944
DeploymentConfig $deploymentConfig,
40-
$filePath = null
45+
?string $filePath = null
4146
) {
4247
parent::__construct($filesystem, $filePath);
4348

@@ -48,30 +53,34 @@ public function __construct(
4853
/**
4954
* @inheritdoc
5055
*/
51-
public function isHandling(array $record)
56+
public function isHandling(array $record): bool
5257
{
5358
if ($this->deploymentConfig->isAvailable()) {
54-
return
55-
parent::isHandling($record)
56-
&& $this->isLoggingEnabled();
59+
return parent::isHandling($record) && $this->isLoggingEnabled();
5760
}
5861

5962
return parent::isHandling($record);
6063
}
6164

6265
/**
63-
* Check that logging functionality is enabled.
66+
* Check that logging functionality is enabled
6467
*
6568
* @return bool
69+
* @throws FileSystemException
70+
* @throws RuntimeException
6671
*/
6772
private function isLoggingEnabled(): bool
6873
{
69-
$configValue = $this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_DEBUG_LOGGING);
74+
$configValue = $this->deploymentConfig->get(
75+
ConfigOptionsList::CONFIG_PATH_DEBUG_LOGGING
76+
);
77+
7078
if ($configValue === null) {
7179
$isEnabled = $this->state->getMode() !== State::MODE_PRODUCTION;
7280
} else {
73-
$isEnabled = (bool)$configValue;
81+
$isEnabled = (bool) $configValue;
7482
}
83+
7584
return $isEnabled;
7685
}
7786
}

lib/internal/Magento/Framework/Logger/Handler/Base.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Logger\Handler;
89

10+
use InvalidArgumentException;
911
use Magento\Framework\Filesystem\DriverInterface;
1012
use Monolog\Formatter\LineFormatter;
1113
use Monolog\Handler\StreamHandler;
@@ -33,19 +35,20 @@ class Base extends StreamHandler
3335

3436
/**
3537
* @param DriverInterface $filesystem
36-
* @param string $filePath
37-
* @param string $fileName
38-
* @throws \Exception
38+
* @param string|null $filePath
39+
* @param string|null $fileName
3940
*/
4041
public function __construct(
4142
DriverInterface $filesystem,
42-
$filePath = null,
43-
$fileName = null
43+
?string $filePath = null,
44+
?string $fileName = null
4445
) {
4546
$this->filesystem = $filesystem;
47+
4648
if (!empty($fileName)) {
4749
$this->fileName = $this->sanitizeFileName($fileName);
4850
}
51+
4952
parent::__construct(
5053
$filePath ? $filePath . $this->fileName : BP . DIRECTORY_SEPARATOR . $this->fileName,
5154
$this->loggerType
@@ -59,14 +62,9 @@ public function __construct(
5962
*
6063
* @param string $fileName
6164
* @return string
62-
* @throws \InvalidArgumentException
6365
*/
64-
private function sanitizeFileName($fileName)
66+
private function sanitizeFileName(string $fileName): string
6567
{
66-
if (!is_string($fileName)) {
67-
throw new \InvalidArgumentException('Filename expected to be a string');
68-
}
69-
7068
$parts = explode('/', $fileName);
7169
$parts = array_filter($parts, function ($value) {
7270
return !in_array($value, ['', '.', '..']);
@@ -78,9 +76,10 @@ private function sanitizeFileName($fileName)
7876
/**
7977
* @inheritDoc
8078
*/
81-
protected function write(array $record)
79+
protected function write(array $record): void
8280
{
8381
$logDir = $this->filesystem->getParentDirectory($this->url);
82+
8483
if (!$this->filesystem->isDirectory($logDir)) {
8584
$this->filesystem->createDirectory($logDir);
8685
}

lib/internal/Magento/Framework/Logger/Handler/System.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Logger\Handler;
89

10+
use Exception;
911
use Magento\Framework\Filesystem\DriverInterface;
12+
use Magento\Framework\Logger\Handler\Exception as ExceptionHandler;
1013
use Monolog\Logger;
1114

1215
/**
@@ -25,38 +28,38 @@ class System extends Base
2528
protected $loggerType = Logger::INFO;
2629

2730
/**
28-
* @var Exception
31+
* @var ExceptionHandler
2932
*/
3033
protected $exceptionHandler;
3134

3235
/**
3336
* @param DriverInterface $filesystem
34-
* @param Exception $exceptionHandler
35-
* @param string $filePath
37+
* @param ExceptionHandler $exceptionHandler
38+
* @param string|null $filePath
39+
* @throws Exception
3640
*/
3741
public function __construct(
3842
DriverInterface $filesystem,
39-
Exception $exceptionHandler,
40-
$filePath = null
43+
ExceptionHandler $exceptionHandler,
44+
?string $filePath = null
4145
) {
4246
$this->exceptionHandler = $exceptionHandler;
4347
parent::__construct($filesystem, $filePath);
4448
}
4549

4650
/**
47-
* Writes formatted record through the handler.
51+
* Writes formatted record through the handler
4852
*
4953
* @param array $record The record metadata
5054
* @return void
5155
*/
52-
public function write(array $record)
56+
public function write(array $record): void
5357
{
5458
if (isset($record['context']['exception'])) {
5559
$this->exceptionHandler->handle($record);
5660

5761
return;
5862
}
59-
6063
$record['formatted'] = $this->getFormatter()->format($record);
6164

6265
parent::write($record);

lib/internal/Magento/Framework/Logger/Monolog.php

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,32 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Framework\Logger;
89

10+
use DateTimeZone;
911
use Monolog\Logger;
1012

13+
/**
14+
* Monolog Logger
15+
*/
1116
class Monolog extends Logger
1217
{
1318
/**
1419
* @inheritdoc
1520
*/
16-
public function __construct($name, array $handlers = [], array $processors = [])
17-
{
21+
public function __construct(
22+
string $name,
23+
array $handlers = [],
24+
array $processors = [],
25+
?DateTimeZone $timezone = null
26+
) {
1827
/**
1928
* TODO: This should be eliminated with MAGETWO-53989
2029
*/
2130
$handlers = array_values($handlers);
2231

23-
parent::__construct($name, $handlers, $processors);
24-
}
25-
26-
/**
27-
* Adds a log record.
28-
*
29-
* @param integer $level The logging level
30-
* @param string $message The log message
31-
* @param array $context The log context
32-
* @return bool Whether the record has been processed
33-
*/
34-
public function addRecord($level, $message, array $context = [])
35-
{
36-
/**
37-
* To preserve compatibility with Exception messages.
38-
* And support PSR-3 context standard.
39-
*
40-
* @link http://www.php-fig.org/psr/psr-3/#context PSR-3 context standard
41-
*/
42-
if ($message instanceof \Exception && !isset($context['exception'])) {
43-
$context['exception'] = $message;
44-
}
45-
46-
$message = $message instanceof \Exception ? $message->getMessage() : $message;
47-
48-
return parent::addRecord($level, $message, $context);
32+
parent::__construct($name, $handlers, $processors, $timezone);
4933
}
5034
}

0 commit comments

Comments
 (0)