From e5be4e97ffc41ca3b0386651a626b781a3637a85 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 6 Oct 2023 18:26:22 +0200 Subject: Update for PHP 8.2 --- Mustache/Loader/ProductionFilesystemLoader.php | 86 ++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Mustache/Loader/ProductionFilesystemLoader.php (limited to 'Mustache/Loader/ProductionFilesystemLoader.php') diff --git a/Mustache/Loader/ProductionFilesystemLoader.php b/Mustache/Loader/ProductionFilesystemLoader.php new file mode 100644 index 0000000..e735332 --- /dev/null +++ b/Mustache/Loader/ProductionFilesystemLoader.php @@ -0,0 +1,86 @@ + '.ms', + * 'stat_props' => array('size', 'mtime'), + * ); + * + * Specifying 'stat_props' overrides the stat properties used to invalidate the template cache. By default, this + * uses 'mtime' and 'size', but this can be set to any of the properties supported by stat(): + * + * http://php.net/manual/en/function.stat.php + * + * You can also disable filesystem stat entirely: + * + * $options = array('stat_props' => null); + * + * But with great power comes great responsibility. Namely, if you disable stat-based cache invalidation, + * YOU MUST CLEAR THE TEMPLATE CACHE YOURSELF when your templates change. Make it part of your build or deploy + * process so you don't forget! + * + * @throws Mustache_Exception_RuntimeException if $baseDir does not exist. + * + * @param string $baseDir Base directory containing Mustache template files. + * @param array $options Array of Loader options (default: array()) + */ + public function __construct($baseDir, array $options = array()) + { + parent::__construct($baseDir, $options); + + if (array_key_exists('stat_props', $options)) { + if (empty($options['stat_props'])) { + $this->statProps = array(); + } else { + $this->statProps = $options['stat_props']; + } + } else { + $this->statProps = array('size', 'mtime'); + } + } + + /** + * Helper function for loading a Mustache file by name. + * + * @throws Mustache_Exception_UnknownTemplateException If a template file is not found. + * + * @param string $name + * + * @return Mustache_Source Mustache Template source + */ + protected function loadFile($name) + { + $fileName = $this->getFileName($name); + + if (!file_exists($fileName)) { + throw new Mustache_Exception_UnknownTemplateException($name); + } + + return new Mustache_Source_FilesystemSource($fileName, $this->statProps); + } +} -- cgit v1.2.3-55-g7522