voku / simple-php-code-parser
Get a simple data structure from your php code.
Fund package maintenance!
voku
Patreon
www.paypal.me/moelleken
Installs: 2 753
Dependents: 2
Suggesters: 0
Security: 0
Stars: 47
Watchers: 6
Forks: 6
Open Issues: 13
Requires
- php: >=7.4
- nikic/php-parser: ~4.16
- phpdocumentor/reflection-common: ~2.2
- phpdocumentor/reflection-docblock: ~5.3
- phpdocumentor/type-resolver: ~1.7.2
- phpstan/phpdoc-parser: ~1.23
- react/async: ~3.0.0 || ~4.1.0
- react/filesystem: ^0.2@dev
- voku/simple-cache: ~4.1
Requires (Dev)
- phpunit/phpunit: ~6.0 || ~7.0 || ~9.0
- dev-master
- 0.20.1
- 0.20.0
- 0.19.6
- 0.19.5
- 0.19.4
- 0.19.3
- 0.19.2
- 0.19.1
- 0.19.0
- 0.18.2
- 0.18.0
- 0.17.0
- 0.16.6
- 0.16.5
- 0.16.4
- 0.16.3
- 0.16.2
- 0.16.1
- 0.16.0
- 0.15.3
- 0.15.2
- 0.15.1
- 0.15.0
- 0.14.0
- 0.13.2
- 0.13.1
- 0.13.0
- 0.12.0
- 0.11.0
- 0.10.0
- 0.9.0
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5.0
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.0
- dev-renovate/codecov-codecov-action-5.x
- dev-renovate/phpdocumentor-type-resolver-1.x
- dev-renovate/actions-checkout-digest
- dev-renovate/actions-cache-4.x
- dev-renovate/shivammathur-setup-php-2.x
- dev-renovate/react-async-4.x
- dev-renovate/major-github-artifact-actions
- dev-renovate/phpunit-phpunit-11.x
- dev-renovate/codecov-codecov-action-4.x
- dev-renovate/actions-cache-3.x
- dev-renovate/nikic-php-parser-5.x
- dev-analysis-dj2339
- dev-analysis-O3BxNL
- dev-analysis-YO03Ro
- dev-analysis-vZMo3r
- dev-analysis-PG5Ew9
- dev-analysis-marjMb
- dev-analysis-M1QJ1K
- dev-analysis-L37kEk
- dev-whitesource/configure
- dev-analysis-1boDOw
- dev-analysis-QMj9Yp
- dev-analysis-QM2ejO
- dev-analysis-QMpwV3
- dev-analysis-ajJopY
- dev-analysis-OMrl1l
This package is auto-updated.
Last update: 2024-11-14 17:32:42 UTC
README
❤ Simple PHP Code Parser
You can simply scan a string, a file or a full directory and you can see a simple data structure from your php code.
- Classes (PHPClass)
- Properties (PHPProperties)
- Constants (PHPConst)
- Methods (PHPMethod)
- Interfaces (PHPInterface)
- Traits (PHPTrait)
- Functions (PHPFunction)
- Parameter (PHPParameter)
This code is forked from JetBrains/phpstorm-stubs but you can't use the classes from "phpstorm-stubs" directly, because they are in a test namespace and the autoloader is "autoload-dev", so here is a extended version.
We will use:
Install via "composer require"
composer require voku/simple-php-code-parser
Quick Start
Parse a string:
$code = ' <?php namespace voku\tests; class SimpleClass {} $obja = new class() {}; $objb = new class {}; class AnotherClass {} '; $phpCode = \voku\SimplePhpParser\Parsers\PhpCodeParser::getFromString($code); $phpClasses = $phpCode->getClasses(); var_dump($phpClasses['voku\tests\SimpleClass']); // "PHPClass"-object
Parse one class:
$phpCode = \voku\SimplePhpParser\Parsers\PhpCodeParser::getFromClassName(Dummy::class); $phpClasses = $phpCode->getClasses(); var_dump($phpClasses[Dummy::class]); // "PHPClass"-object var_dump($phpClasses[Dummy::class]->methods); // "PHPMethod[]"-objects var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']); // "PHPMethod"-object var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']->parameters); // "PHPParameter[]"-objects var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']->parameters['useRandInt']); // "PHPParameter"-object var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']->parameters['useRandInt']->type); // "bool"
Parse one file:
$phpCode = \voku\SimplePhpParser\Parsers\PhpCodeParser::getPhpFiles(__DIR__ . '/Dummy.php'); $phpClasses = $phpCode->getClasses(); var_dump($phpClasses[Dummy::class]); // "PHPClass"-object var_dump($phpClasses[Dummy::class]->methods); // "PHPMethod[]"-objects var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']); // "PHPMethod"-object var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']->parameters); // "PHPParameter[]"-objects var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']->parameters['useRandInt']); // "PHPParameter"-object var_dump($phpClasses[Dummy::class]->methods['withoutPhpDocParam']->parameters['useRandInt']->type); // "bool"
Parse many files:
$phpCode = \voku\SimplePhpParser\Parsers\PhpCodeParser::getPhpFiles(__DIR__ . '/src'); $phpClasses = $phpCode->getClasses(); var_dump($phpClasses[Dummy::class]); // "PHPClass"-object
Support
For support and donations please visit Github | Issues | PayPal | Patreon.
For status updates and release announcements please visit Releases | Twitter | Patreon.
For professional support please contact me.
Thanks
- Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
- Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
- Thanks to StyleCI for the simple but powerfull code style check.
- Thanks to PHPStan && Psalm for really great Static analysis tools and for discover bugs in the code!