Safeguard your PHP code by wrapping function declarations in if (!function_exists())
blocks.
Ensures that functions are only declared if they do not already exist, preventing redeclaration conflicts.
You can also star (🌟) this repo to find it easier later.
You can install the package via composer:
composer require ghostwriter/handrail
Before running Handrail:
<?php
function exampleFunction() {
// some code
}
function anotherFunction() {
// more code
}
After running Handrail:
<?php
if (!function_exists('exampleFunction')) {
function exampleFunction() {
// some code
}
}
if (!function_exists('anotherFunction')) {
function anotherFunction() {
// more code
}
}
To configure the paths or files to scan, create a composer extra
configuration in your composer.json
:
{
"extra": {
"ghostwriter/handrail": {
"disable": false,
"packages": [
"vendor/package"
],
"files": [
"vendor/amphp/amp/src/functions.php",
"relative/path/to/file.php"
]
}
}
}
disable
: (default:false
) A boolean flag to enable or disable Handrail.files
: (default:[]
) An array of files to scan for function declarations.
After installing and configuring Handrail, we will automatically hook into Composer’s lifecycle events (post-install-cmd
and post-update-cmd
) after Composer installs or updates packages.
composer install
composer update
You can also run Handrail manually using the following Composer command:
composer handrail
Handrail provides an API for programmatic execution within PHP scripts:
use Ghostwriter\Handrail\Handrail;
Handrail::new()->guard($phpFile);
- Yevhen Sidelnyk for the inspiration.
Please see CHANGELOG.md for more information on what has changed recently.
Please see LICENSE for more information on the license that applies to this project.
Please see SECURITY.md for more information on security disclosure process.