rayzor65/module-tutorial

该包已被 废弃,不再维护。未建议替代包。

创建可重用模块的教程

1.0.4 2015-12-03 01:40 UTC

This package is not auto-updated.

Last update: 2020-09-22 23:08:42 UTC


README

这是一个如何使用composer拉取模块的示例和迷你教程。在创建模块之前,了解自动加载和命名空间是一个好主意。

编写模块

  • 将此项目复制到一个新目录

  • 编辑 composer.json 并添加您的模块详细信息

  • 自动加载字段表示所有类都将包含在指定的命名空间下。

  • 标记您的模块

    git tag 1.0.1

    git push origin --tags

包含模块

更新您项目的composer文件。

指定仓库位置

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/rayzor65/module-tutorial" // Change this to your module
    }
]

然后添加到 require

    "require": {
        "rayzor65/module-tutorial": "1.0.1" // Change this to your module
    }

现在您可以在项目中这样使用类

use ModuleTutorial\MyModule\MyService;

class ProjectClass
{
    public function ProjectClassFunction()
    {
        // You can now use your autoloaded classes from the module
        $service = new MyService();
        $service->doSomething();
    }
}

最终步骤

  • 请确保您已经添加了自己的README说明