- What is hyperf/devtool and what problem does it solve?
- hyperf/devtool is a development toolkit for the Hyperf framework that adds gen:* commands to the Hyperf console for scaffolding application components. Instead of hand-writing controllers, models, middleware, listeners, and commands, you answer a few interactive prompts and get a class that already follows Hyperf conventions. It removes repetitive boilerplate setup so your team can spend time on business logic instead of file skeletons.
- How do I install hyperf/devtool in a Hyperf project?
- Install it with Composer, typically as a dev dependency: composer require --dev hyperf/devtool. Once installed, the new gen:* commands appear in the Hyperf console and you run them through your project entry point, for example php bin/hyperf.php gen:controller. No manual service registration is normally required because the package ships its own config provider.
- Can I use hyperf/devtool in a Laravel application?
- No. hyperf/devtool is built specifically for the Hyperf framework and its console, dependency injection container, and annotation scanning. It will not register its gen:* commands in a Laravel application, and the generated code relies on Hyperf-specific annotations and class conventions. For Laravel you should use Artisan's built-in make:* generators instead.
- How is hyperf/devtool different from Laravel's artisan make commands?
- The workflow feels similar, but the output targets Hyperf rather than Laravel. Artisan generators produce Laravel controllers, Eloquent models, and form requests, while hyperf/devtool produces classes wired for Hyperf's annotation-based routing, DI container, and coroutine runtime. If you are porting Laravel habits to Hyperf, the gen:* commands are the closest equivalent to artisan make.
- Which components can I scaffold with the gen:* commands?
- The toolkit covers the common building blocks of a Hyperf application: controllers, models, middleware, listeners, and console commands, plus additional generators for other class types. Each generator writes a file into the conventional directory and namespaces it correctly. That consistency is useful on teams where everyone should place new classes in the same location.
- Should hyperf/devtool be installed as a dev dependency only?
- Yes, it is a development-time tool, so require it with --dev and let Composer exclude it from production installs. Nothing in your running application depends on the generator classes at request time. Using composer install --no-dev on deploy keeps the package and its prompts out of your production image.
- Do generated classes include Hyperf annotations and dependency injection wiring?
- Yes. Generated code is aligned with Hyperf conventions, which means annotation-based configuration and DI-friendly constructors rather than plain PHP stubs. A generated controller, for example, is ready to be discovered by the framework without extra registration. You still need to add your own dependencies and route definitions inside the generated class.
- How do the interactive prompts choose namespaces and file paths?
- The generators ask for the class name and derive the namespace and target path from your answers, following Hyperf's default app structure. That keeps new classes in the expected directory with the correct namespace declaration already in place. If you use a custom application namespace, verify the generated namespace matches your composer autoload mapping before committing.
- Which PHP and Hyperf versions does hyperf/devtool support?
- hyperf/devtool tracks the Hyperf release line, so it generally requires a modern PHP version such as PHP 8.1 or newer and a matching Hyperf major version. Because constraints change between releases, run composer show hyperf/devtool to confirm the exact PHP and hyperf/framework requirements before upgrading. Pairing mismatched versions is the usual cause of missing or failing gen:* commands.
- What should I do if the gen: commands are not listed or not found?
- First confirm the package is actually installed with composer show hyperf/devtool, then clear any cached config or runtime container artifacts before retrying the console command. If the command still does not appear, check that your application's config provider discovery is working and that you are running php bin/hyperf.php from the project root. In production-style environments where dev dependencies are skipped, the generator commands are intentionally absent.