Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| TwigCacheResolver | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
| resolve | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Resolves the Twig compile-cache directory from the environment. |
| 5 | * |
| 6 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | * |
| 10 | * @package phpMyFAQ |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @copyright 2026 phpMyFAQ Team |
| 13 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 14 | * @link https://www.phpmyfaq.de |
| 15 | * @since 2026-07-14 |
| 16 | */ |
| 17 | |
| 18 | declare(strict_types=1); |
| 19 | |
| 20 | namespace phpMyFAQ\Twig; |
| 21 | |
| 22 | /** |
| 23 | * Class TwigCacheResolver |
| 24 | * |
| 25 | * Decides whether compiled Twig templates are cached and where, mirroring |
| 26 | * the route-cache configuration: enabled by default in production, disabled |
| 27 | * in debug mode, and overridable via TWIG_CACHE_ENABLED / TWIG_CACHE_DIR. |
| 28 | */ |
| 29 | final class TwigCacheResolver |
| 30 | { |
| 31 | /** |
| 32 | * @return string|false the cache directory, or false when caching is disabled |
| 33 | */ |
| 34 | public static function resolve( |
| 35 | bool $debug, |
| 36 | mixed $enabled, |
| 37 | ?string $configuredDir, |
| 38 | string $defaultDir, |
| 39 | ): string|false { |
| 40 | if ($debug) { |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | if (!filter_var($enabled ?? 'true', FILTER_VALIDATE_BOOLEAN)) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | if ($configuredDir !== null && trim($configuredDir) !== '') { |
| 49 | return $configuredDir; |
| 50 | } |
| 51 | |
| 52 | return $defaultDir; |
| 53 | } |
| 54 | } |