承接 ctasca/mage-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

ctasca/mage-bundle

Composer 安装命令:

composer require ctasca/mage-bundle

包简介

Easily create Magento/Adobe Commerce PHP/XML/JS files from a set of templates

README 文档

README

License PHP Version Require

Easily create Magento2/AdobeCommerce PHP/XML/JS files from a set of templates via the command-line.

Allows you to define your own templates as well as the data provided at files' creation time.

#1 Installation

composer require --dev ctasca/mage-bundle

#2 Copy template files to Magento root dev/ directory

cd <magento_root>/vendor/ctasca/mage-bundle && composer run-script post-install-cmd

After executing the above command, check that dev/ directory of your Magento installation contains a mage-bundle/ directory.

Enable the module

bin/magento module:enable Ctasca_MageBundle

Run setup:upgrade command

bin/magento setup:upgrade

Run setup:di:compile command (optional)

If Magento is running in production mode you will need to also run:

bin/magento setup:di:compile

Available commands

bin/magento magebundle:module:create

Shortcut

bin/magento m:modu:c

Creates a skeleton Magento module in app/code directory, generating the required registration.php and etc/module.xml files

bin/magento magebundle:controller:create

Shortcut

bin/magento m:cont:c

Creates a Controller namespace and Action class in specified module. Developer is prompted to choose a router (either standard or admin), and an Action template from the ones available in mage-bundle/http-controller or mage-bundle/adminhtml-http-controller directories.

bin/magento magebundle:etc:xml:create

Shortcut

bin/magento m:e:x:c

Creates an XML file in Company/Module/etc directory. Templates can be chosen after specifying the area where the template applies to.

bin/magento magebundle:model:set:create

Shortcut

bin/magento m:m:s:c

Creates a Model, Resource Model and Collection classes in specified Company/Module.

bin/magento magebundle:repository:create

Shortcut

bin/magento m:r:c

Creates all the required class for a Repository in specified Company/Module.

IMPORTANT: In order to create a repository a model implementing an interface must exist.

If you need a Repository when creating a model-set with the command magebundle:model:set:create you can choose a template that will also create a Model implementing an interface

