VOOZH about

URL: https://deepwiki.com/hypervel/devtool/2-getting-started

⇱ Getting Started | hypervel/devtool | DeepWiki


Loading...
Menu

Getting Started

This document covers the installation and initial setup of the Hypervel/Devtool package, including package installation via Composer, automatic command registration, and basic usage of the make:* command suite. For detailed information about the system architecture and how commands are registered internally, see System Architecture. For comprehensive documentation of individual generators, see sections 5 through 11.


Installation Requirements

The Hypervel/Devtool package requires the following dependencies:

RequirementVersionPurpose
PHP^8.2Runtime environment
hyperf/devtool~3.1.0Base generator framework and command infrastructure

The hyperf/devtool package provides the GeneratorCommand base class that all code generators extend. The Hypervel/Devtool package implements a fail-safe pattern: if GeneratorCommand is not available, the ConfigProvider() returns an empty configuration array, preventing registration errors.

Sources: composer.json22-25 src/ConfigProvider.php43-45


Installing via Composer

Install the package using Composer:


The package is typically installed as a development dependency since code generation tools are not needed in production environments.

Package Metadata:


The composer.json() defines:

  • PSR-4 autoloading: Maps Hypervel\Devtool\ namespace to src/ directory
  • Hyperf auto-discovery: The extra.hyperf.config key points to Hypervel\Devtool\ConfigProvider, enabling automatic command registration during framework bootstrap

Sources: composer.json1-43


Automatic Command Registration

After installation, Hyperf's package discovery mechanism automatically registers all commands without manual configuration.

Registration Flow:


The ConfigProvider() method performs a dependency check before registering commands. This pattern prevents errors if the base hyperf/devtool package is not installed.

Command Registration Implementation:

The ConfigProvider returns an array with a commands key containing all command class names:


Sources: src/ConfigProvider.php39-82 composer.json31-34


Verifying Installation

After installation, verify that commands are registered by listing available Artisan commands:


This displays all registered make:* commands. Expected output includes:

CommandPurpose
make:modelGenerate model class
make:controllerGenerate controller class
make:middlewareGenerate middleware class
make:requestGenerate FormRequest class
make:resourceGenerate API resource class
make:factoryGenerate model factory
make:seederGenerate database seeder
make:migrationGenerate database migration
make:observerGenerate model observer
make:policyGenerate authorization policy
make:commandGenerate console command
make:ruleGenerate validation rule
make:exceptionGenerate exception class
make:testGenerate PHPUnit test
...16+ additional commands

Command Categories:


Sources: src/ConfigProvider.php48-79


Basic Usage: Your First Commands

Generating a Model

Create a basic model class:


This generates app/Models/User.php. The ModelCommand() class orchestrates model generation and can invoke related generators.

Generate model with additional components:


The --all flag generates:

  • Model class (app/Models/Post.php)
  • Factory class (database/factories/PostFactory.php)
  • Seeder class (database/seeders/PostSeeder.php)
  • Migration file (database/migrations/YYYY_MM_DD_HHMMSS_create_posts_table.php)
  • Controller class (app/Controllers/PostController.php)
  • Policy class (app/Policies/PostPolicy.php)

See Model and Factory Generation for detailed options.

Generating a Controller

Create a resource controller:


This generates app/Controllers/PostController.php with RESTful methods: index(), store(), show(), update(), destroy().

Generate controller with model binding:


This generates a controller with type-hinted model parameters in route methods. See Controller Generation for comprehensive options including --api and --requests flags.

Generating Middleware

Create middleware for request processing:


Generates app/Middleware/CheckApiToken.php implementing the middleware interface. The --psr15 flag generates PSR-15 compliant middleware. See Middleware Generation.

Generating a Database Migration

Create a migration for framework tables:


Generates a timestamped migration file for the cache database driver. Other table generators include:

  • make:session-table - Session storage
  • make:queue-table - Job queue storage
  • make:queue-failed-table - Failed job tracking
  • make:notifications-table - Database notification storage

See Database Migration Generators for all available table generators.

Sources: Various generator command files referenced in src/ConfigProvider.php48-79


Basic Configuration

Customizing Output Paths

Hyperf's generator system reads namespace and path configuration from config/autoload/devtool.php. Create this file to customize generator behavior:


Custom Stub Templates

Override default stub templates by publishing them to your project:


Modify stub files in the ./stubs directory. Generators check for local stubs before using package defaults. See Stub Template System for placeholder syntax and customization options.

Sources: Hyperf framework documentation (configuration convention)


Development Workflow

Typical Command Sequence:


Alternative: Use Orchestration:


The ModelCommand orchestrator pattern automatically invokes dependent generators, reducing manual command execution. See Generator Command Architecture for orchestration details.

Sources: src/Generator/ModelCommand.php (orchestration pattern)


Hot-Reload Development Server

For active development, use the watch command to automatically restart the server when files change:


The WatchCommand() requires the hyperf/watcher package. If not installed, it displays an error message and exits gracefully.

Configuration Options:

OptionShortDescription
--config-CCustom config file path (default: .watcher.php)
--file-FSpecific files to watch (repeatable)
--dir-DSpecific directories to watch (repeatable)
--no-restart-NDisable server restart on changes

Example with custom directories:


See File Watching and Hot Reload for configuration details.

Sources: src/Commands/WatchCommand.php1-66


Next Steps

After completing basic setup:

  1. Explore Code Generators: Review Model System Generators, HTTP Layer Generators, and Additional Generators for detailed command options
  2. Understand Architecture: Read System Architecture to understand how ConfigProvider registration and the generator pattern work
  3. Learn Stub Customization: See Stub Template System to customize generated code templates
  4. Configure Development Tools: Set up File Watching and explore the Event Inspector

All make:* commands support the --help flag for usage information:


Sources: General documentation structure