%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : addictionfreeind ( 1003) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system Directory : /home/addictionfreeind/public_html/admin1/vendor/phpro/grumphp/src/Parser/Php/ |
Upload File : |
<?php
declare(strict_types=1);
namespace GrumPHP\Parser\Php;
use GrumPHP\Collection\ParseErrorsCollection;
use GrumPHP\Parser\ParserInterface;
use GrumPHP\Parser\Php\Context\ParserContext;
use GrumPHP\Parser\Php\Factory\ParserFactory;
use GrumPHP\Parser\Php\Factory\TraverserFactory;
use GrumPHP\Util\Filesystem;
use PhpParser\Error;
use PhpParser\Parser;
use SplFileInfo;
class PhpParser implements ParserInterface
{
/**
* @var ParserFactory
*/
private $parserFactory;
/**
* @var TraverserFactory
*/
private $traverserFactory;
/**
* @var array
*/
private $parserOptions = [];
/**
* @var Filesystem
*/
private $filesystem;
/**
* PhpParser constructor.
*/
public function __construct(
ParserFactory $parserFactory,
TraverserFactory $traverserFactory,
Filesystem $filesystem
) {
$this->parserFactory = $parserFactory;
$this->traverserFactory = $traverserFactory;
$this->filesystem = $filesystem;
}
public function setParserOptions(array $options): void
{
$this->parserOptions = $options;
}
public function parse(SplFileInfo $file): ParseErrorsCollection
{
$errors = new ParseErrorsCollection();
$context = new ParserContext($file, $errors);
$parser = $this->parserFactory->createFromOptions($this->parserOptions);
$traverser = $this->traverserFactory->createForTaskContext($this->parserOptions, $context);
try {
$code = $this->filesystem->readFromFileInfo($file);
$stmts = $parser->parse($code);
$traverser->traverse((array) $stmts);
} catch (Error $e) {
$errors->add(PhpParserError::fromParseException($e, $file->getRealPath()));
}
return $errors;
}
public function isInstalled(): bool
{
return interface_exists(Parser::class);
}
}