Introduction
Modules are extensions to the main engine, allowing you to expand its functionality. Each module is unique in its essence and has its own requirements, but in Flute, there is a uniform structure that every module should adhere to. Some examples of module.
Module Structure
All plugins are located in the app/Modules/
folder. Example of a plugin structure:
Monitoring - This is just an example of a module key. Each module may slightly differ in structure, as well as the key.
Modules
├── Monitoring
│ ├── i18n
│ │ ├── en
│ │ │ └── monitoring.php
│ │ └── ru
│ │ └── monitoring.php
│ ├── Resources
│ │ ├── assets
│ │ │ ├── js
│ │ │ │ └── monitoring.js
│ │ │ └── scss
│ │ │ └── monitoring.scss
│ │ └── Views
│ │ └── servers.blade.php
│ ├── ServiceProviders
│ │ ├── Extensions
│ │ │ └── WidgetExtension.php
│ │ └── MonitoringServiceProvider.php
│ ├── Services
│ │ └── ServersMonitorService.php
│ ├── Widgets
│ │ └── ServersWidget.php
│ ├── Installer.php
│ └── module.json
Installer File
The Installer.php file is optional, but its presence in a module means that some actions are required for installation or deinstallation (performing migrations, removing widgets from the system, etc.)
Each Installer
must necessarily extend the AbstractModuleInstaller
class.
Every install
, uninstall
method must return bool
and these methods are mandatory in the class.
Example of a complete installer implementation:
<?php
namespace Flute\Modules\Monitoring;
use Flute\Core\Support\AbstractModuleInstaller;
use Flute\Modules\Monitoring\Widgets\ServersWidget;
class Installer extends AbstractModuleInstaller
{
public function install(\Flute\Core\Modules\ModuleInformation &$module) : bool
{
// Here, for example, migrations can be executed
$this->importMigrations();
return true;
}
public function uninstall(\Flute\Core\Modules\ModuleInformation &$module) : bool
{
// Here, for example, you can unregister a widget
widgets()->unregister(ServersWidget::class);
return true;
}
}
Configuration File
Each module must have a configuration file. Typically, this is a JSON file with arbitrary parameters applicable to a particular module.
Configuration example:
{
"name": "Monitoring module",
"version": "1.0.0",
"description": "Provides a game info status of players on each added server",
"authors": ["Flames"],
"providers": [
"Flute\\Modules\\Monitoring\\ServiceProviders\\MonitoringServiceProvider"
],
"dependencies": {
"php": "7.4",
"flute": "0.3.1-dev",
"extensions": ["xml", "zip"],
"modules": {
"Shop": "0.2.1",
},
"theme": {
"standard": "1.0.0"
}
}
}
Explanation of Configuration File Parameters
A detailed explanation of each parameter in the JSON configuration file example for a module:
-
"name"
: This is the name of the module. In this case,"Monitoring module"
indicates that the module is intended for monitoring, possibly servers or gaming processes. -
"version"
: The version of the module is stated here."1.0.0"
follows the SemVer versioning semantics, where changes in version numbers indicate different levels of changes in the module. -
"description"
: A brief description of the module. In this case,"Provides a game info status of players on each added server"
suggests that the module provides information about the status of players on added servers. -
"authors"
: A list of authors or developers of the module. This can be a single person or a team. Here, it is listed as["Flames"]
. -
"providers"
: A list of service provider classes used by the module. These classes typically provide specific functionalities or services within the context of the module. Example:["Flute\\Modules\\Monitoring\\ServiceProviders\\MonitoringServiceProvider"]
. -
"dependencies"
: Describes the module dependencies. This is an important part as it indicates the required software or modules for the correct operation of the current module:"php"
: Minimum required PHP version."flute"
: Minimum Flute version required for installing the module."extensions"
: List of required PHP extensions, for example,["xml", "zip"]
."modules"
: List of other modules that the current module depends on, along with their versions. For example, module"Shop"
version"0.2.1"
."theme"
: Indicates a dependency on a specific theme, if available, along with its version.