![]() ![]() |
Info | ![]() |
![]() ![]() |
Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2020-05-14 (6 days ago) ![]() | Not yet rated by the users | Total: 63 This week: 63 | All time: 9,672 This week: 7![]() |
Version | License | PHP version | Categories | |||
simple-php-code-pars 0.0.0 | MIT/X Consortium ... | 7 | PHP 5, Parsers |
Collaborate with this project | Author | |
Simple-PHP-Code-Parser - github.com Description This package can parse PHP code to extract its structure. |
|
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) - Class Properties (PHPProperties) - Class Constants (PHPConst) - Class Methods (PHPMethod) - Functions (PHPFunction) - Function / Method Parameter (PHPParameter)
This code is forked from JetBrains/phpstorm-stubs but you can't use the classes from "phpstorm-stubs" directly, because the are in a test namespace and the autoloader is "autoload-dev", so here is a extended version.
We will use: - "PHP Reflection" AND / OR "nikic/PHP-Parser" - phpDocumentor (+ psalm)
composer require voku/simple-php-code-parser
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 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
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.
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() |
||||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Lic. | License text | ||
![]() ![]() |
Example | Example script | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Doc. | Read me |
![]() | simple-php-code-pars-2020-05-14.zip 40KB |
![]() | simple-php-code-pars-2020-05-14.tar.gz 23KB |
![]() | Install with Composer |
Version Control | Reuses | Unique User Downloads | Download Rankings | ||||||||||||||||
100% | 1 |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
Other classes that need this package |
Class | Why it is needed | Dependency |
---|---|---|
PHP Readme Helper | the code parser is needed to get the informations from the php files | Required |