Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ajthinking/php-file-manipulator-host
Manipulate PHP files using a fluent syntax
https://github.com/ajthinking/php-file-manipulator-host
Last synced: 3 days ago
JSON representation
Manipulate PHP files using a fluent syntax
- Host: GitHub
- URL: https://github.com/ajthinking/php-file-manipulator-host
- Owner: ajthinking
- Created: 2018-03-19T10:15:14.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T03:28:18.000Z (about 2 years ago)
- Last Synced: 2024-05-01T14:54:31.330Z (10 months ago)
- Language: PHP
- Size: 1.13 MB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 23
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# PHP-FILE-MANIPULATOR
Programatically manipulate PHP / Laravel files on disk with an intuiutive, fluent API.## Installation
```
composer require ajthinking/php-file-manipulator
```## Examples
###
```php
use Ajthinking\PHPFile;
use Ajthinking\LaravelFile;// list class methods
PHPFile::load('app/User.php')
->classMethods()// move User.php to a Models directory
PHPFile::load('app/User.php')
->namespace('App\Models')
->move('app/Models/User.php')// install a package trait
PHPFile::load('app/User.php')
->addUseStatements('Package\Tool')
->addTraitUseStatement('Tool')
->save()// find files with the query builder
PHPFile::in('database/migrations')
->where('classExtends', 'Migration')
->get()
->each(function($file) {
echo $file->className()
});// add relationship methods
LaravelFile::load('app/User.php')
->addHasMany('App\Car')
->addHasOne('App\Life')
->addBelongsTo('App\Wife')
->save()// add a route
LaravelFile::load('routes/web.php')
->addRoute('dummy', 'Controller@method')
->save()
// preview will write result relative to storage/.preview
LaravelFile::load('app/User.php')
->setClassName('Mistake')
->preview()// add items to protected properties
LaravelFile::load('app/User.php')
->addFillable('message')
->addCasts(['is_admin' => 'boolean'])
->addHidden('secret')```
## Running tests
```bash
# the test suite requires that you have the package installed in a laravel project
vendor/phpunit/phpunit/phpunit packages/Ajthinking/PHPFileManipulator/tests
```## License
MIT## Contributing
PRs and issues are welcome.## TODO
| task | status |
|------|--------|
| Make the test work without being inside a host application| - |
| How handle base_path() when not in a Laravel app? | - |
| Create a dedicated Storage disk (storage/php-file-manipulator/preview etc) ??? | - |
| It should be able to add use statements with aliases | - |
| It should be capable of reading/writing `GroupUse`, example: `use Package\{Alfa, Beta};` | - |
| Simplify adding multiline docblocks on methods | - |
| Group related resources (PHP/Laravel Reources in separate folders) | - |
| Can it resolve resources from parent classes and traits??? | - |
| Add the missing relationships: https://laravel.com/docs/6.x/eloquent-relationships#introduction | - |
| Make a minimal querybuilder | - |
| Publish to packagist | - |## API
| Resource | GET | SET | ADD | REMOVE |
|------|--------|--------|--------|--------|
| Namespace | yes | yes | | |
| Uses | yes | yes | | |
| ClassName | ```$file->className()``` | ```$file->className('newName)``` | | |
| ClassExtends | yes | yes | yes | yes |
| ClassImplements | yes | yes | yes | yes |
| HasManyMethods | | | ```$file->addHasManyMethods(['App\Car'])``` | |## Acknowledgements
* Built with [nikic/php-parser](https://github.com/nikic/php-parser)
* PSR Printing fixes borrowed from [tcopestake/PHP-Parser-PSR-2-pretty-printer](https://github.com/tcopestake/PHP-Parser-PSR-2-pretty-printer)## Stay tuned!
Follow me on twitter: [@ajthinking](https://twitter.com/ajthinking)