If I am designing a framework with PHP and in my framework there is a A class and a AManager class.
What can I do to let all the A object methods or class methods can only be called within AManager methods?
Such as:
class A {
public function __construct() {
if( the calling environment is not within AManager Object Method )
throw new Exception("error")
else
init..
}
}
I have tried to use __callStatic
and debug_backtrace
of A like:
private static function create($a,$b) {
echo "in create";
new Logger($a,$b);
}
public function __callStatic($name, $arguments) {
$array = debug_backtrace(); // check environment
var_dump($array);
return;
call_user_func_array([Logger::class,$name],$arguments);
}
but the backtrace only shows __callStatic
.
So is there any method to deal my requirement?