ILIAS  release_8 Revision v8.24
class.ilLangDeprecated.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
29{
30 private const ILIAS_CLASS_FILE_RE = "class\..*\.php$";
31
32 protected array $candidates;
33 private \ilDBInterface $db;
34
38 public function __construct()
39 {
40 global $DIC;
41 $this->db = $DIC->database();
42 }
43
47 public function getDeprecatedLangVars(): array
48 {
49 $this->getCandidates();
50 $this->parseCodeFiles();
51 return $this->candidates;
52 }
53
58 protected function getCandidates(): void
59 {
60 $log = array();
61 $set = $this->db->query("SELECT module, identifier FROM lng_log ");
62 while ($rec = $this->db->fetchAssoc($set)) {
63 $log[$rec["module"] . ":" . $rec["identifier"]] = 1;
64 }
65 $set = $this->db->query("SELECT module, identifier FROM lng_data WHERE lang_key = " .
66 $this->db->quote("en", "text") . " ORDER BY module, identifier");
67 while ($rec = $this->db->fetchAssoc($set)) {
68 if (!isset($log[$rec["module"] . ":" . $rec["identifier"]])) {
69 $this->candidates[$rec["identifier"]] = $rec["module"];
70 }
71 }
72 }
73
77 protected function parseCodeFiles(): void
78 {
79 foreach ($this->getCodeFiles(ILIAS_ABSOLUTE_PATH) as $file) {
80 $this->parseCodeFile($file->getPathname());
81 }
82 }
83
87 protected function getCodeFiles(string $path): \Generator
88 {
89 foreach (
90 new \RegexIterator(
91 new \RecursiveIteratorIterator(
92 new \RecursiveDirectoryIterator($path),
93 \RecursiveIteratorIterator::SELF_FIRST,
94 \RecursiveIteratorIterator::CATCH_GET_CHILD
95 ),
96 '/' . self::ILIAS_CLASS_FILE_RE . '/i'
97 ) as $file
98 ) {
99 yield $file;
100 }
101 }
102
106 protected function parseCodeFile(string $file_path): void
107 {
108 $tokens = token_get_all(file_get_contents($file_path));
109 $num_tokens = count($tokens);
110
111 for ($i = 0; $i < $num_tokens; $i++) {
112 if (is_string($tokens[$i])) {
113 continue;
114 }
115
116 $token = $tokens[$i][0];
117 switch ($token) {
118 case T_STRING:
119 case T_CONSTANT_ENCAPSED_STRING:
120 $lv = str_replace(array("'", '"'), "", $tokens[$i][1]);
121 if ($lv !== "") {
122 unset($this->candidates[$lv]);
123 }
124 break;
125 }
126 }
127 }
128}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
parseCodeFile(string $file_path)
Parse code file and reduce candidates.
parseCodeFiles()
Parse Code Files.
getDeprecatedLangVars()
Get deprecated lang vars.
getCodeFiles(string $path)
Get code files.
__construct()
ilLangDeprecated constructor.
getCandidates()
Get candidates from the db.
global $DIC
Definition: feed.php:28
$path
Definition: ltiservices.php:32
$i
Definition: metadata.php:41
$log
Definition: result.php:33
$token
Definition: xapitoken.php:70