Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Pick
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Schema;
6
7use Attribute;
8
9/**
10 * Configures a Reference field's pickable node set (read by the search
11 * endpoint). `types` restricts the node type — the common case, so it is
12 * positional; pass one class-string/handle or an array for several.
13 * `where` narrows further with the finder DSL (`=`/`&`/`|`), e.g.
14 * "productLine = 'klassiker'". `published`/`hidden` override the pickable
15 * gates (default: any publication, hidden included); soft-deleted nodes
16 * are never pickable.
17 *
18 *   #[Pick(Beer::class, where: "productLine = 'klassiker'")]
19 *   #[Pick([Beer::class, Wine::class], published: true)]
20 *
21 * Use the typed params for the node gates and `where` for content-field
22 * predicates; they compose with AND, so don't split one across both.
23 */
24#[Attribute(Attribute::TARGET_PROPERTY)]
25readonly class Pick
26{
27    /** @var list<string> */
28    public array $types;
29
30    /** @param string|list<string> $types */
31    public function __construct(
32        string|array $types = [],
33        public string $where = '',
34        public ?bool $published = null,
35        public ?bool $hidden = null,
36    ) {
37        $this->types = array_values(array_filter(
38            is_array($types) ? $types : [$types],
39            static fn(string $type): bool => $type !== '',
40        ));
41    }
42}