takemo101/simple-module

Laravel Simple 模块

v0.2.2 2022-03-19 06:57 UTC

This package is auto-updated.

Last update: 2024-09-19 12:07:47 UTC


README

Testing PHPStan Validate Composer

一个非常简单的Laravel模块化系统。
享受吧!

安装

执行以下composer命令。

composer require takemo101/simple-module

发布配置

使用以下artisan命令发布配置。

php artisan vendor:publish --tag="simple-module"

关于 composer.json

在composer.json所在的目录下创建一个'module'目录。
然后设置你添加的目录路径到composer.json中。

    "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Module\\": "module/", <- added
            ...
        }
    },
    ...

使用方法

你可以执行以下命令。

1. 创建模块

在模块目录下创建一个模块文件

php artisan simple-module:create ModuleName

or

php artisan simple-module:create ModuleName --namespace=OtherModuleNamespace

2. module install

执行创建的模块文件中的Module.php的安装方法。

php artisan simple-module:install

or

php artisan simple-module:install --module=ModuleName

3. module uninstall

执行创建的模块文件中的Module.php的卸载方法。

php artisan simple-module:uninstall

or

php artisan simple-module:uninstall --module=ModuleName

4. module update

仅更新创建的模块文件的依赖包。

php artisan simple-module:update

or

php artisan simple-module:update --module=ModuleName

如何设置模块文件

以下是一个Module.php的设置示例。

<?php

namespace Other\Sync;

use Takemo101\SimpleModule\Support\ {
    InstallerInterface,
    ServiceProvider,
};

/**
 * Module files are Laravel's service provider, so you can use them in the same way.
 */
class Module extends ServiceProvider implements InstallerInterface
{
    public function register()
    {
        //
    }

    public function boot()
    {
        //
    }

    /**
     * module install process
     *
     * @return void
     */
    public function install()
    {
        // Write the process when installing the module.
    }

    /**
     * module uninstall process
     *
     * @return void
     */
    public function uninstall()
    {
        // Write the process when uninstalling the module.
    }

    /**
     * install packages
     *
     * Set the package string to the key of the associative array.
     * For the value of the associative array, set whether to uninstall or not with boolean type.
     *
     * @return boolean[]
     */
    public function packages(): array
    {
        return [
            'bensampo/laravel-enum' => true, // It is deleted at the same time as uninstalling
            'jeroennoten/laravel-adminlte' => false, // Not deleted even if uninstalled
        ];
    }
}