PHP Luminova: Autoload Modules in CLI Scope
Bootstrap Luminova from a standalone PHP executable.
In this guide, we will discuss how to autoload the Luminova framework when creating a standalone PHP executable. When creating a custom PHP executable in Luminova, it is recommended to place your script within the /bin/ directory. However, you can also create it in your project root directory at the same level as the novakit script.
Implementation
When creating your script, it’s important to ensure that the Luminova framework is accessible within your executable. This allows you to leverage global functions, load necessary modules, and include classes required for your script’s functionality.
Example
#!/usr/bin/env php
<?php
// /bin/script
use Luminova\Boot;
/**
* Autoload Luminova framework
*/
require dirname(__DIR__) . '/system/Boot.php';
/**
* Sets up the CLI (Command Line Interface) environment.
* Define CLI-related constants, finishes bootstrapping.
*/
Boot::cli();
chdir(APP_ROOT);
// Your script implementationFor a script in the project root, load the boot file with __DIR__ . '/system/Boot.php'. The working-directory change makes relative paths resolve from the project root.
See Also
- Command Executor Helpers - Learn more about CLI command execution and handling.
- Base Command Classes - Learn how to extend and implement a CLI command controller class.
- Command Attributes - Learn about PHP attribute routing and its usage.