Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Slot
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
4 / 4
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 template
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 path
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 context
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Celemas\Boiler;
6
7/** @api */
8final class Slot
9{
10    /**
11     * @param non-empty-string $path
12     * @param array<array-key, mixed> $context
13     */
14    private function __construct(
15        private readonly string $path,
16        private readonly array $context = [],
17    ) {}
18
19    /**
20     * Renders a template when the inserted template calls `$this->slot()`.
21     *
22     * The slot template receives the caller context, this context, and the data
23     * passed to `$this->slot([...])`, with later values overriding earlier ones.
24     *
25     * @param non-empty-string $path
26     * @param array<array-key, mixed> $context
27     */
28    public static function template(string $path, array $context = []): self
29    {
30        return new self($path, $context);
31    }
32
33    /**
34     * @internal
35     *
36     * @return non-empty-string
37     */
38    public function path(): string
39    {
40        return $this->path;
41    }
42
43    /**
44     * @internal
45     *
46     * @return array<array-key, mixed>
47     */
48    public function context(): array
49    {
50        return $this->context;
51    }
52}