在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):creolab/laravel-modules开源软件地址(OpenSource Url):https://github.com/creolab/laravel-modules开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):AbandonedThis package is no longer maintained. I encourage you to use composer packages for your modules to get the most flexibility out of it. Modules in Laravel 4Application specific modules in Laravel 4 can be enabled by adding the following to your "composer.json" file:
And by adding a new provider to your providers list in "app/config/app.php":
Also you need to add your modules directory to the composer autoloader:
This also means you need to run "composer dump-autoload" every time you add a new class to your module. By default you can add a "modules" directory in your "app" directory. So as an example this is a structure for one of my projects:
Note that every module has a "module.json" file, in which you can enable/disable the module. I plan on adding more meta data to these module definitions, but I need feedback as to what to put in there. The first thing will probably be some kind of a bootstrap class. If you want to have your modules in more that 1 directories you need to change the packages config file as following:
And don't forget to add those directories to your autoload list inside the composer.json file. One of the available option is the order in which the modules are loaded. This can be done simply by adding the following to your module.json file:
The order defaults to 0, so keep that in mind if you don't define it. For now take a look at the example implementation, and please provide feedback ;) https://github.com/bstrahija/laravel-modules-example CommandsThere are 2 commands available through this package:
Which simply diplays all current modules depending on the mode set in the configuration. And:
Which is only required if you have your modules setup in the "manifest" mode (see below). This command scans the modules exactly like in the "auto" mode, but caches the results into a manifest file. OptimizationBy default the package scans the "modules" directory for "module.json" files. This is not the best solution way to discover modules, and I do plan to implement some kind of a caching to the Finder class. To optimize the modules Finder even more you can publish the package configuration, and add the modules and definitions directly inside the configuration file by running:
And the editing the file "app/config/packages/creolab/laravel-modules/config.php". You just need to change the "mode" parameter from "auto" to "manual", and list your modules under the "modules" key. An example of that is already provided inside the configuration. Note for Manual mode with multiple paths : Laravel-Modules could not determine witch path to use. So please specify the folder containing the module you want to load. Like this example :
You can also add multiple module paths as an array, but do note that if a module has the same name, there will be problems. Including filesYou can also specify which files in the module will be automatically included. Simply add a list of files inside your module.json config:
There are some defaults set on which files will be included if they exist. Take a look at the latest config file, and republish the configuration if needed. By default these files will be included:
So you have the choice to either add your custom files to the global configuration, which will look for these files in every module, or you can set it up on a per module basis by adding it to the module.json file. Service providersA new addition is registering service providers for each module. Just add a line to your module.json file that looks something like this:
These service provider classes work exactly like any other service provider added to your app/config/app.php configuration, so setup these classes by extending the \Illuminate\Support\ServiceProvider class and adding the appropriate methods. You can also register multiple providers for every module by simply providing an array:
Keep in mind that you may have to run composer dump-autoload so you want get error on missing classes. Modules ManifestAnother possible mode is "manifest" which basically writes a JSON manifest file in your Laravel storage directory that contains all the modules definitions. This is only done the first time and to update the manifest file you need to either delete it, or rescan the modules via the following command:
AssetsJust recently the ability to publish public assets for each module has been added. Just run:
And all modules that contain an "assets" directory will be published to the Laravel public directory. You can also publish assets for individual modules by providing the module name:
MigrationsEvery module can have it's own migrations, and they need to be in the module/migrations directory. So for example if you want to create a migration that creates a user table for the auth module:
And to run all module migrations do this:
Or to run migrations for a specific module:
You can also seed the database form the module if your module.json contains a seeder setting. Just pass the --seed option to the command:
SeedingThe modules can also have seeders. Just create the class like you would create a normal seeder, place it somewhere inside your module, and be sure to run composer dump-autoload. Then add the following to your module.json file:
This setting should contain the namespace path to your seeder class. Now simply run:
To seed all your modules. Or you can do it for a specific module:
CommandsYou can add module specific commands. This is a sample artisan command file creation :
Then in the module.json add (you can also add an array if you have multiple commands) :
After a dump-autoload you can now execute modules.mymodule:mycommand from command line :
AliasesIf you declare Facades into your modules you will like to create Aliases for your module, you can simply reference your alias in the
LicenseThi package is open-sourced software licensed under the MIT license. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论