Managing Requirements
Requirements are hard prerequisites that must be satisfied for a module to be enabled. Unlike Supports, which gracefully adapt the module’s behavior, Requirements will block the module from starting entirely if they are not met.
Why use Requirements?
Section titled “Why use Requirements?”- Prevention: Stop the module from running on incompatible environments.
- Stability: Ensure critical system components are loaded before execution.
- Complex Validation: Use logical operators to define sophisticated environmental needs.
How to define Requirements?
Section titled “How to define Requirements?”-
Import Required Classes
Section titled “Import Required Classes”Ensure your module imports the necessary classes from the framework:
-
Add Requirements to your Module
Section titled “Add Requirements to your Module”Use the
requirements()method in yourmodule()definition. You can chain multiple conditions together.use Illuminate\Support\ServiceProvider;use Epsicube\Support\Contracts\IsModule;use Epsicube\Support\Modules\{Module, Requirements, Condition};class ImageProcessorModule extends ServiceProvider implements IsModule{public function module(): Module{return Module::make('image-processor', '1.1.0')->requirements(fn (Requirements $requirements) => $requirements->add(// Base system prerequisiteCondition::phpVersion('>= 8.2'),Condition::phpExtensions('fileinfo'), // Mandatory for MIME detection// The module needs at least one valid engine to functionCondition::any(Condition::phpExtensions('gd'),Condition::phpExtensions('imagick'),Condition::all(Condition::phpExtensions('vips'),Condition::phpVersion('>= 8.3') // VIPS requires PHP 8.3+ here)),// Conditional Requirement (Condition::when)// If 'imagick' is used, we strictly require PHP 8.3...Condition::when(Condition::phpExtensions('imagick'), [Condition::phpVersion('>= 8.3'),])));}} -
Learn how to define Conditions
Section titled “Learn how to define Conditions”The
Conditionhelper provides several static methods to check the environment.These are the same conditions used in the Support system.
See the Available Conditions.