davidgamboa/magento2-module-scaffold 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

davidgamboa/magento2-module-scaffold

Composer 安装命令:

composer create-project davidgamboa/magento2-module-scaffold

包简介

CLI to scaffold Magento 2 modules in one command

README 文档

README

CLI to scaffold Magento 2 modules in one command. Installs globally via Composer — no Magento installation required.

composer global require davidgamboa/magento2-module-scaffold
scaffold make Acme/ProductEvents --type=observer --class=ProductSave --event=catalog_product_save_after

Installation

composer global require davidgamboa/magento2-module-scaffold

Make sure ~/.config/composer/vendor/bin (or ~/.composer/vendor/bin) is in your PATH:

export PATH="$PATH:$HOME/.config/composer/vendor/bin"

Usage

scaffold make Vendor/Module --type=<type> [options]

Vendor/Module must follow PascalCase: Acme/ProductEvents, not acme/productevents.

Output directory

The output directory is resolved in this order:

  1. --output=<path> — explicit override
  2. Magento root auto-detection — walks up from your current directory looking for bin/magento, then writes to {magento_root}/app/code/Vendor/Module/
  3. Fallback — {CWD}/Vendor/Module/

Global options

Option Description
--output=<path> Override output directory
--dry-run Print files that would be generated without writing
--force Overwrite if the output directory already exists

Interactive mode

Any missing required argument triggers a prompt:

$ scaffold make MyVendor/MyModule

Module type:
  [0] observer
  [1] plugin
  ...
> 0

Observer class name [MyModuleObserver]: ProductSave
Event name [catalog_product_save_after]:

✓ Generated MyVendor/MyModule (observer) → app/code/MyVendor/MyModule/

Module types

observer

Generates an event observer.

scaffold make Acme/ProductEvents \
  --type=observer \
  --class=ProductSaveObserver \
  --event=catalog_product_save_after \
  --output=app/code/Acme/ProductEvents

Generated files:

registration.php
etc/module.xml
etc/di.xml
etc/events.xml
Observer/ProductSaveObserver.php
composer.json

etc/events.xml registers the observer on the given event. Observer/ProductSaveObserver.php implements ObserverInterface with an execute() stub.

plugin

Generates a Magento plugin (interceptor) for a target class method.

scaffold make Acme/Catalog \
  --type=plugin \
  --class=ProductPlugin \
  --target="Magento\Catalog\Model\Product" \
  --method=getName

Generated files:

registration.php
etc/module.xml
etc/di.xml          ← <type> block with plugin registration
Plugin/ProductPlugin.php
composer.json

The plugin class includes before, after, and around stubs for the target method.

cron

Generates a Magento cron job.

scaffold make Acme/Imports \
  --type=cron \
  --class=ImportProducts \
  --schedule="0 2 * * *"

Generated files:

registration.php
etc/module.xml
etc/di.xml
etc/crontab.xml
Cron/ImportProducts.php
composer.json

graphql

Generates a GraphQL resolver.

scaffold make Acme/ProductGraph \
  --type=graphql \
  --class=ProductResolver \
  --field=products

Generated files:

registration.php
etc/module.xml
etc/di.xml
etc/schema.graphqls
Model/Resolver/ProductResolver.php
composer.json

etc/schema.graphqls adds a field to the Query type. The resolver implements Magento's ResolverInterface.

api

Generates a REST API endpoint with interface, repository implementation, and DI preference binding.

scaffold make Acme/ProductApi \
  --type=api \
  --class=ProductRepository \
  --interface=ProductRepositoryInterface

Generated files:

registration.php
etc/module.xml
etc/di.xml          ← preference binding
etc/webapi.xml      ← GET/POST/DELETE routes
Api/ProductRepositoryInterface.php
Model/ProductRepository.php
composer.json

command

Generates a Magento CLI command (bin/magento my:command).

scaffold make Acme/Tools \
  --type=command \
  --class=ImportCommand \
  --command-name=import:products

Generated files:

registration.php
etc/module.xml
etc/di.xml          ← injects command into CommandListInterface
Console/Command/ImportCommand.php
composer.json

Files generated for every type

Every module type includes these four files:

File Purpose
registration.php Registers the module with Magento's ComponentRegistrar
etc/module.xml Declares the module name and version
composer.json PSR-4 autoload + magento/framework require
etc/di.xml Base DI config (extended by plugin/api/command types)

Requirements

  • PHP >= 8.1
  • Composer

No Magento installation needed. The tool generates files you then drop into any Magento project.

License

MIT

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固