Download .zip |
Info | View files (50) | Download .zip | 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.
Files |
File | Role | Description | ||
---|---|---|---|---|
.github (4 files) | ||||
src (1 directory) | ||||
tests (5 files) | ||||
.editorconfig | Data | Auxiliary data | ||
.gitattributes | Data | Auxiliary data | ||
.gitignore | Data | Auxiliary data | ||
.scrutinizer.yml | Data | Auxiliary data | ||
.styleci.yml | Data | Auxiliary data | ||
.travis.yml | Data | Auxiliary data | ||
CHANGELOG.md | Data | Auxiliary data | ||
circle.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpcs.php_cs | Example | Example script | ||
phpstan.neon | Data | Auxiliary data | ||
phpunit.xml | Data | Auxiliary data | ||
psalm.xml | Data | Auxiliary data | ||
README.md | Doc. | Read me |
Files | / | .github |
File | Role | Description |
---|---|---|
CONTRIBUTING.md | Data | Auxiliary data |
FUNDING.yml | Data | Auxiliary data |
ISSUE_TEMPLATE.md | Data | Auxiliary data |
PULL_REQUEST_TEMPLATE.md | Data | Auxiliary data |
Files | / | src | / | voku | / | SimplePhpParser | / | Model |
File | Role | Description | ||
---|---|---|---|---|
types (6 files) | ||||
BasePHPClass.php | Class | Class source | ||
BasePHPElement.php | Class | Class source | ||
PHPClass.php | Class | Class source | ||
PHPConst.php | Class | Class source | ||
PHPDefineConstant.php | Class | Class source | ||
PHPDocElement.php | Class | Class source | ||
PHPFunction.php | Class | Class source | ||
PHPInterface.php | Class | Class source | ||
PHPMethod.php | Class | Class source | ||
PHPParameter.php | Class | Class source | ||
PHPProperty.php | Class | Class source |
Files | / | src | / | voku | / | SimplePhpParser | / | Model | / | types |
File | Role | Description |
---|---|---|
ArrayArray.php | Class | Class source |
ArrayFloat.php | Class | Class source |
ArrayInt.php | Class | Class source |
ArrayString.php | Class | Class source |
BooleanFalse.php | Class | Class source |
BooleanTrue.php | Class | Class source |
Files | / | src | / | voku | / | SimplePhpParser | / | Parsers |
File | Role | Description | ||
---|---|---|---|---|
Helper (4 files, 1 directory) | ||||
Visitors (2 files) | ||||
PhpCodeParser.php | Class | Class source |
Files | / | src | / | voku | / | SimplePhpParser | / | Parsers | / | Helper |
File | Role | Description | ||
---|---|---|---|---|
Psalm (2 files) | ||||
DocFactoryProvider.php | Class | Class source | ||
ParserContainer.php | Class | Class source | ||
ParserErrorHandler.php | Class | Class source | ||
Utils.php | Class | Class source |
Files | / | src | / | voku | / | SimplePhpParser | / | Parsers | / | Helper | / | Psalm |
File | Role | Description |
---|---|---|
FakeConfig.php | Class | Class source |
FakeFileProvider.php | Class | Class source |
Files | / | src | / | voku | / | SimplePhpParser | / | Parsers | / | Visitors |
File | Role | Description |
---|---|---|
ASTVisitor.php | Class | Class source |
ParentConnector.php | Class | Class source |
Files | / | tests |
File | Role | Description |
---|---|---|
bootstrap.php | Aux. | Auxiliary script |
Dummy.php | Class | Class source |
Dummy2.php | Class | Class source |
DummyInterface.php | Class | Class source |
ParserTest.php | Class | Class source |
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 |