菜谱项目

CacheWarmer.php 870B

123456789101112131415161718192021222324252627282930313233
  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($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. }