Download the PHP package ajthinking/archetype without Composer
On this page you can find all versions of the php package ajthinking/archetype. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ajthinking/archetype
More information about ajthinking/archetype
Files in ajthinking/archetype
Package archetype
Short Description Programmatically edit PHP and Laravel files.
License MIT
Informations about the package archetype
Enabling Rapid-Application-Development-tools, PR-bots, code analyzers and other things
- Programatically modify php files with an intuitive top level read/write API
- Read/write on classes, framework- and language constructs using
FileQueryBuilders
andAbstractSyntaxTreeQueryBuilders
Getting started
That's it! Check out introduction of concepts below or review the API examples
PHPFile
read/write API
LaravelFile
read/write API
Show output
File QueryBuilders
Filter and retrieve a set of files to interact with.
Abstract Syntax Tree QueryBuilder
As seen in the previous examples we can query and manipulate nodes with simple or primitive values, such as strings and arrays. However, if we want to perform custom or more in dept queries we must use the ASTQueryBuilder
.
Example: how can we fetch explicit column names in a migration file?
The ASTQueryBuilder examines all possible paths and automatically terminates those that cant complete the query:
The ASTQueryBuilder relies entirely on nikic/php-parser. Available query methods mirror the PhpParser
types and properties. To understand this syntax better you may want to tinker with dd($file->ast())
while building your queries. Basic conventions are listed below.
- Traverse into nodes by using methods (
method()
,staticCall()
...) - Traverse into node properties by accessing properties (
args
,stmts
...) - Filter results with
where(...)
- Resolving matching paths with
get()
ASTQueryBuilder
also supports removing, replacing and injecting nodes :wrench:
Errors 😵
If a file can't be parsed, a FileParseError
will be thrown. This can happen if you try to explicitly load a broken file but also when performing queries matching one or more problematic files.
To see all offending files run php artisan archetype:errors
. To ignore files with problems, put them in config/archetype.php
-> ignored_paths
.
Configuration
Requirmenst
- UNIX filesystem
- PHP >= 7.4
- Laravel >= 7
Contributing
PRs and issues are welcome :pray: Feel free to take a stab at an incomplete test.
Development installation
License
MIT
Acknowledgements
- Built with nikic/php-parser
- PSR Printing fixes borrowed from tcopestake/PHP-Parser-PSR-2-pretty-printer