public function ResourceManager::getResourceLastVersion in RESTful 7.2
Return the last version for a given resource.
Parameters
string $resource_name: The name of the resource.
int $major_version: Get the last version for this major version. If NULL the last major version for the resource will be used.
Return value
array Array containing the majorVersion and minorVersion.
Overrides ResourceManagerInterface::getResourceLastVersion
2 calls to ResourceManager::getResourceLastVersion()
- ResourceManager::getVersionFromRequest in src/
Resource/ ResourceManager.php - Gets the major and minor version for the current request.
- ResourceManager::parseVersionString in src/
Resource/ ResourceManager.php - Parses the version string.
File
- src/
Resource/ ResourceManager.php, line 328 - Contains \Drupal\restful\Resource\ResourceManager.
Class
Namespace
Drupal\restful\ResourceCode
public function getResourceLastVersion($resource_name, $major_version = NULL) {
$resources = array();
// Get all the resources corresponding to the resource name.
foreach ($this->pluginManager
->getDefinitions() as $plugin_id => $plugin_definition) {
if ($plugin_definition['resource'] != $resource_name || isset($major_version) && $plugin_definition['majorVersion'] != $major_version) {
continue;
}
$resources[$plugin_definition['majorVersion']][$plugin_definition['minorVersion']] = $plugin_definition;
}
// Sort based on the major version.
ksort($resources, SORT_NUMERIC);
// Get a list of resources for the latest major version.
$resources = end($resources);
if (empty($resources)) {
return NULL;
}
// Sort based on the minor version.
ksort($resources, SORT_NUMERIC);
// Get the latest resource for the minor version.
$resource = end($resources);
return array(
$resource['majorVersion'],
$resource['minorVersion'],
);
}