CacheWarmer.php 915 B

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\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. /**
  19. * @return void
  20. */
  21. protected function writeCacheFile(string $file, $content)
  22. {
  23. $tmpFile = @tempnam(\dirname($file), basename($file));
  24. if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $file)) {
  25. @chmod($file, 0666 & ~umask());
  26. return;
  27. }
  28. throw new \RuntimeException(\sprintf('Failed to write cache file "%s".', $file));
  29. }
  30. }