Created
August 3, 2017 22:51
-
-
Save clowestab/b300cd39bccf4408b72098182e7a3f97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function callOldVersion($argumentsList) { | |
//If they have requested a NON current API version | |
if (APIHelpers::$API_VERSION != APIHelpers::CURRENT_API_VERSION) { | |
//get the name of the method that they have called | |
$actionName = $this->dispatcher->getActionName(); | |
//build the name of the legacy action method | |
$legacyActionName = $actionName . APIHelpers::$API_VERSION; | |
//if there is a legacy version.. | |
if (method_exists($this->oldApiService, $legacyActionName)) { | |
//iterate through previous versions, and convert the arguments | |
for ($toVersion = APIHelpers::$API_VERSION; $toVersion < APIHelpers::CURRENT_API_VERSION; $toVersion++) { | |
$fromVersion = $toVersion + 1; | |
//echo "Convert from " . $fromVersion . " to " . $toVersion; | |
//build the convertor method name | |
$convertorName = $actionName . $fromVersion . "to" . $toVersion; | |
//if a convertor with that name exists | |
if (method_exists("ArgumentConvertors", $convertorName)) { | |
//convert the arguments | |
$argumentsList = call_user_func_array(array("ArgumentConvertors", $convertorName), $argumentsList); | |
} | |
//otherwise the legacy version must take the same parameters | |
} | |
$response = call_user_func_array(array($this->oldApiService, $legacyActionName), $argumentsList); | |
return $response; | |
} | |
//indicate that there was no legacy handler so we should just call the normal method | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment