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

api-platform / core / 13855495414

14 Mar 2025 11:19AM UTC coverage: 8.526% (-15.0%) from 23.51%
13855495414

Pull #7017

github

web-flow
Merge 0d3b24a16 into bf09616cf
Pull Request #7017: feat(metadata) Load external PHP file resources

22 of 78 new or added lines in 10 files covered. (28.21%)

36 existing lines in 2 files now uncovered.

13401 of 157170 relevant lines covered (8.53%)

22.93 hits per line

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

0.0
/src/Metadata/Extractor/PhpFileResourceExtractor.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\Metadata\Extractor;
15

16
use ApiPlatform\Metadata\ApiResource;
17

18
/**
19
 * Extracts an array of metadata from a list of PHP files.
20
 *
21
 * @author Loïc Frémont <lc.fremont@gmail.com>
22
 */
23
final class PhpFileResourceExtractor extends AbstractResourceExtractor
24
{
25
    use ResourceExtractorTrait;
26

27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function extractPath(string $path): void
31
    {
NEW
32
        $resource = $this->getPHPFileClosure($path)();
×
33

NEW
34
        if (!$resource instanceof ApiResource) {
×
NEW
35
            return;
×
36
        }
37

NEW
38
        $resourceReflection = new \ReflectionClass($resource);
×
39

NEW
40
        foreach ($resourceReflection->getProperties() as $property) {
×
NEW
41
            $property->setAccessible(true);
×
NEW
42
            $resolvedValue = $this->resolve($property->getValue($resource));
×
NEW
43
            $property->setValue($resource, $resolvedValue);
×
44
        }
45

NEW
46
        $this->resources = [$resource];
×
47
    }
48

49
    /**
50
     * Scope isolated include.
51
     *
52
     * Prevents access to $this/self from included files.
53
     */
54
    private function getPHPFileClosure(string $filePath): \Closure
55
    {
NEW
56
        return \Closure::bind(function () use ($filePath): mixed {
×
NEW
57
            return require $filePath;
×
NEW
58
        }, null, null);
×
59
    }
60
}
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