|
15 | 15 | use Joomla\CMS\Installer\Installer;
|
16 | 16 | use Joomla\CMS\Log\Log;
|
17 | 17 | use Joomla\Database\DatabaseInterface;
|
| 18 | +use Joomla\Filesystem\Exception\FilesystemException; |
18 | 19 | use Joomla\Filesystem\File;
|
| 20 | +use Joomla\Filesystem\Folder; |
19 | 21 | use Joomla\Registry\Registry;
|
20 | 22 | use Joomla\Utilities\ArrayHelper;
|
21 | 23 |
|
@@ -444,6 +446,12 @@ public static function parseIniFile($fileName, $debug = false)
|
444 | 446 | return [];
|
445 | 447 | }
|
446 | 448 |
|
| 449 | + $cacheFile = JPATH_CACHE . '/language/' . ltrim(str_replace([JPATH_ROOT, '/'], ['', '-'], $fileName), '-') . '.' . filemtime($fileName) . '.php'; |
| 450 | + |
| 451 | + if (is_file($cacheFile)) { |
| 452 | + return include $cacheFile; |
| 453 | + } |
| 454 | + |
447 | 455 | // This was required for https://github.com/joomla/joomla-cms/issues/17198 but not sure what server setup
|
448 | 456 | // issue it is solving
|
449 | 457 | $disabledFunctions = explode(',', \ini_get('disable_functions'));
|
@@ -471,10 +479,28 @@ public static function parseIniFile($fileName, $debug = false)
|
471 | 479 | restore_error_handler();
|
472 | 480 | }
|
473 | 481 |
|
| 482 | + if (!\is_array($strings)) { |
| 483 | + $strings = []; |
| 484 | + } |
| 485 | + |
474 | 486 | // Ini files are processed in the "RAW" mode of parse_ini_string, leaving escaped quotes untouched - lets postprocess them
|
475 | 487 | $strings = str_replace('\"', '"', $strings);
|
476 | 488 |
|
477 |
| - return \is_array($strings) ? $strings : []; |
| 489 | + // Write cache |
| 490 | + try { |
| 491 | + Folder::create(\dirname($cacheFile)); |
| 492 | + |
| 493 | + $data = "<?php\ndefined('_JEXEC') or die;\nreturn " . var_export($strings, true) . ";\n"; |
| 494 | + $bytesWritten = file_put_contents($cacheFile, $data); |
| 495 | + |
| 496 | + if ($bytesWritten === false || $bytesWritten < \strlen($data)) { |
| 497 | + throw new FilesystemException('Unable to write cache file'); |
| 498 | + } |
| 499 | + } catch (\FilesystemException $e) { |
| 500 | + // We ignore the error, as the file is for caching only. |
| 501 | + } |
| 502 | + |
| 503 | + return $strings; |
478 | 504 | }
|
479 | 505 |
|
480 | 506 | /**
|
|
0 commit comments