modulatr / loader
此包最新版本(dev-develop)没有可用的许可信息。
Modulatr
dev-develop
2018-04-17 22:25 UTC
Requires
- php: ^7.2
Requires (Dev)
- phpunit/phpunit: ^7.0
This package is not auto-updated.
Last update: 2024-09-19 13:15:56 UTC
README
用于在PHP项目中创建和加载模块的包。
通过Composer安装
composer require modulatr/loader
使用方法
Modulatr 与框架无关,尽管有计划根据需求实现流行框架的服务提供者。
首先,创建一个新的模块。
<?php namespace App\Modules; use Modulatr\Loader\Module; class Example extends Module { public function getId(): string { return 'example'; } public function getServiceProviders(): array { return []; } }
接下来,将模块加载到ModuleLoader类中,URI部分作为第一个参数,配置数组作为第二个参数
<?php use Modulatr\Loader\ModuleLoader; use App\Modules\Example; $loader = new ModuleLoader(['example', 'index'], [ 'modules' => [ Example::class, ], ]);
在上面的例子中,传递给模块的URI将是 /example/index
如果你使用Laravel等框架,你可能想要从路由名称(可能是 example.index)创建数组,以便不直接将模块绑定到URI。
现在,如果你在loader上调用 getCurrentModule(),你将返回你的模块类,因为它的ID是 example,而URI数组包含字符串 example。