Files
apimacro/vendor/psy/psysh/src/ParserFactory.php

36 lines
750 B
PHP
Raw Normal View History

2024-05-07 12:17:25 +02:00
<?php
/*
* This file is part of Psy Shell.
*
2024-05-17 12:24:19 +00:00
* (c) 2012-2023 Justin Hileman
2024-05-07 12:17:25 +02:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Psy;
use PhpParser\Parser;
use PhpParser\ParserFactory as OriginalParserFactory;
/**
2024-05-17 12:24:19 +00:00
* Parser factory to abstract over PHP Parser library versions.
2024-05-07 12:17:25 +02:00
*/
class ParserFactory
{
/**
2024-05-17 12:24:19 +00:00
* New parser instance.
2024-05-07 12:17:25 +02:00
*/
2024-05-17 12:24:19 +00:00
public function createParser(): Parser
2024-05-07 12:17:25 +02:00
{
2024-05-17 12:24:19 +00:00
$factory = new OriginalParserFactory();
2024-05-07 12:17:25 +02:00
2024-05-17 12:24:19 +00:00
if (!\method_exists($factory, 'createForHostVersion')) {
return $factory->create(OriginalParserFactory::PREFER_PHP7);
2024-05-07 12:17:25 +02:00
}
2024-05-17 12:24:19 +00:00
return $factory->createForHostVersion();
2024-05-07 12:17:25 +02:00
}
}