Hi there and welcome to my first official problem! I'm trying to override a function, but only certain parts. The function i want to override, is different in several versions of the open source CMS system. The specific parts which i need to change in order for this to work, are the same in all of those versions.
The override has to work with all of those different versions of the CMS system.
I can't use PECL (apd) package or any other external PHP package for this. And as far i know and could find in the PHP manual, there is no function for this.
So, for example:
We have the different CMS system versions: 1, 2 and 3.
And we would have a original function like this one (THIS IS JUST AN EXAMPLE AND NOT THE ACTUAL FUNCTION I NEED CHANGED), which can only be used for version 3. Certain parts are the same in all versions, and some parts are different:
public function createAccessToken($body = false)
{
if (!$body) { //this is different
$body = 'grant_type=client_credentials'; //this is different
}
$this->action = 'POST'; //this is different
$this->endpoint = 'v1/oauth2/token'; //this is different
$response = $this->makeCall($body, "application/json", true); //this is different
if (!isset($response->access_token)) { //this is THE SAME
return false; //this is THE SAME
}
$this->token = $response->access_token; //this is different
return true; //this is different
}
And this is what i would like to change for all of those versions:
public function createAccessToken($body = false)
{
if (!$body) {
$body = 'grant_type=client_credentials';
}
$this->action = 'POST';
$this->endpoint = 'v1/oauth2/token';
$response = $this->makeCall($body, "application/json", true);
if (isset($response->access_token)) { //IT'S CHANGED! THE -> ! IS GONE
return false;
}
$this->token = $response->access_token;
return true;
}
But the function above (which has changed), will only work with version 3 of the CMS system.
Therefore, is there any way i can only override the specific part i need to change and "get" the code which doesn't have to change some other way so the function would still be executed? So again:
public function createAccessToken($body = false)
{
//some way to get the code above the part i need to change, untill i get to the part which needs to be changed. So the override "takes over" from here.
if (isset($response->access_token)) { //IT'S CHANGED! THE -> ! IS GONE
return false;
}
//some way to get the rest of the code and have the function continue agian
}
Hope you can help me out on this.