PhpFileLoader.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Translation\Loader;
  11. /**
  12. * PhpFileLoader loads translations from PHP files returning an array of translations.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class PhpFileLoader extends FileLoader
  17. {
  18. private static ?array $cache = [];
  19. protected function loadResource(string $resource): array
  20. {
  21. if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) || filter_var(\ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOL))) {
  22. self::$cache = null;
  23. }
  24. if (null === self::$cache) {
  25. return require $resource;
  26. }
  27. return self::$cache[$resource] ??= require $resource;
  28. }
  29. }