ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
generate_language_identifier_enum.php File Reference

Go to the source code of this file.

Variables

if(PHP_SAPI !=='cli') $repo_root = dirname(__DIR__, 5)
 Generates the enum of the language identifiers of one module (an implementation of ILIAS\Language\LanguageIdentifier, see Language::txt()) from the module's .pot, or checks an existing one against it (–check, for CI). More...
 
const LANGUAGE_IDENTIFIER_ENUM_TOOL = 'components/ILIAS/Language/tools/language-identifier-enum/generate_language_identifier_enum.php'
 
 $fail
 
 $printable
 Makes control characters visible in everything printed that comes from a file or the command line. More...
 
 $identifier_format = '/^[A-Za-z_][A-Za-z0-9_]*$/'
 
 $reserved_case_names = ['CLASS', '__HALT_COMPILER']
 Case names PHP rejects (all other keywords are allowed as names of class constants and cases). More...
 
 $comment_safe = static fn(string $text): string => str_replace('*/', '*\\/', $text)
 
 $inside_repository
 The absolute path of $path if it lies inside $root, null otherwise. More...
 
 $case_names
 
 $render
 

Variable Documentation

◆ $case_names

$case_names
Parameters
list<string>$identifiers
Returns
array{names: array<string, string>, collisions: list<string>}

Definition at line 125 of file generate_language_identifier_enum.php.

◆ $comment_safe

$comment_safe = static fn(string $text): string => str_replace('*/', '*\\/', $text)

Definition at line 85 of file generate_language_identifier_enum.php.

◆ $fail

$fail
Initial value:
= static function (string $message): never {
fwrite(STDERR, 'ERROR: ' . $message . PHP_EOL);
exit(2);
}
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

Definition at line 64 of file generate_language_identifier_enum.php.

Referenced by ilAdvancedMDSettingsGUI\deleteFields(), ilAdvancedMDSettingsGUI\deleteRecords(), ilAdvancedMDSettingsGUI\exportRecords(), ilObjWorkspaceFolderGUI\performPasteIntoMultipleObjects(), StandardFormTest\testRenderWithErrorOnField(), StandardFormTest\testRenderWithErrorOnForm(), and ILIAS\Tests\Refinery\Parser\ABNF\BrickTest\testRepeat().

◆ $identifier_format

$identifier_format = '/^[A-Za-z_][A-Za-z0-9_]*$/'

Definition at line 78 of file generate_language_identifier_enum.php.

◆ $inside_repository

$inside_repository
Initial value:
= static function (string $path, string $root): ?string {
if ($path === '' || str_contains($path, "\0")) {
return null;
}
if (!str_starts_with($path, '/')) {
$path = getcwd() . '/' . $path;
}
$missing = [];
$existing = rtrim($path, '/');
while ($existing !== '' && !file_exists($existing)) {
$missing[] = basename($existing);
$existing = dirname($existing);
}
$resolved = realpath($existing === '' ? '/' : $existing);
$resolved_root = realpath($root);
if ($resolved === false || $resolved_root === false) {
return null;
}
foreach ($missing as $segment) {
if ($segment === '' || $segment === '.' || $segment === '..') {
return null;
}
}
$absolute = $resolved . ($missing === [] ? '' : '/' . implode('/', array_reverse($missing)));
return str_starts_with($absolute . '/', rtrim($resolved_root, '/') . '/') && $absolute !== $resolved_root
? $absolute
: null;
}

The absolute path of $path if it lies inside $root, null otherwise.

Symbolic links of the deepest existing ancestor are resolved; the non-existing rest must not contain "." or "..".

Definition at line 91 of file generate_language_identifier_enum.php.

◆ $printable

$printable
Initial value:
= static fn(string $text): string => (string) preg_replace_callback(
'/[\x00-\x1F\x7F]/',
static fn(array $match): string => sprintf('\x%02X', ord($match[0])),
)
$text
Definition: xapiexit.php:21

Makes control characters visible in everything printed that comes from a file or the command line.

Definition at line 72 of file generate_language_identifier_enum.php.

◆ $render

$render
Parameters
array<string,string>$names identifier => case name

Definition at line 172 of file generate_language_identifier_enum.php.

Referenced by ILIAS\LegalDocuments\ConsumerToolbox\ConsumerSlots\SelfRegistration\guis(), and ILIAS\DataProtection\Consumer\showMatchingDocument().

◆ $repo_root

if (PHP_SAPI !=='cli') $repo_root = dirname(__DIR__, 5)

Generates the enum of the language identifiers of one module (an implementation of ILIAS\Language\LanguageIdentifier, see Language::txt()) from the module's .pot, or checks an existing one against it (–check, for CI).

See README.md next to this file.

Usage: php generate_language_identifier_enum.php [–check | –stdout] [–module=<module>] –namespace=<Namespace> <pot file> <enum file> <pot file> the .pot of the module, inside this ILIAS directory <enum file> the enum, "<EnumName>.php", inside this ILIAS directory - written atomically (its directory must exist), with –stdout only printed, with –check only read –module the module (default: the "X-Domain" header of the .pot, else its file name) –namespace the namespace of the enum, e.g. "ILIAS\Poll" –check compares the enum with the .pot: missing or surplus cases, wrong values, wrong module - exit code 1 if it deviates. For an enum without cases, module() must return a single-quoted string literal (it cannot be called without a case). Exit codes: 0 success (no deviation), 1 deviation (–check), 2 invalid arguments or input.

Case names: the identifier in upper case, every run of characters other than A-Z, 0-9 and "_" replaced by one "_", a leading digit and the names PHP does not allow for a case (CLASS, __HALT_COMPILER) prefixed with "KEY_". Identifiers that end up with the same name (e.g. "style" and "Style") are numbered deterministically: the identifier in lower case keeps the name, the others (in byte order) get "_2", "_3", ... (skipping every name taken otherwise) - reported on stderr. One case per msgid, plural messages included.

Deliberately declares no named classes or functions: this file lives inside the classmap-scanned components/ tree (see convert_module_to_po.php).

Definition at line 54 of file generate_language_identifier_enum.php.

◆ $reserved_case_names

$reserved_case_names = ['CLASS', '__HALT_COMPILER']

Case names PHP rejects (all other keywords are allowed as names of class constants and cases).

Definition at line 83 of file generate_language_identifier_enum.php.

◆ LANGUAGE_IDENTIFIER_ENUM_TOOL

const LANGUAGE_IDENTIFIER_ENUM_TOOL = 'components/ILIAS/Language/tools/language-identifier-enum/generate_language_identifier_enum.php'

Definition at line 62 of file generate_language_identifier_enum.php.