PhpFileLoader.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 $cache = [];
  19. /**
  20. * {@inheritdoc}
  21. */
  22. protected function loadResource($resource)
  23. {
  24. if ([] === self::$cache && \function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(\ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOLEAN))) {
  25. self::$cache = null;
  26. }
  27. if (null === self::$cache) {
  28. return require $resource;
  29. }
  30. if (isset(self::$cache[$resource])) {
  31. return self::$cache[$resource];
  32. }
  33. return self::$cache[$resource] = require $resource;
  34. }
  35. }