forked from phpactor/phpactor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
phpactorgh-2611: Introduce decorator to expand PHAR files for indexer (…
- Loading branch information
Showing
5 changed files
with
58 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Phpactor\Indexer\Adapter\Php; | ||
|
||
use Iterator; | ||
use IteratorAggregate; | ||
use Phar; | ||
use RecursiveIteratorIterator; | ||
use SplFileInfo; | ||
use Traversable; | ||
use UnexpectedValueException; | ||
|
||
/** | ||
* @implements IteratorAggregate<SplFileInfo> | ||
*/ | ||
class FileInfoPharExpandingIterator implements IteratorAggregate | ||
{ | ||
/** | ||
* @param Iterator<SplFileInfo> $innerIterator | ||
* @param list<string> $supportedExtensions | ||
*/ | ||
public function __construct(private Iterator $innerIterator, private array $supportedExtensions = ['php']) | ||
{ | ||
} | ||
|
||
public function getIterator(): Traversable | ||
{ | ||
foreach ($this->innerIterator as $fileInfo) { | ||
if ($fileInfo->getExtension() !== 'phar') { | ||
yield $fileInfo; | ||
} | ||
try { | ||
$phar = new Phar($fileInfo->getPathname()); | ||
} catch (UnexpectedValueException) { | ||
continue; | ||
} | ||
$iterator = new RecursiveIteratorIterator($phar); | ||
foreach ($iterator as $fileInfo) { | ||
assert($fileInfo instanceof SplFileInfo); | ||
if (!in_array($fileInfo->getExtension(), $this->supportedExtensions)) { | ||
continue; | ||
} | ||
yield $fileInfo; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters