Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
PharSupport
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 mock
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 clearMocks
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 running
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasVendorDirectory
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 vendorPath
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 Hyde\Foundation;
6
7use Hyde\Hyde;
8use Phar;
9
10use function dirname;
11use function is_dir;
12use function rtrim;
13use function str_replace;
14
15/**
16 * Provides experimental support for running the HydeCLI in a standalone Phar archive.
17 *
18 * @experimental
19 *
20 * @internal
21 */
22class PharSupport
23{
24    /** @var array<string, bool> */
25    protected static array $mocks = [];
26
27    public static function mock(string $method, bool $value): void
28    {
29        self::$mocks[$method] = $value;
30    }
31
32    public static function clearMocks(): void
33    {
34        self::$mocks = [];
35    }
36
37    public static function running(): bool
38    {
39        return self::$mocks['running'] ?? Phar::running() !== '';
40    }
41
42    public static function hasVendorDirectory(): bool
43    {
44        return self::$mocks['hasVendorDirectory'] ?? is_dir(Hyde::path('vendor'));
45    }
46
47    public static function vendorPath(string $path = '', string $package = 'framework'): string
48    {
49        return rtrim(str_replace('/', DIRECTORY_SEPARATOR, rtrim(dirname(__DIR__, 3).'/'.$package.'/'.$path, '/\\')), '/\\');
50    }
51}