ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLangDeprecated.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 private const ILIAS_CLASS_FILE_RE = "class\..*\.php$";
30
31 protected array $candidates;
32 private \ilDBInterface $db;
33
37 public function __construct()
38 {
39 global $DIC;
40 $this->db = $DIC->database();
41 }
42
46 public function getDeprecatedLangVars(): array
47 {
48 $this->getCandidates();
49 $this->parseCodeFiles();
50 return $this->candidates;
51 }
52
57 protected function getCandidates(): void
58 {
59 $log = array();
60 $set = $this->db->query("SELECT module, identifier FROM lng_log ");
61 while ($rec = $this->db->fetchAssoc($set)) {
62 $log[$rec["module"] . ":" . $rec["identifier"]] = 1;
63 }
64 $set = $this->db->query("SELECT module, identifier FROM lng_data WHERE lang_key = " .
65 $this->db->quote("en", "text") . " ORDER BY module, identifier");
66 while ($rec = $this->db->fetchAssoc($set)) {
67 if (!isset($log[$rec["module"] . ":" . $rec["identifier"]])) {
68 $this->candidates[$rec["identifier"]] = $rec["module"];
69 }
70 }
71 }
72
76 protected function parseCodeFiles(): void
77 {
78 foreach ($this->getCodeFiles(ILIAS_ABSOLUTE_PATH) as $file) {
79 $this->parseCodeFile($file->getPathname());
80 }
81 }
82
86 protected function getCodeFiles(string $path): \Generator
87 {
88 foreach (
89 new \RegexIterator(
90 new \RecursiveIteratorIterator(
91 new \RecursiveDirectoryIterator($path),
92 \RecursiveIteratorIterator::SELF_FIRST,
93 \RecursiveIteratorIterator::CATCH_GET_CHILD
94 ),
95 '/' . self::ILIAS_CLASS_FILE_RE . '/i'
96 ) as $file
97 ) {
98 yield $file;
99 }
100 }
101
105 protected function parseCodeFile(string $file_path): void
106 {
107 $tokens = token_get_all(file_get_contents($file_path));
108 $num_tokens = count($tokens);
109
110 for ($i = 0; $i < $num_tokens; $i++) {
111 if (is_string($tokens[$i])) {
112 continue;
113 }
114
115 $token = $tokens[$i][0];
116 switch ($token) {
117 case T_STRING:
118 case T_CONSTANT_ENCAPSED_STRING:
119 $lv = str_replace(array("'", '"'), "", $tokens[$i][1]);
120 if ($lv !== "") {
121 unset($this->candidates[$lv]);
122 }
123 break;
124 }
125 }
126 }
127}
Search for deprecated lang vars.
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.
$log
Definition: ltiresult.php:34
$path
Definition: ltiservices.php:30
global $DIC
Definition: shib_login.php:26
$token
Definition: xapitoken.php:70