-
Notifications
You must be signed in to change notification settings - Fork 0
Extension Development
This document provides essential guidelines for developing third-party extensions for WebifyCMS.
WebifyCMS core (ext-base) defines the following global helper functions.
Third-party extensions must NOT declare functions with these names to avoid fatal conflicts.
| Function | Description |
|---|---|
app() |
Returns the web application instance |
console_app() |
Returns the console application instance |
is_dev() |
Checks if running in development environment |
is_debug() |
Checks if debug mode is enabled |
dependency() |
Returns the dependency service instance |
| Function | Description |
|---|---|
load_env_variables(string $path, string $fileName = '.env') |
Loads environment variables from .env file |
get_env_variable(string $name, mixed $default = null) |
Gets an environment variable value |
| Function | Description |
|---|---|
log_message(string $type, array|string $message, string $category = 'application') |
Logs messages (supports: info, warning, debug, trace) |
| Function | Description |
|---|---|
set_alias(string $alias, string $path) |
Sets a path alias |
get_alias(string $alias) |
Resolves a path from an alias |
| Function | Description |
|---|---|
url(array|string $url, bool|string $scheme = false) |
Creates a URL based on route parameters |
request_url() |
Returns the current requested URL |
home_url(bool|string $scheme = false) |
Returns the home URL |
remember_url(array|string $url, ?string $name = null) |
Remembers a URL for later retrieval |
previous_url(?string $name = null) |
Returns the previously remembered URL |
| Function | Description |
|---|---|
administration() |
Returns the administration service instance |
administration_path() |
Returns the administration path |
administration_url(array|string|null $url = null, bool|string $scheme = false) |
Creates an administration URL |
in_administration() |
Checks if currently in administration area |
| Function | Description |
|---|---|
view() |
Returns the framework's view component |
| Function | Description |
|---|---|
translate(string $category, string $message, array $params = [], ?string $language = null) |
Translates a string |
| Constant | Value | Description |
|---|---|---|
ENV_PRODUCTION |
'prod' |
Production environment identifier |
ENV_DEVELOPMENT |
'dev' |
Development environment identifier |
Prefix your helper functions with your extension's unique identifier:
// ❌ BAD - May conflict with core or other extensions
function log_message() { }
function url() { }
// ✅ GOOD - Unique to your extension
function my_extension_log_special() { }
function my_extension_custom_url() { }If you want to provide fallback implementations or avoid conflicts:
if (!function_exists('my_extension_helper')) {
function my_extension_helper() {
// Your implementation
}
}For extension-specific functionality, prefer namespaced classes:
namespace MyVendor\MyExtension\Helper;
class UrlHelper {
public static function generateCustomUrl(): string {
// Your implementation
}
}
// Usage:
use MyVendor\MyExtension\Helper\UrlHelper;
UrlHelper::generateCustomUrl();Instead of redefining functionality, use WebifyCMS core helper functions:
// ✅ Use core functions
function my_extension_admin_dashboard_url(): string {
return administration_url('my-extension/dashboard');
}
function my_extension_log_error(string $message): void {
log_message('error', "[MyExtension] {$message}", 'my-extension');
}Always document your global helper functions in your extension's README:
## Helper Functions
This extension provides the following global helper functions:
- `my_extension_do_something()` - Does something useful
- `my_extension_format_output()` - Formats output in a specific wayIf your extension needs to define helper functions, register them in your composer.json:
{
"name": "vendor/my-extension",
"autoload": {
"psr-4": {
"MyVendor\\MyExtension\\": "src/"
},
"files": [
"src/helpers.php"
]
}
}Important: Composer loads files in the order they're defined across all packages. WebifyCMS core helpers will load first, so never redefine core function names.
If you encounter this error:
Fatal error: Cannot redeclare log_message() in /path/to/extension/helpers.php
Solution: Your extension is trying to define a function that already exists in the core. Choose a different, unique function name.
If your helper function isn't available:
- Ensure
composer.jsonincludes your helpers file in thefilesautoload section - Run
composer dump-autoloadto regenerate the autoloader - Clear any application caches
- Check the WebifyCMS Documentation
- Review the core helper functions in
vendor/webifycms/ext-base/src/helpers.php - Ask questions in the WebifyCMS Community
Last Updated: 2025-12-06