pxlrbt / php-scoper-prefix-remover
Installs: 1 492
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 3
Forks: 4
Open Issues: 1
Requires
- nikic/php-parser: ^4.10
README
PHP-Scoper Patcher for removing prefixes from global functions/classes/traits.
Installation
composer require --dev pxlrbt/php-scoper-prefix-remover
Usage
Import the required classes either manually or via composer autoloader:
require __DIR__ . '/vendor/autoload.php'; use pxlrbt\PhpScoper\PrefixRemover\IdentifierExtractor; use pxlrbt\PhpScoper\PrefixRemover\RemovePrefixPatcher;
Extract the functions/classes/traits/interfaces you want the prefix removed from a stub file:
$identifiers = (new IdentifierExtractor()) ->addStub('stub-file.php') ->extract();
Add the patcher in the patcher section of PHPScoper and pass the identifiers you extracted earlier:
'patchers' => [ // Some patcher (new RemovePrefixPatcher($identifiers)), // More patchers
WordPress
For removing prefixes from WordPress functions/classes install WordPress stubs.
composer require --dev php-stubs/wordpress-stubs
Then add the stubs file to the extractor:
use pxlrbt\PhpScoper\PrefixRemover\IdentifierExtractor; $identifiers = (new IdentifierExtractor()) ->addStub('vendor/php-stubs/wordpress-stubs/wordpress-stubs.php') ->extract();
Specific PHP version
There might be issues with new reserved keywords (e.g. readonly as new keyword in PHP 8.1 and WordPress function name). You can set the targeted PHP version by providing a non default lexer like this:
use pxlrbt\PhpScoper\PrefixRemover\IdentifierExtractor; use PhpParser\Lexer\Emulative; $identifiers = (new IdentifierExtractor()) ->addStub('vendor/php-stubs/wordpress-stubs/wordpress-stubs.php') ->setLexer(new Emulative(['phpVersion' => '8.0'])) ->extract();