Skip to content

feat(devtool): add --path option to generator commands#7670

Merged
limingxinleo merged 3 commits intohyperf:masterfrom
binaryfire:generator-custom-path
Jan 25, 2026
Merged

feat(devtool): add --path option to generator commands#7670
limingxinleo merged 3 commits intohyperf:masterfrom
binaryfire:generator-custom-path

Conversation

@binaryfire
Copy link
Contributor

This PR adds a --path option to generator commands.

Problem

Currently, the --namespace option lets you set a custom namespace, but the file path is always resolved from composer.json autoload rules. If the namespace is not in composer.json, the command fails.

This makes it difficult to generate files into packages or modules that are not in the root composer.json.

Solution

Add a --path option that allows specifying where the file should be created.

# Generate to a custom location
php bin/hyperf.php gen:class MyClass --namespace="My\Package" --path="packages/my-package/src"

# Absolute paths also work
php bin/hyperf.php gen:class MyClass --namespace="My\Package" --path="/tmp/output"

When --path is not provided, the existing behavior is unchanged.

Changes

- Add --path option to GeneratorCommand::getOptions()
- Update GeneratorCommand::getPath() to use custom path when provided
- Add tests

@limingxinleo limingxinleo merged commit 4c376b1 into hyperf:master Jan 25, 2026
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants