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

api-platform / core / 17071323229

19 Aug 2025 01:36PM UTC coverage: 0.0%. First build
17071323229

Pull #7225

github

web-flow
Merge 1e726a585 into 020385253
Pull Request #7225: feat: json streamer

0 of 307 new or added lines in 31 files covered. (0.0%)

0 of 52230 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/Hydra/State/Util/SearchHelperTrait.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Hydra\State\Util;
15

16
use ApiPlatform\Hydra\IriTemplate;
17
use ApiPlatform\Hydra\IriTemplateMapping;
18
use ApiPlatform\Metadata\FilterInterface;
19
use ApiPlatform\Metadata\Operation;
20
use ApiPlatform\Metadata\Parameters;
21
use ApiPlatform\Metadata\QueryParameterInterface;
22

23
trait SearchHelperTrait
24
{
25
    /**
26
     * @param FilterInterface[] $filters
27
     */
28
    private function getSearch(string $path, ?Operation $operation = null, ?string $resourceClass = null, ?array $filters = [], ?Parameters $parameters = null, ?callable $getFilter = null): IriTemplate
29
    {
NEW
30
        ['mapping' => $mapping, 'keys' => $keys] = $this->getSearchMappingAndKeys($operation, $resourceClass, $filters, $parameters, $getFilter);
×
31

NEW
32
        return new IriTemplate(
×
NEW
33
            variableRepresentation: 'BasicRepresentation',
×
NEW
34
            mapping: $mapping,
×
NEW
35
            template: \sprintf('%s{?%s}', $path, implode(',', $keys)),
×
NEW
36
        );
×
37
    }
38

39
    /**
40
     * @param FilterInterface[] $filters
41
     *
42
     * @return array{mapping: list<IriTemplateMapping>, keys: list<string>}
43
     */
44
    private function getSearchMappingAndKeys(?Operation $operation = null, ?string $resourceClass = null, ?array $filters = [], ?Parameters $parameters = null, ?callable $getFilter = null): array
45
    {
NEW
46
        $mapping = [];
×
NEW
47
        $keys = [];
×
48

NEW
49
        if ($filters) {
×
NEW
50
            foreach ($filters as $filter) {
×
NEW
51
                foreach ($filter->getDescription($resourceClass) as $variable => $data) {
×
NEW
52
                    $keys[] = $variable;
×
NEW
53
                    $mapping[] = new IriTemplateMapping(variable: $variable, property: $data['property'] ?? null, required: $data['required'] ?? false);
×
54
                }
55
            }
56
        }
57

NEW
58
        $params = $operation ? ($operation->getParameters() ?? []) : ($parameters ?? []);
×
59

NEW
60
        foreach ($params as $key => $parameter) {
×
NEW
61
            if (!$parameter instanceof QueryParameterInterface || false === $parameter->getHydra()) {
×
NEW
62
                continue;
×
63
            }
64

NEW
65
            if ($getFilter && ($filterId = $parameter->getFilter()) && \is_string($filterId) && ($filter = $getFilter($filterId))) {
×
NEW
66
                $filterDescription = $filter->getDescription($resourceClass);
×
67

NEW
68
                foreach ($filterDescription as $variable => $description) {
×
69
                    // // This is a practice induced by PHP and is not necessary when implementing URI template
NEW
70
                    if (str_ends_with((string) $variable, '[]')) {
×
NEW
71
                        continue;
×
72
                    }
73

NEW
74
                    if (!($descriptionProperty = $description['property'] ?? null)) {
×
NEW
75
                        continue;
×
76
                    }
77

NEW
78
                    if (($prop = $parameter->getProperty()) && $descriptionProperty !== $prop) {
×
NEW
79
                        continue;
×
80
                    }
81

NEW
82
                    $k = str_replace(':property', $description['property'], $key);
×
NEW
83
                    $variable = str_replace($description['property'], $k, $variable);
×
NEW
84
                    $keys[] = $variable;
×
NEW
85
                    $m = new IriTemplateMapping(variable: $variable, property: $description['property'], required: $description['required']);
×
NEW
86
                    if (null !== ($required = $parameter->getRequired())) {
×
NEW
87
                        $m->required = $required;
×
88
                    }
NEW
89
                    $mapping[] = $m;
×
90
                }
91

NEW
92
                if ($filterDescription) {
×
NEW
93
                    continue;
×
94
                }
95
            }
96

NEW
97
            if (str_contains($key, ':property') && $parameter->getProperties()) {
×
NEW
98
                $required = $parameter->getRequired();
×
NEW
99
                foreach ($parameter->getProperties() as $prop) {
×
NEW
100
                    $k = str_replace(':property', $prop, $key);
×
NEW
101
                    $m = new IriTemplateMapping(variable: $k, property: $prop);
×
NEW
102
                    $keys[] = $k;
×
NEW
103
                    if (null !== $required) {
×
NEW
104
                        $m->required = $required;
×
105
                    }
NEW
106
                    $mapping[] = $m;
×
107
                }
108

NEW
109
                continue;
×
110
            }
111

NEW
112
            if (!($property = $parameter->getProperty())) {
×
NEW
113
                continue;
×
114
            }
115

NEW
116
            $m = new IriTemplateMapping(variable: $key, property: $property);
×
NEW
117
            $keys[] = $key;
×
NEW
118
            if (null !== ($required = $parameter->getRequired())) {
×
NEW
119
                $m->required = $required;
×
120
            }
NEW
121
            $mapping[] = $m;
×
122
        }
123

NEW
124
        return ['mapping' => $mapping, 'keys' => $keys];
×
125
    }
126
}
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

© 2025 Coveralls, Inc