|
|
преди 3 месеца | |
|---|---|---|
| bin | преди 6 месеца | |
| src | преди 5 месеца | |
| templates | преди 3 месеца | |
| tests | преди 3 месеца | |
| .gitignore | преди 6 месеца | |
| CHANGELOG.md | преди 3 месеца | |
| LICENSE | преди 6 месеца | |
| QUALITY_REPORT.md | преди 3 месеца | |
| README.md | преди 6 месеца | |
| SETUP.md | преди 6 месеца | |
| UNIT_TESTS.md | преди 6 месеца | |
| composer.json | преди 3 месеца | |
| composer.lock | преди 6 месеца | |
| phpunit.xml | преди 6 месеца |
A powerful command-line tool for generating SixShop extension boilerplate code, designed to streamline the development process within the SixShop ecosystem.
# Install as development dependency
composer require six-shop/maker-bundle --dev
# Or install globally
composer global require six-shop/maker-bundle
# Clone the repository
git clone https://github.com/sixshop/maker-bundle.git
cd maker-bundle
# Install dependencies
composer install
# 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
The tool guides you through a step-by-step process:
$ 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]:
✅ 扩展创建完成!
# 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
$ 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
✅ 迁移文件生成完成!
| 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 |
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');
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
The SixShop Maker Bundle includes a comprehensive unit test suite covering all major functionality:
| 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 |
# 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/
Composer Generator Tests:
Controller Generator Tests:
Entity Generator Tests:
Model Generator Tests:
Migration Generator Tests:
Route Updater Tests:
The tool automatically detects existing composer.json files and offers:
All generated files use PHP templates located in /templates/:
composer.json.tpl.php - Package configurationsrc/Extension.php.tpl.php - Main extension class.gitignore.tpl.php - Git ignore rulesroute/api.php.tpl.php - API routesroute/admin.php.tpl.php - Admin routesconfig.php.tpl.php - Configuration fileinfo.php.tpl.php - Metadata fileTemplates 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 descriptionMaker - Main command controller and user interaction for extension creationComposerGenerator - Handles composer.json generation and detectionDirectoryGenerator - Creates directory structureGitignoreGenerator - Generates .gitignore filesPhpCodeGenerator - Creates PHP source files from templatesMigrationMaker - Enhanced CLI command for database migration generation with full SixShop integrationMigrationGenerator - Core migration file generator using CakePHP MigrationsModelGenerator - ThinkPHP model generator using templates with validation and relationshipsEntityGenerator - Entity class generator using templates with type safety and data validation# 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
# 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
Permission Errors
Error: Target path not writable
Solution: Ensure write permissions on target directory
Missing Dependencies
Error: Composer autoload not found
Solution: Run composer install first
Invalid Package Names
Error: Package name format incorrect
Solution: Use format "vendor/package" with lowercase and hyphens
For verbose output, use PHP's built-in debugging:
# Enable error reporting
php -d display_errors=1 vendor/bin/sixshop-maker
We welcome contributions! Please see our contributing guidelines:
# 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
This project is licensed under the MIT License. See the LICENSE file for details.
Made with ❤️ for the SixShop community