ewth / mageinterfacegen

此软件包最新版本(dev-master)没有可用的许可证信息。

Magento 2 的接口和模型生成器

dev-master 2018-07-13 04:12 UTC

This package is not auto-updated.

Last update: 2024-09-26 20:08:20 UTC


README

Magento 2 的接口和模型生成器

该工具接受如以下示例的基本接口结构,并生成可用于 Magento 2 的有用接口和域模型。请注意,它假设所有内容都是字符串,因此您需要审查生成的代码以确保无误,但它使得生成新的接口和模型这种重复性工作变得容易得多。它不强制执行任何命名约定,可以与 camelCasesnake_case 一起使用。

请注意,输出将被打印到控制台,实际上它不会修改任何文件。

用法

php mageinterfacegen.php path/to/interface.php

path/to/interface.php 中期望的内容(extends ... 是可选的,它只查看 interface ... 部分)

namespace My\App\Namespace;

interface NewInterface extends \Magento\Framework\Api\ExtensibleDataInterface
{
    const KEY_FIRST_ITEM = 'first_item';
    const KEY_SECOND_ITEM = 'secondItem';
    const THIRD_ITEM = 'third_item';
}

这将导致

Processing NewInterface


-------------- begin interface --------------

    /**
     * @param string $firstItem
     * @return $this
     */
    public function setFirstItem($firstItem);

    /**
     * @return string
     */
    public function getFirstItem();

    /**
     * @param string $secondItem
     * @return $this
     */
    public function setSecondItem($secondItem);

    /**
     * @return string
     */
    public function getSecondItem();

    /**
     * @param string $thirdItem
     * @return $this
     */
    public function setThirdItem($thirdItem);

    /**
     * @return string
     */
    public function getThirdItem();



-------------- end interface --------------

**** When you've copied the above, press enter to generate the domain model




-------------- begin model --------------

    /**
     * @param string $firstItem
     * @return $this
     */
    public function setFirstItem($firstItem)
    {
        return $this->setData(self::KEY_FIRST_ITEM, $firstItem);
    }

    /**
     * @return string
     */
    public function getFirstItem()
    {
        return $this->getData(self::KEY_FIRST_ITEM);
    }

    /**
     * @param string $secondItem
     * @return $this
     */
    public function setSecondItem($secondItem)
    {
        return $this->setData(self::KEY_SECOND_ITEM, $secondItem);
    }

    /**
     * @return string
     */
    public function getSecondItem()
    {
        return $this->getData(self::KEY_SECOND_ITEM);
    }

    /**
     * @param string $thirdItem
     * @return $this
     */
    public function setThirdItem($thirdItem)
    {
        return $this->setData(self::THIRD_ITEM, $thirdItem);
    }

    /**
     * @return string
     */
    public function getThirdItem()
    {
        return $this->getData(self::THIRD_ITEM);
    }



-------------- end model --------------