1
0
Fork 0
php-language-server/src/Index/ProjectIndex.php

52 lines
1.1 KiB
PHP
Raw Normal View History

2016-12-13 00:51:02 +00:00
<?php
declare(strict_types = 1);
namespace LanguageServer\Index;
/**
* A project index manages the source and dependency indexes
*/
class ProjectIndex extends AbstractAggregateIndex
{
/**
* The index for dependencies
*
* @var DependenciesIndex
*/
private $dependenciesIndex;
/**
* The Index for the project source
*
* @var Index
*/
private $sourceIndex;
public function __construct(Index $sourceIndex, DependenciesIndex $dependenciesIndex)
{
$this->sourceIndex = $sourceIndex;
$this->dependenciesIndex = $dependenciesIndex;
}
/**
* @return ReadableIndex[]
*/
protected function getIndexes(): array
{
return [$this->sourceIndex, $this->dependenciesIndex];
}
/**
* @param string $uri
* @return Index
*/
public function getIndexForUri(string $uri): Index
{
if (preg_match('/\/vendor\/([^\/]+\/[^\/]+)\//', $uri, $matches)) {
$packageName = $matches[1];
2016-12-13 00:51:02 +00:00
return $this->dependenciesIndex->getDependencyIndex($packageName);
}
return $this->sourceIndex;
}
}