• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 12021710761

25 Nov 2024 06:54PM UTC coverage: 79.441% (-2.6%) from 81.993%
12021710761

push

github

web-flow
ci: close stale issues and pull requests

7879 of 9918 relevant lines covered (79.44%)

61.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
/src/Tempest/Cache/src/CacheConfig.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Cache;
6

7
use Psr\Cache\CacheItemPoolInterface;
8
use Tempest\Core\DiscoveryCache;
9
use function Tempest\env;
10

11
final class CacheConfig
12
{
13
    /** @var class-string<\Tempest\Cache\Cache>[] */
14
    public array $caches = [];
15

16
    public ?bool $enable;
17

18
    public bool $projectCache = false;
19

20
    public bool $viewCache = false;
21

22
    public DiscoveryCacheStrategy $discoveryCache;
23

24
    public function __construct(
390✔
25
        public string $directory = __DIR__ . '/../../../../.cache',
26
        public ?CacheItemPoolInterface $projectCachePool = null,
27

28
        /** Used as a global override, should be true in production, null in local */
29
        ?bool $enable = null,
30
    ) {
31
        $this->enable = $enable ?? env('CACHE') ?? null;
390✔
32
        $this->projectCache = (bool)env('PROJECT_CACHE', false);
390✔
33
        $this->viewCache = (bool)env('VIEW_CACHE', false);
390✔
34
        $this->discoveryCache = $this->resolveDiscoveryCacheStrategy();
390✔
35
    }
36

37
    /** @param class-string<\Tempest\Cache\Cache> $className */
38
    public function addCache(string $className): void
382✔
39
    {
40
        $this->caches[] = $className;
382✔
41
    }
42

43
    private function resolveDiscoveryCacheStrategy(): DiscoveryCacheStrategy
390✔
44
    {
45
        if (PHP_SAPI === 'cli') {
390✔
46
            $command = $_SERVER['argv'][1] ?? null;
390✔
47

48
            if ($command === 'dg' || $command === 'discovery:generate') {
390✔
49
                return DiscoveryCacheStrategy::NONE;
×
50
            }
51
        }
52

53
        $cache = env('CACHE');
390✔
54

55
        if ($cache !== null) {
390✔
56
            $current = DiscoveryCacheStrategy::make($cache);
×
57
        } else {
58
            $current = DiscoveryCacheStrategy::make(env('DISCOVERY_CACHE'));
390✔
59
        }
60

61
        if ($current === DiscoveryCacheStrategy::NONE) {
390✔
62
            return $current;
×
63
        }
64

65
        $original = DiscoveryCacheStrategy::make(@file_get_contents(DiscoveryCache::CURRENT_DISCOVERY_STRATEGY));
390✔
66

67
        if ($current !== $original) {
390✔
68
            return DiscoveryCacheStrategy::INVALID;
×
69
        }
70

71
        return $current;
390✔
72
    }
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc