ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
DuplicateIdentifierMessage.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\Refinery\Factory as Refinery;
25
32{
33 private const int MAX_ENTRY_WIDTH = 200;
34 private const int MAX_LOGGED_ENTRIES = 200;
35
37 public static function entry(string $key, array $existing): string
38 {
39 return sprintf('%s (%s)', $key, implode(', ', $existing));
40 }
41
43 public static function of(Language $lng, Refinery $refinery, array $entries): string
44 {
45 $list = $refinery->encode()->htmlSpecialCharsAsEntities()->transform(
46 PlainLogText::of(PlainLogText::keyList(self::shortened($entries), '; '))
47 );
48
49 // str_replace(), not sprintf(): a locally changed text with another "%" must not fail
50 $text = $lng->txt('lng_identifier_not_unique');
51
52 return str_contains($text, '%s') ? str_replace('%s', $list, $text) : $text . ' ' . $list;
53 }
54
56 public static function forLog(array $entries): string
57 {
58 $logged = implode('; ', self::shortened(array_slice($entries, 0, self::MAX_LOGGED_ENTRIES)));
59 $left_out = count($entries) - self::MAX_LOGGED_ENTRIES;
60
61 return PlainLogText::of(sprintf(
62 'Language entries rejected or not applied, their identifier exists in another module or in another spelling: %s%s',
63 $logged,
64 $left_out > 0 ? sprintf(' … (+%d)', $left_out) : ''
65 ));
66 }
67
72 private static function shortened(array $entries): array
73 {
74 return array_map(static fn(string $entry): string => mb_strimwidth($entry, 0, self::MAX_ENTRY_WIDTH, '…'), $entries);
75 }
76}
Builds data types.
Definition: Factory.php:36
Texts naming entries left out or rejected because their identifier exists in another module (see Iden...
static of(Language $lng, Refinery $refinery, array $entries)
static keyList(array $keys, string $separator=', ')
The first MAX_LISTED_KEYS of $keys, then "… (+N)" for the rest (the full list belongs into the log).
global $lng
Definition: privfeed.php:26
$text
Definition: xapiexit.php:21