summaryrefslogtreecommitdiff
path: root/inc/lib/Twig/Cache/Filesystem.php
diff options
context:
space:
mode:
authorAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:22:40 +1000
committerAppleman1234 <applemansigloo@gmail.com>2022-09-25 13:22:40 +1000
commit92561d7f36508b7e0271926e417adf0e2e53916b (patch)
treea8588b4f70af276c5acf58836e33b1f6ff5c61e8 /inc/lib/Twig/Cache/Filesystem.php
parent6f1083e4b51fc9c4c594f6c72cf3d84ef4d0298b (diff)
Initial attempt a switch to composer and PHP-8.1 compatibility
Diffstat (limited to 'inc/lib/Twig/Cache/Filesystem.php')
-rw-r--r--inc/lib/Twig/Cache/Filesystem.php93
1 files changed, 0 insertions, 93 deletions
diff --git a/inc/lib/Twig/Cache/Filesystem.php b/inc/lib/Twig/Cache/Filesystem.php
deleted file mode 100644
index 65976282..00000000
--- a/inc/lib/Twig/Cache/Filesystem.php
+++ /dev/null
@@ -1,93 +0,0 @@
-<?php
-
-/*
- * This file is part of Twig.
- *
- * (c) Fabien Potencier
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-/**
- * Implements a cache on the filesystem.
- *
- * @author Andrew Tch <andrew@noop.lv>
- */
-class Twig_Cache_Filesystem implements Twig_CacheInterface
-{
- const FORCE_BYTECODE_INVALIDATION = 1;
-
- private $directory;
- private $options;
-
- /**
- * @param $directory string The root cache directory
- * @param $options int A set of options
- */
- public function __construct($directory, $options = 0)
- {
- $this->directory = rtrim($directory, '\/').'/';
- $this->options = $options;
- }
-
- public function generateKey($name, $className)
- {
- $hash = hash('sha256', $className);
-
- return $this->directory.$hash[0].$hash[1].'/'.$hash.'.php';
- }
-
- public function load($key)
- {
- if (file_exists($key)) {
- @include_once $key;
- }
- }
-
- public function write($key, $content)
- {
- $dir = dirname($key);
- if (!is_dir($dir)) {
- if (false === @mkdir($dir, 0777, true)) {
- if (PHP_VERSION_ID >= 50300) {
- clearstatcache(true, $dir);
- }
- if (!is_dir($dir)) {
- throw new RuntimeException(sprintf('Unable to create the cache directory (%s).', $dir));
- }
- }
- } elseif (!is_writable($dir)) {
- throw new RuntimeException(sprintf('Unable to write in the cache directory (%s).', $dir));
- }
-
- $tmpFile = tempnam($dir, basename($key));
- if (false !== @file_put_contents($tmpFile, $content) && @rename($tmpFile, $key)) {
- @chmod($key, 0666 & ~umask());
-
- if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) {
- // Compile cached file into bytecode cache
- if (function_exists('opcache_invalidate')) {
- opcache_invalidate($key, true);
- } elseif (function_exists('apc_compile_file')) {
- apc_compile_file($key);
- }
- }
-
- return;
- }
-
- throw new RuntimeException(sprintf('Failed to write cache file "%s".', $key));
- }
-
- public function getTimestamp($key)
- {
- if (!file_exists($key)) {
- return 0;
- }
-
- return (int) @filemtime($key);
- }
-}
-
-class_alias('Twig_Cache_Filesystem', 'Twig\Cache\FilesystemCache', false);