PHPackages                             ajthinking/php-file-manipulator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. ajthinking/php-file-manipulator

ActivePackage[Parsing &amp; Serialization](/categories/parsing)

ajthinking/php-file-manipulator
===============================

Programmatically edit PHP and Laravel files.

v2.0.0(2y ago)27212419[2 issues](https://github.com/ajthinking/archetype/issues)MITPHPCI failing

Since Jan 3Pushed 2y ago3 watchersCompare

[ Source](https://github.com/ajthinking/archetype)[ Packagist](https://packagist.org/packages/ajthinking/php-file-manipulator)[ RSS](/packages/ajthinking-php-file-manipulator/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (10)Dependencies (6)Versions (85)Used By (0)

[![image](https://user-images.githubusercontent.com/3457668/148050728-f80fb02c-e24e-4957-b960-8e52796fbf23.png)](https://user-images.githubusercontent.com/3457668/148050728-f80fb02c-e24e-4957-b960-8e52796fbf23.png)

### Enabling Rapid-Application-Development-tools, PR-bots, code analyzers and other things

[](#enabling-rapid-application-development-tools-pr-bots-code-analyzers-and-other-things)

[![tests](https://github.com/ajthinking/archetype/workflows/tests/badge.svg)](https://github.com/ajthinking/archetype/workflows/tests/badge.svg)[![version](https://camo.githubusercontent.com/48a8e440eb156c3c24317e8f77775d3df20008dfd7fe02d59d61dc6c092b30bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616a7468696e6b696e672f6172636865747970653f636f6c6f723d626c7565)](https://camo.githubusercontent.com/48a8e440eb156c3c24317e8f77775d3df20008dfd7fe02d59d61dc6c092b30bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616a7468696e6b696e672f6172636865747970653f636f6c6f723d626c7565)[![Total Downloads](https://camo.githubusercontent.com/4d6b6211490ad1588472327ff8c887f97beea05bdf65d3179097d7e38b034b6c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616a7468696e6b696e672f6172636865747970652e737667)](https://packagist.org/packages/ajthinking/archetype)

- Programatically modify php files with an intuitive top level read/write API
- Read/write on classes, framework- and language constructs using `FileQueryBuilders` and `AbstractSyntaxTreeQueryBuilders`

Getting started
---------------

[](#getting-started)

```
composer require ajthinking/archetype
```

>

That's it! Check out introduction of concepts below or review the [API examples](docs.md)

`PHPFile` read/write API
------------------------

[](#phpfile-readwrite-api)

```
use Archetype\Facades\PHPFile;

// Create new files
PHPFile::make()->class(\Acme\Product::class)
    ->use('Shippable')
    ->public()->property('stock', -1)
    ->save();
```

```
// Modify existing files
PHPFile::load(\App\Models\User::class)
    ->className('NewClassName')
    ->save();
```

`LaravelFile` read/write API
----------------------------

[](#laravelfile-readwrite-api)

```
use Archetype\Facades\LaravelFile; // extends PHPFile

// Expanding on our User model
LaravelFile::user()
    ->add()->use(['App\Traits\Dumpable', 'App\Contracts\PlayerInterface'])
    ->add()->implements('PlayerInterface')
    ->table('gdpr_users')
    ->add()->fillable('nickname')
    ->remove()->hidden()
    ->empty()->casts()
    ->hasMany('App\Game')
    ->belongsTo('App\Guild')
    ->save()
    ->render();
```

Show output```
