Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace PHPUnit\Runner\Extension;
11
 
12
use function is_file;
13
use PharIo\Manifest\ApplicationName;
14
use PharIo\Manifest\Exception as ManifestException;
15
use PharIo\Manifest\ManifestLoader;
16
use PharIo\Version\Version as PharIoVersion;
17
use PHPUnit\Runner\Version;
18
use SebastianBergmann\FileIterator\Facade as FileIteratorFacade;
19
 
20
/**
21
 * @internal This class is not covered by the backward compatibility promise for PHPUnit
22
 */
23
final class PharLoader
24
{
25
    /**
26
     * @psalm-return array{loadedExtensions: list<string>, notLoadedExtensions: list<string>}
27
     */
28
    public function loadPharExtensionsInDirectory(string $directory): array
29
    {
30
        $loadedExtensions    = [];
31
        $notLoadedExtensions = [];
32
 
33
        foreach ((new FileIteratorFacade)->getFilesAsArray($directory, '.phar') as $file) {
34
            if (!is_file('phar://' . $file . '/manifest.xml')) {
35
                $notLoadedExtensions[] = $file . ' is not an extension for PHPUnit';
36
 
37
                continue;
38
            }
39
 
40
            try {
41
                $applicationName = new ApplicationName('phpunit/phpunit');
42
                $version         = new PharIoVersion(Version::series());
43
                $manifest        = ManifestLoader::fromFile('phar://' . $file . '/manifest.xml');
44
 
45
                if (!$manifest->isExtensionFor($applicationName)) {
46
                    $notLoadedExtensions[] = $file . ' is not an extension for PHPUnit';
47
 
48
                    continue;
49
                }
50
 
51
                if (!$manifest->isExtensionFor($applicationName, $version)) {
52
                    $notLoadedExtensions[] = $file . ' is not compatible with this version of PHPUnit';
53
 
54
                    continue;
55
                }
56
            } catch (ManifestException $e) {
57
                $notLoadedExtensions[] = $file . ': ' . $e->getMessage();
58
 
59
                continue;
60
            }
61
 
62
            /**
63
             * @noinspection PhpIncludeInspection
64
             *
65
             * @psalm-suppress UnresolvableInclude
66
             */
67
            require $file;
68
 
69
            $loadedExtensions[] = $manifest->getName()->asString() . ' ' . $manifest->getVersion()->getVersionString();
70
        }
71
 
72
        return [
73
            'loadedExtensions'    => $loadedExtensions,
74
            'notLoadedExtensions' => $notLoadedExtensions,
75
        ];
76
    }
77
}