You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
878 B

3 years ago
  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\HttpKernel\CacheWarmer;
  11. /**
  12. * Abstract cache warmer that knows how to write a file to the cache.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. abstract class CacheWarmer implements CacheWarmerInterface
  17. {
  18. protected function writeCacheFile(string $file, $content)
  19. {
  20. $tmpFile = @tempnam(\dirname($file), basename($file));
  21. if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
  22. @chmod($file, 0666 & ~umask());
  23. return;
  24. }
  25. throw new \RuntimeException(sprintf('Failed to write cache file "%s".', $file));
  26. }
  27. }