Skip to content

Commit

Permalink
rex_log_file: factory-Methode (#5957)
Browse files Browse the repository at this point in the history
  • Loading branch information
dergel committed Feb 27, 2024
1 parent 33bb439 commit 66d68b3
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .tools/phpstan/baseline.neon
Expand Up @@ -2545,6 +2545,11 @@ parameters:
count: 1
path: ../../redaxo/src/core/lib/util/formatter.php

-
message: "#^Method rex_log_file\\:\\:callFactoryClass\\(\\) has parameter \\$arguments with no value type specified in iterable type array\\.$#"
count: 1
path: ../../redaxo/src/core/lib/util/log_file.php

-
message: "#^Method rex_logger\\:\\:callFactoryClass\\(\\) has parameter \\$arguments with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/cronjob/lib/manager.php
Expand Up @@ -138,7 +138,7 @@ public function log($success, $message)
$environment = rex::getEnvironment();
}

$log = new rex_log_file(rex_path::log('cronjob.log'), 2_000_000);
$log = rex_log_file::factory(rex_path::log('cronjob.log'), 2_000_000);
$data = [
$success ? 'SUCCESS' : 'ERROR',
$this->id ?: '--',
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/cronjob/package.yml
Expand Up @@ -19,7 +19,7 @@ pages:

requires:
php: '>=8.1'
redaxo: ^5.16.0
redaxo: ^5.17.0-dev

console_commands:
cronjob:run: rex_command_cronjob_run
2 changes: 1 addition & 1 deletion redaxo/src/addons/cronjob/pages/log.php
Expand Up @@ -42,7 +42,7 @@

$formElements = [];

$file = new rex_log_file($logFile);
$file = rex_log_file::factory($logFile);

/** @var rex_log_entry $entry */
foreach (new LimitIterator($file, 0, 100) as $entry) {
Expand Down
4 changes: 2 additions & 2 deletions redaxo/src/addons/phpmailer/lib/mailer.php
Expand Up @@ -178,7 +178,7 @@ private function log(string $success): void
$replytos = implode(', ', array_column($this->getReplyToAddresses(), 0));
}

$log = new rex_log_file(self::logFile(), 2_000_000);
$log = rex_log_file::factory(self::logFile(), 2_000_000);
$data = [
$success,
$this->From . ($replytos ? '; reply-to: ' . $replytos : ''),
Expand Down Expand Up @@ -255,7 +255,7 @@ public static function errorMail(): void
return;
}

$file = new rex_log_file($logFile);
$file = rex_log_file::factory($logFile);

$logevent = false;

Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/phpmailer/package.yml
Expand Up @@ -21,7 +21,7 @@ pages:

requires:
php: '>=8.1'
redaxo: ^5.13.0
redaxo: ^5.17.0-dev

default_config:
from: ''
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/addons/phpmailer/pages/log.php
Expand Up @@ -34,7 +34,7 @@
</thead>
<tbody>';

$file = new rex_log_file($logFile);
$file = rex_log_file::factory($logFile);
foreach (new LimitIterator($file, 0, 30) as $entry) {
$data = $entry->getData();
$class = 'ERROR' == trim($data[0]) ? 'rex-state-error' : 'rex-mailer-log-ok';
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/core/boot.php
Expand Up @@ -90,7 +90,7 @@
require_once rex_path::core('functions/function_rex_other.php');

// ----------------- VERSION
rex::setProperty('version', '5.16.1');
rex::setProperty('version', '5.17.0-dev');

$cacheFile = rex_path::coreCache('config.yml.cache');
$configFile = rex_path::coreData('config.yml');
Expand Down
9 changes: 9 additions & 0 deletions redaxo/src/core/lib/util/log_file.php
Expand Up @@ -10,6 +10,8 @@
*/
class rex_log_file implements Iterator
{
use rex_factory_trait;

/** @var string */
private $path;

Expand Down Expand Up @@ -40,6 +42,7 @@ class rex_log_file implements Iterator
/**
* @param string $path File path
* @param int|null $maxFileSize Maximum file size
* @deprecated since 5.17.0, use `rex_log_file::factory` instead
*/
public function __construct($path, $maxFileSize = null)
{
Expand All @@ -53,6 +56,12 @@ public function __construct($path, $maxFileSize = null)
$this->file = fopen($path, 'a+');
}

public static function factory(string $path, ?int $maxFileSize = null): static
{
$class = static::getFactoryClass();
return new $class($path, $maxFileSize);
}

/**
* Adds a log entry.
*
Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/core/lib/util/logger.php
Expand Up @@ -137,7 +137,7 @@ public static function open()
{
// check if already opened
if (!self::$file) {
self::$file = new rex_log_file(self::getPath(), 2_000_000);
self::$file = rex_log_file::factory(self::getPath(), 2_000_000);
}
}

Expand Down
2 changes: 1 addition & 1 deletion redaxo/src/core/pages/system.log.redaxo.php
Expand Up @@ -45,7 +45,7 @@

$editor = rex_editor::factory();

$file = new rex_log_file($logFile);
$file = rex_log_file::factory($logFile);
foreach (new LimitIterator($file, 0, 100) as $entry) {
/** @var rex_log_entry $entry */
$data = $entry->getData();
Expand Down

0 comments on commit 66d68b3

Please sign in to comment.