public function AcquiaLiftAPI::ensureUniqueAgentName in Acquia Lift Connector 7.2
Same name and namespace in other branches
- 7 includes/acquia_lift.classes.inc \AcquiaLiftAPI::ensureUniqueAgentName()
Returns a unique agent name based on the name passed in.
Checks existing agents in Acquia Lift and adds a suffix if the passed in name already exists. Also ensures the name is within the smaller of Acquia Lift's max length restriction and the passed in max length restriction.
Parameters
$agent_name: The desired agent name.
$max_length: The max length restriction other than that imposed by Acquia Lift itself. The function will use the smaller of the two max length restrictions.
Return value
string A machine-readable name for the agent that does not exist yet in Acquia Lift.
File
- includes/
AcquiaLiftAPI.inc, line 1031
Class
Code
public function ensureUniqueAgentName($agent_name, $max_length) {
if ($max_length > self::NAME_MAX_LENGTH) {
$max_length = self::NAME_MAX_LENGTH;
}
$agent_name = substr($agent_name, 0, $max_length);
$existing = $this
->getExistingAgentNames();
$index = 0;
$suffix = '';
while (in_array($agent_name . $suffix, $existing)) {
$suffix = '-' . $index;
while (strlen($agent_name . $suffix) > $max_length) {
$agent_name = substr($agent_name, 0, -1);
}
$index++;
}
$new_name = $agent_name . $suffix;
self::$existing_tests[] = $new_name;
return $new_name;
}