a9467a6f9883934188786f56cf4791e61b900364
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / devtools / missing / language / item / DevtoolsMissingLanguageItem.class.php
1 <?php
2
3 namespace wcf\data\devtools\missing\language\item;
4
5 use wcf\data\DatabaseObject;
6 use wcf\data\language\Language;
7 use wcf\system\language\LanguageFactory;
8 use wcf\system\WCF;
9 use wcf\util\JSON;
10
11 /**
12 * Represents a missing language item log entry.
13 *
14 * @author Matthias Schmidt
15 * @copyright 2001-2020 WoltLab GmbH
16 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
17 * @package WoltLabSuite\Core\Devtools\Missing\Language\Item
18 * @since 5.3
19 *
20 * @property-read int $itemID unique id of the missing language item log entry
21 * @property-read int $languageID id of the language the missing language item was requested for
22 * @property-read string $languageItem name of the missing language item
23 * @property-read int $lastTime timestamp of the last time the missing language item was requested
24 * @property-read string $stackTrace stack trace of how the missing language item was requested for the last time
25 */
26 class DevtoolsMissingLanguageItem extends DatabaseObject
27 {
28 /**
29 * Returns the language the missing language item was requested for or `null` if the language
30 * does not exist anymore.
31 *
32 * @return null|Language
33 */
34 public function getLanguage()
35 {
36 if ($this->languageID === null) {
37 return;
38 }
39
40 return LanguageFactory::getInstance()->getLanguage($this->languageID);
41 }
42
43 /**
44 * Returns the formatted stack trace of how the missing language item was requested for the
45 * last time.
46 *
47 * @return string
48 */
49 public function getStackTrace()
50 {
51 $stackTrace = JSON::decode($this->stackTrace);
52 foreach ($stackTrace as &$stackEntry) {
53 foreach ($stackEntry['args'] as &$stackEntryArg) {
54 if (\gettype($stackEntryArg) === 'string') {
55 $stackEntryArg = \str_replace(["\n", "\t"], ['\n', '\t'], $stackEntryArg);
56 }
57 }
58 unset($stackEntryArg);
59 }
60 unset($stackEntry);
61
62 return WCF::getTPL()->fetch('__devtoolsMissingLanguageItemStackTrace', 'wcf', [
63 'stackTrace' => $stackTrace,
64 ]);
65 }
66 }