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

nepada / bust-cache / 3806223582

pending completion
3806223582

push

github

Petr Morávek
Fix compatibility with Latte 3.0.5

2 of 2 new or added lines in 1 file covered. (100.0%)

311 of 315 relevant lines covered (98.73%)

0.99 hits per line

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

97.06
/src/Bridges/BustCacheLatte/Nodes/BustCacheNode.php
1
<?php
2
declare(strict_types = 1);
3

4
namespace Nepada\Bridges\BustCacheLatte\Nodes;
5

6
use Latte\Compiler\NodeHelpers;
7
use Latte\Compiler\Nodes\Php\ExpressionNode;
8
use Latte\Compiler\Nodes\Php\ModifierNode;
9
use Latte\Compiler\Nodes\StatementNode;
10
use Latte\Compiler\PrintContext;
11
use Latte\Compiler\Tag;
12
use Latte\Engine;
13
use Nepada\BustCache\BustCachePathProcessor;
14
use Nepada\BustCache\FileSystem\FileNotFoundException;
15
use Nepada\BustCache\FileSystem\IOException;
16
use Nepada\BustCache\Manifest\InvalidManifestException;
17

18
/**
19
 * {bustCache $file}
20
 * {bustCache dynamic $file}
21
 */
22
final class BustCacheNode extends StatementNode
23
{
24

25
    public ExpressionNode $file;
26

27
    private bool $strictMode;
28

29
    private bool $autoRefresh;
30

31
    private BustCachePathProcessor $bustCachePathProcessor;
32

33
    public function __construct(ExpressionNode $file, bool $strictMode, bool $autoRefresh, BustCachePathProcessor $bustCachePathProcessor)
1✔
34
    {
35
        $this->file = $file;
1✔
36
        $this->strictMode = $strictMode;
1✔
37
        $this->autoRefresh = $autoRefresh;
1✔
38
        $this->bustCachePathProcessor = $bustCachePathProcessor;
1✔
39
    }
1✔
40

41
    public static function create(Tag $tag, bool $strictMode, bool $autoRefresh, BustCachePathProcessor $bustCachePathProcessor): self
1✔
42
    {
43
        $tag->outputMode = $tag::OutputKeepIndentation;
1✔
44
        $tag->expectArguments();
1✔
45
        $dynamic = Engine::VERSION_ID < 3_00_05 ? $tag->parser->tryConsumeModifier('dynamic') : $tag->parser->tryConsumeSeparatedToken('dynamic');
1✔
46
        $autoRefresh = $dynamic !== null || $autoRefresh;
1✔
47
        $file = $tag->parser->parseUnquotedStringOrExpression();
1✔
48

49
        return new self($file, $strictMode, $autoRefresh, $bustCachePathProcessor);
1✔
50
    }
51

52
    /**
53
     * @param PrintContext $context
54
     * @return string
55
     * @throws IOException
56
     * @throws InvalidManifestException
57
     */
58
    public function print(PrintContext $context): string
1✔
59
    {
60
        // safeUrl is intentionally disabled, we verify the node content represents a valid file path inside BustCachePathProcessor
61
        $modifier = new ModifierNode([], true, false);
1✔
62

63
        if (! $this->autoRefresh) {
1✔
64
            try {
65
                /** @throws \InvalidArgumentException */
66
                $fileValue = NodeHelpers::toValue($this->file, constants: true);
1✔
67
                if (! is_string($fileValue)) {
1✔
68
                    throw new \InvalidArgumentException('File path must be a string');
×
69
                }
70
                $processedPath = $this->bustCachePathProcessor->__invoke($fileValue, true, false);
1✔
71
                return $context->format(
1✔
72
                    'echo %modify(%dump) %line;',
1✔
73
                    $modifier,
74
                    $processedPath,
75
                    $this->position,
1✔
76
                );
77
            } catch (\InvalidArgumentException) { // non-literal file argument used => compile time processing not possible
1✔
78
            } catch (FileNotFoundException) { // missing file => compile time not possible
1✔
79
            }
80
        }
81

82
        return $context->format(
1✔
83
            'echo %modify($this->global->bustCachePathProcessor->__invoke(%node, %dump, %dump)) %line;',
1✔
84
            $modifier,
85
            $this->file,
1✔
86
            $this->strictMode,
1✔
87
            $this->autoRefresh,
1✔
88
            $this->position,
1✔
89
        );
90
    }
91

92
    public function &getIterator(): \Generator
1✔
93
    {
94
        yield $this->file;
1✔
95
    }
1✔
96

97
}
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