1
0
Fork 0

feat: allow optional path repository

pull/12186/head
Soner Sayakci 2024-11-06 17:03:14 +01:00
parent 3dc279cf66
commit e5ac92b410
No known key found for this signature in database
3 changed files with 14 additions and 2 deletions

View File

@ -930,7 +930,8 @@
"options": { "options": {
"type": "object", "type": "object",
"properties": { "properties": {
"symlink": { "type": ["boolean", "null"] } "symlink": { "type": ["boolean", "null"] },
"optional": { "type": "boolean" }
}, },
"additionalProperties": true "additionalProperties": true
} }

View File

@ -105,7 +105,7 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn
/** /**
* Initializes path repository. * Initializes path repository.
* *
* @param array{url?: string, options?: array{symlink?: bool, reference?: string, relative?: bool, versions?: array<string, string>}} $repoConfig * @param array{url?: string, options?: array{symlink?: bool, reference?: string, relative?: bool, versions?: array<string, string>, optional?: bool}} $repoConfig
*/ */
public function __construct(array $repoConfig, IOInterface $io, Config $config, ?HttpDownloader $httpDownloader = null, ?EventDispatcher $dispatcher = null, ?ProcessExecutor $process = null) public function __construct(array $repoConfig, IOInterface $io, Config $config, ?HttpDownloader $httpDownloader = null, ?EventDispatcher $dispatcher = null, ?ProcessExecutor $process = null)
{ {
@ -160,6 +160,10 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn
} }
} }
if (array_key_exists('optional', $this->options) && $this->options['optional'] === true) {
return;
}
throw new \RuntimeException('The `url` supplied for the path (' . $this->url . ') repository does not exist'); throw new \RuntimeException('The `url` supplied for the path (' . $this->url . ') repository does not exist');
} }

View File

@ -161,6 +161,13 @@ class PathRepositoryTest extends TestCase
} }
} }
public function testLoadPackageFromFileSystemWithIncorrectPathButOptional(): void
{
$repositoryUrl = implode(DIRECTORY_SEPARATOR, [__DIR__, 'Fixtures', 'path', 'missing']);
$repository = $this->createPathRepo(['url' => $repositoryUrl, 'options' => ['optional' => true]]);
self::assertEmpty($repository->getPackages());
}
/** /**
* @param array<mixed> $options * @param array<mixed> $options
*/ */