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

ICanBoogie / bind-symfony-dependency-injection / 38836100724

16 Oct 2026 01:37AM UTC coverage: 38.462% (-18.7%) from 57.143%
38836100724

push

github

olvlvl
Additional safety when dumping

0 of 19 new or added lines in 2 files covered. (0.0%)

20 of 52 relevant lines covered (38.46%)

0.46 hits per line

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

0.0
/src/ContainerPathname.php
1
<?php
2

3
namespace ICanBoogie\Binding\SymfonyDependencyInjection;
4

5
use ICanBoogie\Application;
6
use RuntimeException;
7
use Stringable;
8

9
use function basename;
10
use function dirname;
11
use function file_exists;
12
use function filemtime;
13
use function glob;
14
use function is_file;
15
use function is_link;
16
use function is_writeable;
17
use function readlink;
18
use function time;
19
use function unlink;
20

21
/**
22
 * Represents the container pathname.
23
 *
24
 * The pathname is a symbolic link to a file named after the hash of its content
25
 * (`container-compiled.<hash>.php`). The link is switched atomically when the container changes, and
26
 * a file is never modified once written, so a process that resolved the link can always load the file.
27
 */
28
final class ContainerPathname implements Stringable
29
{
30
    private const FILENAME = 'container-compiled.php';
31
    private const HASHED_PATTERN = 'container-compiled.*.php*';
32

33
    /**
34
     * Hashed files older than this many seconds, and not targeted by the link, are removed.
35
     */
36
    private const PRUNE_AFTER = 600;
37

38
    public static function from(Application $app): self
39
    {
40
        return new self($app->config->var_cache . self::FILENAME);
×
41
    }
42

43
    private function __construct(
44
        private readonly string $pathname
45
    ) {
46
    }
×
47

48
    public function __toString(): string
49
    {
50
        return $this->pathname;
×
51
    }
52

53
    /**
54
     * @param string $hash Hash of the container source.
55
     */
56
    public function hashed(string $hash): string
57
    {
NEW
58
        return dirname($this->pathname) . '/container-compiled.' . $hash . '.php';
×
59
    }
60

61
    /**
62
     * Returns the pathname of the file targeted by the link, if it exists.
63
     */
64
    public function resolve(): ?string
65
    {
NEW
66
        $target = @readlink($this->pathname);
×
67

NEW
68
        if ($target === false) {
×
NEW
69
            return null;
×
70
        }
71

NEW
72
        $target = dirname($this->pathname) . '/' . basename($target);
×
73

NEW
74
        return is_file($target) ? $target : null;
×
75
    }
76

77
    /**
78
     * Whether the link exists, even if dangling.
79
     */
80
    public function exists(): bool
81
    {
NEW
82
        return is_link($this->pathname) || file_exists($this->pathname);
×
83
    }
84

85
    /**
86
     * Removes the hashed files, and the temporary files left by crashed writers, that are not the current target and are old enough that no
87
     * process can still be about to load them.
88
     */
89
    public function prune(?string $keep = null): void
90
    {
NEW
91
        $keep ??= $this->resolve();
×
92

NEW
93
        foreach (glob(dirname($this->pathname) . '/' . self::HASHED_PATTERN) ?: [] as $file) {
×
NEW
94
            if ($file === $keep) {
×
NEW
95
                continue;
×
96
            }
97

NEW
98
            $mtime = @filemtime($file);
×
99

NEW
100
            if ($mtime !== false && time() - $mtime > self::PRUNE_AFTER) {
×
NEW
101
                @unlink($file);
×
102
            }
103
        }
104
    }
105

106
    public function assert_writeable(): void
107
    {
108
        $dir = dirname($this->pathname);
×
109

110
        if (!file_exists($dir)) {
×
111
            throw new RuntimeException("The directory '$dir' does not exist");
×
112
        }
113

114
        if (!is_writeable($dir)) {
×
115
            throw new RuntimeException("The directory '$dir' is not writeable");
×
116
        }
117
    }
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc