targetToEntity() public static method

public static targetToEntity ( $object, Scalr\Model\Entity\OrchestrationRule $entity )
$entity Scalr\Model\Entity\OrchestrationRule
Ejemplo n.º 1
0
 public static function targetToEntity($object, OrchestrationRule $entity)
 {
     /* @var $entity FarmRoleScript */
     parent::targetToEntity($object, $entity);
     if ($entity->target == static::TARGET_VALUE_SPECIFIED_FARM_ROLE) {
         /* @var $entity FarmRoleScript */
         if (empty($object->target->roles) || !is_array($object->target->roles)) {
             throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Property target.roles must be an array of FarmRoleForeignKeys");
         }
         $roles = $object->target->roles;
         $roleIds = [];
         foreach ($roles as $idx => $role) {
             if (empty($role)) {
                 throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid farm role identifier for target.roles[{$idx}]");
             } else {
                 if (is_object($role)) {
                     if (empty($role->id)) {
                         throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, "Missed property id for target.roles[{$idx}]");
                     }
                     $roleIds[] = $role->id;
                 } else {
                     $roleIds[] = $role;
                 }
             }
         }
         try {
             $entity->targets = $roleIds;
         } catch (InvalidEntityConfigurationException $e) {
             throw new ApiErrorException(404, ErrorMessage::ERR_OBJECT_NOT_FOUND, $e->getMessage(), $e->getCode(), $e);
         }
     }
 }