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
Code Parser

Code Parser Laravel Package

hyperf/code-parser

A lightweight PHP code parser for Hyperf that uses nikic/php-parser to inspect source as an AST. It helps analyze classes, methods, and properties, traverse nodes with visitors, and support code generation and transformation workflows.

View on GitHub
Deep Wiki
Context7

A code parser component for Hyperf.

Frequently asked questions about Code Parser
What does hyperf/code-parser actually do?
It is a lightweight PHP source-code parser for the Hyperf ecosystem that turns PHP files into structured metadata such as namespaces, classes, methods, properties, parameters, and annotations. It is built on nikic/php-parser and inspects code as an AST so framework components can analyze source without loading or executing it. Typical uses include dependency injection metadata, routing annotation discovery, code generation, and static-analysis workflows.
Can I use hyperf/code-parser in a Laravel application?
It is designed for the Hyperf ecosystem and does not ship a Laravel service provider or Laravel-specific configuration. Hyperf is a coroutine runtime with its own container and lifecycle, so it is not a package you install into a Laravel app to add parsing features. For Laravel projects, use nikic/php-parser directly or Laravel-native reflection and discovery tooling instead.
How do I install hyperf/code-parser with Composer?
You install it with composer require hyperf/code-parser, but in practice it usually arrives as a transitive dependency of Hyperf components rather than being required on its own. Confirm your project already targets the Hyperf 3.2 baseline, which pins nikic/php-parser 5.6. Run composer why-not against your lock file if resolution fails, since conflicting Symfony or parser constraints will block the install.
What PHP version and dependencies does hyperf/code-parser require?
The parser requires PHP 8.2 or newer and depends on nikic/php-parser 5.6. In the wider Hyperf 3.2 release the framework also expects Symfony 6 or 7, PHPUnit 11, Guzzle 7, and either Elasticsearch 8 or 9, so those constraints can affect resolution. Check transitive pins on Symfony 5 or Carbon 2 before adopting it in an existing project.
Does it read docblocks and annotations for dependency injection and routing?
Yes. It extracts docblocks and annotations alongside class, method, property, and parameter metadata, which is what lets Hyperf components wire dependency injection and discover routing definitions from source. The parser returns that metadata as data structures; the component using it decides how annotations map to container bindings or routes. Laravel developers would need to write their own driver to interpret that metadata against Laravel's container and router.
Can hyperf/code-parser be used for code generation and static analysis?
Yes, code generation and transformation are core intended use cases. Because parsing is AST-based, you can traverse nodes with visitors, inspect structure, and emit or rewrite source without loading the classes. That makes it suitable for scaffolding, migration tooling, and analysis passes that run outside the request path.
How does hyperf/code-parser perform on large codebases?
It is lightweight because it parses files as text into an AST instead of autoloading and reflecting on classes, so it avoids bootstrapping application code. Parsing still costs CPU, so in long-lived coroutine workers you should cache or precompute metadata rather than re-parsing every request. For build-time analysis, parsing once during deploy and storing the results is the safest pattern.
How do I test code that relies on hyperf/code-parser?
The Hyperf 3.2 baseline uses PHPUnit 11, so unit tests can feed fixture PHP files through the parser and assert on the resulting metadata or visitor output. Keep fixtures small and representative, and assert on structural data rather than exact AST node ordering. Avoid sharing mutable parser or visitor state across coroutine tests.
What are the alternatives to hyperf/code-parser for Laravel projects?
The closest alternative is nikic/php-parser used directly, which is the same underlying engine and gives you full control over visitors and node handling. For simpler needs, native PHP Reflection or Laravel's own discovery and attribute scanning may be enough. Tools such as laravel-ide-helper or better-reflection style libraries cover specific metadata and IDE use cases without adopting a Hyperf dependency.
Is hyperf/code-parser maintained, and is it semver-safe to upgrade?
It is maintained inside the Hyperf monorepo and versioned alongside Hyperf releases, so it carries no Laravel version constraint. The 3.2 release is an example of a minor version carrying breaking changes across the framework, so treat upgrades as review-gated rather than automatic. Pin your version, snapshot composer.lock, and confirm the 3.1 patch horizon if you need to defer the move.
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.
vento/laravel-airbrake
wfeller/laravel-batch
maco-studios/mage-os-installer
busarm/armie
siberfx/laravel-logger
kfteam1991/dcat-admin
dashed/dashed-laposta
dashed/dashed-ecommerce-montaportal
dashed/dashed-ecommerce-etsy
neohq/string-blade-compiler
log1x/acf-composer
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