{"id":25229042,"url":"https://github.com/ajthinking/php-file-manipulator-host","last_synced_at":"2025-04-05T14:12:40.370Z","repository":{"id":32601327,"uuid":"125839278","full_name":"ajthinking/php-file-manipulator-host","owner":"ajthinking","description":"Manipulate PHP files using a fluent syntax","archived":false,"fork":false,"pushed_at":"2023-01-05T03:28:18.000Z","size":1180,"stargazers_count":0,"open_issues_count":23,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-11T10:47:26.183Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajthinking.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-19T10:15:14.000Z","updated_at":"2023-03-17T12:11:00.000Z","dependencies_parsed_at":"2023-01-14T21:45:54.131Z","dependency_job_id":null,"html_url":"https://github.com/ajthinking/php-file-manipulator-host","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajthinking%2Fphp-file-manipulator-host","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajthinking%2Fphp-file-manipulator-host/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajthinking%2Fphp-file-manipulator-host/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajthinking%2Fphp-file-manipulator-host/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajthinking","download_url":"https://codeload.github.com/ajthinking/php-file-manipulator-host/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345844,"owners_count":20924102,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-11T10:46:58.795Z","updated_at":"2025-04-05T14:12:40.353Z","avatar_url":"https://github.com/ajthinking.png","language":"PHP","funding_links":["https://www.patreon.com/ajthinking"],"categories":[],"sub_categories":[],"readme":"# PHP-FILE-MANIPULATOR\nProgramatically manipulate PHP / Laravel files on disk with an intuiutive, fluent API.\n\n## Installation\n```\ncomposer require ajthinking/php-file-manipulator\n```\n\n## Examples\n\n### \n```php\nuse Ajthinking\\PHPFile;\nuse Ajthinking\\LaravelFile;\n\n// list class methods\nPHPFile::load('app/User.php')\n    -\u003eclassMethods()\n\n// move User.php to a Models directory\nPHPFile::load('app/User.php')\n    -\u003enamespace('App\\Models')\n    -\u003emove('app/Models/User.php')\n\n// install a package trait\nPHPFile::load('app/User.php')\n    -\u003eaddUseStatements('Package\\Tool')\n    -\u003eaddTraitUseStatement('Tool')\n    -\u003esave()\n\n// find files with the query builder\nPHPFile::in('database/migrations')\n    -\u003ewhere('classExtends', 'Migration')\n    -\u003eget()\n    -\u003eeach(function($file) {\n        echo $file-\u003eclassName()\n    });\n\n// add relationship methods\nLaravelFile::load('app/User.php')\n    -\u003eaddHasMany('App\\Car')\n    -\u003eaddHasOne('App\\Life')\n    -\u003eaddBelongsTo('App\\Wife')\n    -\u003esave()\n\n// add a route\nLaravelFile::load('routes/web.php')\n    -\u003eaddRoute('dummy', 'Controller@method')\n    -\u003esave()\n    \n// preview will write result relative to storage/.preview\nLaravelFile::load('app/User.php')\n    -\u003esetClassName('Mistake')\n    -\u003epreview()\n\n// add items to protected properties\nLaravelFile::load('app/User.php')\n    -\u003eaddFillable('message')\n    -\u003eaddCasts(['is_admin' =\u003e 'boolean'])\n    -\u003eaddHidden('secret')    \n\n```\n\n## Running tests\n```bash\n# the test suite requires that you have the package installed in a laravel project\nvendor/phpunit/phpunit/phpunit packages/Ajthinking/PHPFileManipulator/tests\n```\n\n## License\nMIT\n\n## Contributing\nPRs and issues are welcome. \n\n## TODO\n\n\n| task | status |\n|------|--------|\n| Make the test work without being inside a host application| - |\n| How handle base_path() when not in a Laravel app? | - |\n| Create a dedicated Storage disk (storage/php-file-manipulator/preview etc) ??? | - |\n| It should be able to add use statements with aliases | - |\n| It should be capable of reading/writing `GroupUse`, example:  `use Package\\{Alfa, Beta};` | - |\n| Simplify adding multiline docblocks on methods | - |\n| Group related resources (PHP/Laravel Reources in separate folders) | - |\n| Can it resolve resources from parent classes and traits??? | - |\n| Add the missing relationships: https://laravel.com/docs/6.x/eloquent-relationships#introduction | - |\n| Make a minimal querybuilder | - |\n| Publish to packagist | - |\n\n## API\n\n| Resource | GET | SET | ADD | REMOVE |\n|------|--------|--------|--------|--------|\n| Namespace | yes | yes | | |\n| Uses | yes | yes | | |\n| ClassName | ```$file-\u003eclassName()``` | ```$file-\u003eclassName('newName)``` | | |\n| ClassExtends | yes | yes | yes | yes |\n| ClassImplements | yes | yes | yes | yes |\n| HasManyMethods |  |  | ```$file-\u003eaddHasManyMethods(['App\\Car'])``` |  |\n\n## Acknowledgements\n* Built with [nikic/php-parser](https://github.com/nikic/php-parser)\n* PSR Printing fixes borrowed from [tcopestake/PHP-Parser-PSR-2-pretty-printer](https://github.com/tcopestake/PHP-Parser-PSR-2-pretty-printer)\n\n## Stay tuned!\nFollow me on twitter: [@ajthinking](https://twitter.com/ajthinking)\n\n\u003ca href=\"https://www.patreon.com/ajthinking\" \u003eHelp me continue this work | Patreon\u003c/a\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajthinking%2Fphp-file-manipulator-host","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajthinking%2Fphp-file-manipulator-host","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajthinking%2Fphp-file-manipulator-host/lists"}