Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Php File Manipulator

Php File Manipulator Laravel Package

ajthinking/php-file-manipulator

Manipulate PHP files programmatically with a clean, fluent API. Read, modify, and rewrite classes, methods, properties, and namespaces without fragile regex, making code generation and refactoring safe and predictable.

View on GitHub
Deep Wiki
Context7

Programmatically edit PHP and Laravel files.

Frequently asked questions about Php File Manipulator
What is ajthinking/php-file-manipulator (Archetype) used for?
Archetype is a PHP package that lets you read, modify, and rewrite PHP and Laravel source files through a clean, fluent API. Instead of patching code with brittle regex, it works on the parsed syntax tree so you can safely change classes, methods, properties, and namespaces. Typical uses are code generation, automated refactoring, and introspecting Laravel structures such as models, controllers, and service providers. It is best treated as a development or static-analysis dependency rather than a runtime library.
How do I install Archetype in a Laravel project?
Install it with Composer, normally as a dev dependency since it is a development and static-analysis tool rather than a runtime library. On PHP 8.1 through 8.4 it resolves to the 2.x line, which pulls in nikic/php-parser ^5.0. Composer will stop resolution if your project is pinned to php-parser 4.x, which is the usual cause of a failed install. After installing, run your test suite and any analysis scripts to confirm parity.
Which PHP and Laravel versions does Archetype 2.x support?
Version 2.x requires PHP 8.1 or higher and fits Laravel 10, 11, 12, and 13, using php-parser ^5.0. Older stacks, meaning PHP 7.4 through 8.1 with Laravel 6 through 9, stay on the 1.x line with its php-parser ^4.11 constraint. The 2.0.1 release adds an explicit PHP requirement so the platform expectation is clear during Composer resolution. CI covers twelve PHP and Laravel combinations plus macOS and PHPStan runs.
Can I upgrade from Archetype 1.x to 2.0.1 without changing my code?
Yes, the release notes state no application code changes are required, so treat the upgrade as a dependency-resolution task rather than a rewrite. From 2.0.0 you can upgrade directly on PHP 8.1 or newer; from 1.x you mainly need to resolve conflicts with the old php-parser ^4.11 pin. Update your Composer constraints, clear php-parser 5 conflicts, and then run your full test suite. Re-run any Archetype-based introspection jobs and compare their output before rolling out.
How do I modify a class method programmatically without regex?
Archetype parses the file into an abstract syntax tree and exposes a fluent API for navigating to a class, its methods, properties, and namespace. You locate the node you want, change or add what you need, and write the file back out, so the result stays syntactically valid. Because edits happen on the tree rather than on raw text, formatting quirks and nested braces do not break the change. That makes it suitable for repeatable code generation and refactoring jobs.
Does Archetype use regex or a real PHP parser?
It uses nikic/php-parser, the same AST engine behind much of the PHP static-analysis ecosystem, rather than pattern matching on raw text. That is why it can rewrite classes, methods, properties, and namespaces predictably instead of failing on edge cases. Version 2.x depends on php-parser ^5.0, while the legacy 1.x line is pinned to ^4.11. The trade-off is a dependency constraint you must resolve alongside tools like Pest 3.
Should Archetype be a production runtime dependency?
No, it is best classified as a development or static-analysis dependency for codebase introspection and code generation. It fits into CI tooling, refactoring scripts, and generators rather than request-handling code paths. Keeping it in require-dev also avoids shipping the parser and its transitive dependencies to production. If you do need it at runtime for a specific generator, document why and pin the major version.
Is Archetype safe to use with Statamic-based projects?
The largest known consumer of Archetype is Statamic, which is a positive ecosystem signal and means the most exercised paths are well covered. Version 2.0.1 resolves cleanly on Statamic 5 with Laravel 12 and Statamic 6 with Laravel 13, producing byte-identical output to 2.0.0 across every path Statamic exercises. Statamic 4 and 3.4 remain on ^1.0.3 and are unaffected by the 2.x release. Custom Archetype queries outside Statamic's usage should still be validated with your own tests.
What are the alternatives to Archetype for manipulating PHP files?
The underlying engine is nikic/php-parser, which you can use directly if you want full control over node traversal and printing. For refactoring at scale there are tools like Rector, which focus on automated upgrade and transformation rules rather than a fluent editing API. Archetype's value is the Laravel-aware, fluent layer on top of the parser, so pick it when you want concise code generation and introspection rather than a full rule-based refactoring framework. Evaluate against your team's need for Laravel-specific structure discovery.
Is Archetype maintained, and will it work on PHP 9?
Version 2.0.1 is a low-churn maintenance release that adds a changelog, LICENSE.md, Dependabot configuration, an explicit PHP requirement, and verified CI coverage across PHP and Laravel combinations. It also fixes ->throw() matching, broadens getReflection() error handling from Exception to Throwable, resolves PHP 8.4 implicit-nullable deprecations, and corrects shipped config paths. The known forward-looking risk is PHP 9: the package deliberately caps PHP compatibility because its AST node-identity mechanism relies on dynamic properties. Composer will fail fast rather than install a package that fatals, but that leaves a future migration obligation to plan for.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager