I'm writing a composer package that needs to execute a list of safety checks when Composer autoload.php is called and before accessing its classes and methods
I have this composer.json file:
{
"name": "def-studio/logger",
"description": "Def Studio logger system",
"type": "library",
"require": {
"php": ">=5.3.0"
},
"license": "MIT",
"autoload": {
"psr-4": {
"DefStudio\\Logger\\": "src/"
}
}
}
After ./vendor/autoload.php
is called and the main class DefStudio\Logger\Logger.php
is loaded, I need to execute this method: Logger::perform_checks()
everytime the class is loaded.
my code is, actually:
include_once './vendor/autoload.php';
use DefStudio\Logger\Logger;
Logger::perform_checks();
try{
//random messy code here
}catch(Exception $ex){
Logger::error("error!", $ex);
}
I need my package to call Logger::perform_checks()
everytime autoload.php
is called and I don't want to rely on the user to remember to call it.. I wish it to be automagically called when autoload.php
is invoked
Is there any way to automatically execute a php script when autoload.php
is called?