# SixShop Maker Bundle **Repository Path**: sixdec-1/sixshop-maker-bundle ## Basic Information - **Project Name**: SixShop Maker Bundle - **Description**: 这个扩展用来生成sixshop扩展代码 - **Primary Language**: PHP - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-23 - **Last Updated**: 2025-10-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SixShop Maker Bundle A powerful command-line tool for generating SixShop extension boilerplate code, designed to streamline the development process within the SixShop ecosystem. [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![PHP Version](https://img.shields.io/badge/PHP-%3E%3D8.0-blue)](https://php.net) [![ThinkPHP](https://img.shields.io/badge/ThinkPHP-%5E8.1-green)](https://github.com/top-think/framework) ## 🚀 Features ### 🔧 Extension Generation - **Automated Code Generation**: Generates complete SixShop extension structure with zero manual coding - **Intelligent Detection**: Automatically detects existing extensions and pre-fills configuration values - **Smart Path Management**: Flexible target path selection with validation and confirmation - **Template-Based**: Uses configurable PHP templates for consistent code generation - **PSR-4 Compliant**: Generates proper namespace structure and autoloading configuration - **Interactive CLI**: User-friendly command-line interface with helpful prompts and validation ### 📊 Database Migration Generation - **Extension-Aware Migration Generation**: Automatically detects SixShop extension context and configuration - **Complete Code Generation Workflow**: Generates migration files, ThinkPHP models, and entity classes - **Interactive Workflow**: Step-by-step prompts for extension path, table details, and field definitions - **CakePHP Migrations Integration**: Uses the robust CakePHP migrations library for database schema management - **Rich Field Types**: Support for string, integer, text, decimal, boolean, datetime, and more - **Advanced Options**: Field length, nullability, default values, comments, indexes, and unique constraints - **Template-Based Models**: Generated models include validation rules, type casting, and relationship methods ## 📋 Requirements - **PHP**: >= 8.0 - **Composer**: Latest version recommended - **ThinkPHP Framework**: ^8.1 - **Symfony Console**: ^7.3 ## 🛠 Installation ### Via Composer (Recommended) ```bash # Install as development dependency composer require six-shop/maker-bundle --dev # Or install globally composer global require six-shop/maker-bundle ``` ### Manual Installation ```bash # Clone the repository git clone https://github.com/sixshop/maker-bundle.git cd maker-bundle # Install dependencies composer install ``` ## 🎯 Usage ### Extension Generation #### Quick Start ```bash # If installed locally php vendor/bin/sixshop-maker create_extension # If installed globally sixshop-maker create_extension # Or directly php bin/sixshop-maker create_extension # To see all available commands php vendor/bin/sixshop-maker list ``` #### Interactive Workflow The tool guides you through a step-by-step process: 1. **Target Path Selection**: Choose where to generate your extension 2. **Package Configuration**: Set package name, namespace, and description 3. **Extension Settings**: Configure extension ID and metadata 4. **File Generation**: Automatic creation of all necessary files #### Example Session ```bash $ php vendor/bin/sixshop-maker create_extension 请输入扩展生成的目标路径 [/current/path]: ./my-extension 将在以下路径生成扩展: /full/path/to/my-extension 确认使用此路径? [yes] 请输入Composer包名 (例如: six-shop/hello): my-vendor/awesome-extension 请输入包描述 [A SixShop extension package]: My awesome SixShop extension 请输入命名空间 (例如: SixShop\Hello\) [MyVendor\AwesomeExtension\]: 请输入扩展ID [my-vendor-awesome-extension]: ✅ 扩展创建完成! ``` ### Database Migration Generation #### Quick Start ```bash # Create migration with models (fully interactive) php vendor/bin/sixshop-maker create_migration # Add columns to existing table php vendor/bin/sixshop-maker create_migration --action=add_column # Drop columns from table php vendor/bin/sixshop-maker create_migration --action=drop_column ``` #### Interactive Migration Creation ```bash $ php vendor/bin/sixshop-maker create_migration users 📏 生成数据库迁移文件 请输入项目目标路径 (绝对路径或相对路径) [/current/path]: ./my-project 将在以下路径生成迁移文件: /full/path/to/my-project/database/migrations 确认使用此路径? [yes] == 表名: users == == 操作类型: create == 迁移文件将保存在: /full/path/to/my-project/database/migrations 🗒 定义表字段 支持的字段类型: integer, biginteger, string, text, boolean, datetime, timestamp, date, time, decimal, float, binary, json 字段名 (回车结束字段定义): username 字段类型 [string]: string 字段长度 (可选): 100 允许为空? [yes]: no 默认值 (可选): 字段备注 (可选): User login name 创建索引? [no]: no 创建唯一索引? [no]: yes ✓ 已添加字段: username (string) 字段名 (回车结束字段定义): email 字段类型 [string]: string 字段长度 (可选): 255 允许为空? [yes]: no 默认值 (可选): 字段备注 (可选): User email address 创建索引? [no]: no 创建唯一索引? [no]: yes ✓ 已添加字段: email (string) 字段名 (回车结束字段定义): ✅ Migration created: 20231201120000_create_users_table.php ✅ 迁移文件生成完成! ``` #### Supported Field Types | Type | Description | Options | |------|-------------|----------| | `integer` | 32-bit integer | length, null, default, comment, index | | `biginteger` | 64-bit integer | null, default, comment, index | | `string` | Variable-length string | length (default: 255), null, default, comment, index, unique | | `text` | Long text field | null, default, comment | | `boolean` | True/false value | null, default, comment, index | | `decimal` | Fixed-point number | precision, scale, null, default, comment | | `float` | Floating-point number | null, default, comment | | `datetime` | Date and time | null, default, comment | | `timestamp` | Unix timestamp | null, default, comment | | `date` | Date only | null, default, comment | | `time` | Time only | null, default, comment | | `binary` | Binary data | length, null, comment | | `json` | JSON data | null, default, comment | #### Programmatic Usage ```php use SixShop\MakerBundle\Generator\MigrationGenerator; $generator = new MigrationGenerator('/path/to/migrations'); // Define table fields $fields = [ [ 'name' => 'username', 'type' => 'string', 'length' => 100, 'null' => false, 'unique' => true, 'comment' => 'User login name' ], [ 'name' => 'email', 'type' => 'string', 'length' => 255, 'null' => false, 'unique' => true, 'comment' => 'User email address' ] ]; // Generate migration $success = $generator->generateMigration('users', $fields, 'create'); ``` ## 📁 Generated Structure The tool creates a complete extension structure: ``` my-extension/ ├── composer.json # Package configuration ├── .gitignore # Git ignore rules ├── src/ │ └── Extension.php # Main extension class ├── route/ │ ├── api.php # API routes │ └── admin.php # Admin routes ├── config.php # Extension configuration └── info.php # Extension metadata ``` ## 🧪 Testing ### Unit Test Suite The SixShop Maker Bundle includes a comprehensive unit test suite covering all major functionality: #### Test Coverage | Component | Tests | Description | |-----------|-------|--------------| | **ComposerGeneratorTest** | 11 tests | Composer.json generation and validation | | **ControllerGeneratorTest** | 10 tests | API and Admin controller generation | | **EntityGeneratorTest** | 8 tests | Entity class generation with validation | | **ModelGeneratorTest** | 6 tests | ThinkPHP model generation | | **MigrationGeneratorTest** | 8 tests | Database migration generation | | **RouteUpdaterTest** | 10 tests | Route file updating functionality | #### Running Tests ```bash # Run all tests vendor/bin/phpunit # Run with detailed output vendor/bin/phpunit --testdox # Run specific test class vendor/bin/phpunit tests/Unit/Generator/ComposerGeneratorTest.php # Run with coverage (requires Xdebug) vendor/bin/phpunit --coverage-html coverage/ ``` #### Test Categories **Composer Generator Tests:** - ✅ Content generation with proper JSON structure - ✅ PSR-4 autoloading configuration - ✅ SixShop extension metadata - ✅ File saving and directory creation - ✅ Package validation and error handling **Controller Generator Tests:** - ✅ API and Admin controller generation - ✅ RESTful method implementation - ✅ Namespace and import handling - ✅ Validation rule generation - ✅ Entity method integration **Entity Generator Tests:** - ✅ Entity class structure generation - ✅ Method parameter validation - ✅ Namespace and directory handling - ✅ BaseEntity inheritance - ✅ Type safety implementation **Model Generator Tests:** - ✅ ThinkPHP model generation - ✅ Field type mapping - ✅ Validation rules - ✅ Relationship definitions - ✅ Configuration options **Migration Generator Tests:** - ✅ Create table migrations - ✅ Add/drop column operations - ✅ Field type support - ✅ Index and constraint handling - ✅ CakePHP integration **Route Updater Tests:** - ✅ Route file updating - ✅ Resource route generation - ✅ Namespace handling - ✅ Existing route detection - ✅ Error handling #### Test Environment - **Framework**: PHPUnit 10.5+ - **PHP Version**: 8.0+ - **Test Coverage**: 90%+ code coverage - **Isolated Testing**: Each test uses temporary directories - **Mock Objects**: Symfony Console components mocked ## 🔧 Smart Features ### Existing Extension Detection The tool automatically detects existing `composer.json` files and offers: - **One-click regeneration** with existing configuration - **Pre-filled prompts** with current values - **Seamless updates** for existing extensions ### Path Intelligence - **Automatic validation** of target paths - **Permission checking** before generation - **Directory creation** if paths don't exist - **Confirmation prompts** for safety ### Namespace Handling - **Consistent formatting** across all generated files - **PSR-4 compliance** with proper autoloading - **JSON-safe escaping** in configuration files - **User-friendly display** in terminal interfaces ## 🎨 Customization ### Templates All generated files use PHP templates located in `/templates/`: - `composer.json.tpl.php` - Package configuration - `src/Extension.php.tpl.php` - Main extension class - `.gitignore.tpl.php` - Git ignore rules - `route/api.php.tpl.php` - API routes - `route/admin.php.tpl.php` - Admin routes - `config.php.tpl.php` - Configuration file - `info.php.tpl.php` - Metadata file ### Available Variables Templates have access to these variables: - `$name` - Package name (e.g., "vendor/package") - `$namespace` - PHP namespace (e.g., "Vendor\\Package\\") - `$id` - Extension ID (e.g., "vendor-package") - `$description` - Package description ## 🏗 Architecture ### Components #### Extension Generation - **`Maker`** - Main command controller and user interaction for extension creation - **`ComposerGenerator`** - Handles composer.json generation and detection - **`DirectoryGenerator`** - Creates directory structure - **`GitignoreGenerator`** - Generates .gitignore files - **`PhpCodeGenerator`** - Creates PHP source files from templates #### Migration Generation - **`MigrationMaker`** - Enhanced CLI command for database migration generation with full SixShop integration - **`MigrationGenerator`** - Core migration file generator using CakePHP Migrations - **`ModelGenerator`** - ThinkPHP model generator using templates with validation and relationships - **`EntityGenerator`** - Entity class generator using templates with type safety and data validation - **Interactive Field Builder** - Step-by-step field definition interface - **Extension Context Detection** - Automatic detection and parsing of composer.json for extension metadata ### Design Patterns - **Generator Pattern**: Specialized classes for each artifact type - **Template Method**: Consistent generation workflow - **Single Responsibility**: Each generator handles one concern - **Command Pattern**: CLI interface implementation ## 🔄 Workflow Examples ### Creating a New Extension ```bash # Start the maker php vendor/bin/sixshop-maker create_extension # Follow prompts Target Path: ./my-new-extension Package Name: sixshop/payment-gateway Namespace: SixShop\PaymentGateway\ Extension ID: sixshop-payment-gateway # Result: Complete extension ready for development ``` ### Regenerating an Existing Extension ```bash # Run in directory with existing composer.json php vendor/bin/sixshop-maker create_extension # Tool detects existing configuration Found existing composer.json: ./composer.json Package: sixshop/payment-gateway Namespace: SixShop\PaymentGateway\ # Confirm regeneration Use existing configuration? [yes] # Files updated with current templates ``` ## 🐛 Troubleshooting ### Common Issues **Permission Errors** ```bash Error: Target path not writable ``` Solution: Ensure write permissions on target directory **Missing Dependencies** ```bash Error: Composer autoload not found ``` Solution: Run `composer install` first **Invalid Package Names** ```bash Error: Package name format incorrect ``` Solution: Use format "vendor/package" with lowercase and hyphens ### Debug Mode For verbose output, use PHP's built-in debugging: ```bash # Enable error reporting php -d display_errors=1 vendor/bin/sixshop-maker ``` ## 🤝 Contributing We welcome contributions! Please see our contributing guidelines: 1. Fork the repository 2. Create a feature branch 3. Make your changes 4. Add tests if applicable 5. Submit a pull request ### Development Setup ```bash # Clone and setup git clone https://github.com/sixshop/maker-bundle.git cd maker-bundle composer install # Run the tool locally php bin/sixshop-maker list ``` ## 📄 License This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. ## 👥 Authors - **runphp** - *Initial work* - [runphp@qq.com](mailto:runphp@qq.com) ## 🔗 Links - [SixShop Framework](https://github.com/sixshop) - [ThinkPHP Framework](https://github.com/top-think/framework) - [Symfony Console](https://symfony.com/doc/current/console.html) ## 📝 Changelog ### v1.0.0 - Initial release with core generation features - Smart existing extension detection - Flexible path management - Template-based file generation - PSR-4 compliant namespace handling --- **Made with ❤️ for the SixShop community**