Scalr\Api\Service\User\V1beta0\Adapter\RoleAdapter::behaviorsToData PHP Method

behaviorsToData() public static method

Transforms internal names of given behaviors to use in API
public static behaviorsToData ( array $behaviors ) : array
$behaviors array Array of a Role behaviors
return array Returns an array of names of behaviors
    public static function behaviorsToData(array $behaviors)
    {
        return array_merge(array_keys(array_intersect(static::$supportedBehaviors, $behaviors)), array_diff($behaviors, static::$supportedBehaviors));
    }

Usage Example

Beispiel #1
0
 /**
  * {@inheritdoc}
  * @see ApiEntityAdapter::validateEntity()
  * @param Entity\FarmRoleScalingMetric $entity scaling metric entity
  */
 public function validateEntity($entity)
 {
     if (!$entity instanceof Entity\FarmRoleScalingMetric) {
         throw new InvalidArgumentException(sprintf("First argument must be instance of Scalr\\Model\\Entity\\FarmRoleScalingMetric class"));
     }
     $farmRole = $entity->getFarmRole();
     if (empty($farmRole)) {
         throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, sprintf("Could not find out the Farm role with ID: %d", $entity->farmRoleId));
     }
     $disabledScalingBehaviors = array_intersect(FarmRoleAdapter::$disableScalingBehaviors, $farmRole->getRole()->getBehaviors());
     if (!empty($disabledScalingBehaviors)) {
         throw new ApiErrorException(409, ErrorMessage::ERR_CONFIGURATION_MISMATCH, sprintf('Can not add Scaling Metric to the Role with the following built-in automation types: %s.', implode(', ', RoleAdapter::behaviorsToData($disabledScalingBehaviors))));
     }
     if (empty($entity->id)) {
         if (empty($entity->metricId)) {
             throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property name");
         }
         $criteria = [['farmRoleId' => $entity->farmRoleId], ['metricId' => $entity->metricId]];
         if (!empty(Entity\FarmRoleScalingMetric::findOne($criteria))) {
             throw new ApiErrorException(409, ErrorMessage::ERR_UNICITY_VIOLATION, 'This Scaling metric already added to the current Farm role.');
         }
     }
 }
All Usage Examples Of Scalr\Api\Service\User\V1beta0\Adapter\RoleAdapter::behaviorsToData