Bug: Adding version to className in Restler->addAPIClass()
Hey Arul,
check out line 1309 of Restler.php in v3 branch.
//versioned api
if (false !== ($index = strrpos($className, '\\'))) {
$name = substr($className, 0, $index)
. '\\v{$version}' . substr($className, $index);
} else if (false !== ($index = strrpos($className, '_'))) {
$name = substr($className, 0, $index)
. '_v{$version}' . substr($className, $index);
} else {
$name = 'v{$version}\\' . $className;
}
If I have a class named Org\SoilWater\v2\SoilWater then the first condition of the ifelse will be triggered, but name will end up as Org\SoilWater\v2\v{$version}\SoilWater, when it should end up as Org\SoilWater\v{$version\SoilWater.
For some reason when using v1 the APIs still work, but it breaks with v2 onwards. Basically the v2 APIs are not functional and don't appear in resources.json.
Cheers, Sam.
Hey Sam,
I think you got confused on how we add the api class. Let me explain how that works
Your index.php should be like
$r = new Restler();
$r->addAPIClass('Org\SoilWater\SoilWater'); //note that there is no version in the class name
$r->setAPIVersion(2); // sets the maximum version available
$r->handle();
When v2 of the api is called Restler will automatically load Org\SoilWater\v2\SoilWater class
Ah. It's so obvious now! Thanks Arul.