This command creates the following:

  • An API Interface for the repository
  • An API Data Interface for the model (if it doesn't exist)
  • An API Data Search Result Interface
  • The repository Model implementing the repository Interface

Do not forget to add the preferences to your di.xml for the repository classes once created. For example:

<config>
    <preference for="Company\Module\Api\Data\$MODEL_NAMEInterface" type="Company\Module\Model\$MODEL_NAME" />
    <preference for="Company\Module\Api\$MODEL_NAMERepositoryInterface" type="Company\Module\Model\$MODEL_NAMERepository" />
    <preference for="Company\Module\Api\Data\$MODEL_NAMESearchResultInterface" type="Company\Module\Model\$MODEL_NAMESearchResult" />
</config>
bin/magento magebundle:model:create

Shortcut

bin/magento m:mode:c

Creates a Model class in specified Company/Module. There is also the template to create an interface instead of a class.

bin/magento magebundle:block:create

Shortcut

bin/magento m:b:c

Creates a template Block class in specified Company/Module.

bin/magento magebundle:helper:create

Shortcut

bin/magento m:h:c

Creates a Helper class in specified Company/Module.

bin/magento magebundle:customer-data:create

Shortcut

bin/magento m:cu:c

Creates a CustomerData class in specified Company/Module.

bin/magento magebundle:view-model:create

Shortcut

bin/magento m:v:c

Creates a View Model class in specified Company/Module.

bin/magento magebundle:observer:create

Shortcut

bin/magento m:o:c

Creates an Observer class in specified Company/Module.

bin/magento magebundle:plugin:create

Shortcut

bin/magento m:p:c

Creates a Plugin class in specified Company/Module.

bin/magento magebundle:cron:create

Shortcut

bin/magento m:cr:c

Creates a Cron class in specified Company/Module.

bin/magento magebundle:console-command:create

Shortcut

bin/magento m:cons:c

Creates a Console Command class in specified Company/Module.

bin/magento magebundle:data-patch:create

Shortcut

bin/magento m:d:c

Creates a Setup Data Patch class in specified Company/Module.

bin/magento magebundle:schema-patch:create

Shortcut

bin/magento m:s:c

Creates a Setup Schema Patch class in specified Company/Module.

bin/magento magebundle:api-interface:create

Shortcut

bin/magento m:a:c

Creates an API interface in specified Company/Module. Templates can be chosen after specifying the area where the template applies to.

For functional API interfaces, the generated file will be created in the Company/Module/Api directory

For data API interfaces, the generated file will be created in the Company/Module/Api/Data directory

bin/magento magebundle:jquery-widget:create

Shortcut

bin/magento m:j:c

Creates a JQuery widget file in specified Company/Module. JS file will be created in the specified module's view/$AREA/web/js directory.

bin/magento magebundle:ui-component:create

Shortcut

bin/magento m:u:c

Creates an Ui Component JS file in specified Company/Module. JS file will be created in the specified module's view/$AREA/web/js directory.

bin/magento magebundle:logger:create

Shortcut

bin/magento m:l:c

Creates a Logger Handler and Logger classes files in specified Company/Module.

Log filename can be specified when executing this command.

bin/magento magebundle:js:mixin:create

Shortcut

bin/magento m:j:m:c

Creates a JS mixin file in specified Company/Module. JS file will be created in the specified module's view/$AREA/web/js directory.

bin/magento magebundle:exception:create

Shortcut

bin/magento m:e:c

Creates an Exception class in specified Company/Module.

Utilities commands

bin/magento magebundle:util:encryptor

Shortcut

bin/magento m:u:e

Encrypts/Decrypts a string using Magento crypt key

Setting custom working directory

By default, MageBundle creates files in the app/code directory and in the specified module's namespace

It is possible, to change this behaviour by creating a json file named pwd.json in the $MAGENTO-ROOT/dev/mage-bundle directory and specifying the directory (relative to magento root) where files will be created when executing MageBundle commands.

This can be useful, for example, when developing a module which is not located in app/code directory

Important:

The directory specified in pwd.json must end with a forward-slash

pwd.json example:

{
  "pwd" : "packages/my-package/"
}

About template files:

Template files are written in PHP version 8.1.

For example the http-get-action-json-result.tpl.php contains the following

{{php}}
declare(strict_types=1);

namespace {{namespace}};

use Magento\Framework\App\Action\HttpGetActionInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Controller\Result\Json;

class {{class_name}} implements HttpGetActionInterface
{
    /**
     * @param RequestInterface $request
     * @param JsonFactory $jsonFactory
     */
    public function __construct(
        private readonly RequestInterface $request,
        private readonly JsonFactory $jsonFactory
    ){}

    /**
     * @return Json
     */
    public function execute(): Json
    {
        $jsonResponse = $this->jsonFactory->create();
        return $jsonResponse->setData([]);
    }
}

To set your own templates just place them in the MAGENTO_ROOT/dev/mage-bundle/$TEMPLATES_DIRECTORY/ directory and choose the template when executing the magebundle create commands.

Note: When executing the magebundle:etc:xml:create command, files are generated with the same name as the template file.
To create your own templates, use the filename for the xml file to be generated appending __$STRING to the template filename.
For example to define your own global acl.xml template, create, for example, the template file naming like so: acl__custom.tpl.xml. Then simply place it in the dev/mage-bundle/etc/global directory and select it when executing the create command.

IMPORTANT: If a filename already exists in a module's directory, the create command will not be executed and an error is output to the console.
This is to prevent overwriting an existing file.

For a list of the templates defined within the module go to...

The repository wiki page

Templates Data Provider

It is possible to define your own templates as well as the data that are passed when these are generated.

In order to do so, simply create a JSON file in the MAGENTO_ROOT/dev/mage-bundle/custom-data/#path-to-template# directory, naming the file exactly as the template file that is being generated and defining a JSON Object with setter methods as keys and their corresponding values.

As an example, for XML files generated in Company/Module/etc directories, custom data should be stored in MAGENTO_ROOT/dev/mage-bundle/custom-data/etc/#area#/#template_name#.tpl.json

Example

{
  "setTestNamespace" : "\\Ctasca\\MageBundle\\Test",
  "setCustomDataArray" : ["First Value", "Second Value"]
}

After creating this JSON file, it will be possible to use the placeholder {{test_namespace}} in a template file.

As setCustomDataArray provides an array, this will be imploded with PHP_EOL separator. To use it in your template files you would use the placeholder: {{custom_data_array}}

ctasca/mage-bundle 适用场景与选型建议

ctasca/mage-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 390 次下载、GitHub Stars 达 25, 最近一次更新时间为 2022 年 09 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 ctasca/mage-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ctasca/mage-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 ctasca/mage-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 25
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-20