adapter() public method

Gets a new Instance of the adapter
public adapter ( string $name, string $scope = null, string $version = null ) : ApiEntityAdapter
$name string The name of the adapter
$scope string optional The scope of the adapter
$version string optional The version of the adapter
return Scalr\Api\DataType\ApiEntityAdapter Returns the instance of the specified adapter
Ejemplo n.º 1
0
 /**
  * Gets a new Instance of the adapter
  *
  * @param   string|CloudCredentials|object  $name   The name of the adapter, or CloudCredentials entity, or cloud credentials data
  *
  * @return  ApiEntityAdapter    Returns the instance of cloud credentials adapter
  *
  * @throws  ApiErrorException
  */
 public function adapter($name, array $transform = null)
 {
     if (is_object($name)) {
         //
         $property = $name instanceof $this->entityClass ? static::$entityDescriminator : static::$objectDiscriminator;
         $value = empty($transform) ? $name->{$property} : $transform[$name->{$property}];
         switch (true) {
             case PlatformFactory::isOpenstack($value, true):
                 $value = SERVER_PLATFORMS::OPENSTACK;
                 break;
             case PlatformFactory::isCloudstack($value):
                 $value = SERVER_PLATFORMS::CLOUDSTACK;
                 break;
             case PlatformFactory::isRackspace($value):
                 $value = SERVER_PLATFORMS::RACKSPACE;
                 break;
         }
         if (!isset(static::$inheritanceMap[$value])) {
             throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Unknown cloud '{$value}'");
         }
         $class = empty(static::$inheritanceMap) ? $value : static::$inheritanceMap[$value];
         $name = empty(static::$inheritedNamespace) ? $class : static::$inheritedNamespace . "\\{$class}";
     }
     return parent::adapter($name);
 }
Ejemplo n.º 2
0
 /**
  * Gets a new Instance of the adapter
  *
  * @param   string|FarmRoleScalingMetric|object $name                The name of the adapter or FarmRoleScalingMetric entity or farm role scaling metric data
  * @param   string                              $scope      optional The scope of the adapter
  * @param   string                              $version    optional The version of the adapter
  *
  * @return ApiEntityAdapter
  *
  * @throws ApiErrorException
  */
 public function adapter($name, $scope = null, $version = null)
 {
     if (is_object($name)) {
         $object = $name;
         if ($object instanceof FarmRoleScalingMetric) {
             $name = ScalingRuleAdapter::$ruleTypeMap[$object->metric->alias];
         } else {
             $name = $this->getBareId($object, 'ruleType');
             if (!$name) {
                 throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_STRUCTURE, 'Missed property ruleType');
             }
             if (!in_array($name, ScalingRuleAdapter::$ruleTypeMap)) {
                 throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, 'Unexpected ruleType value');
             }
         }
         $name = static::$scalingRuleNamespace . "\\" . $name;
     }
     return parent::adapter($name, $scope, $version);
 }