Scalr\Api\Rest\Controller\ApiController::adapter PHP Method

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
    public function adapter($name, $scope = null, $version = null)
    {
        if (empty($scope)) {
            $scope = '$2';
        }
        if (empty($version)) {
            $version = '$3';
        }
        //The same version Adapter should be used as the version of the controller
        $adapterClass = preg_replace('/^(?<namespace>.+?)\\\\(?<scope>[^\\\\]+?)\\\\(?<version>V\\d+(?:beta\\d*)?)(?<class>\\\\.+)$/', "\$1\\\\" . ucfirst($scope) . "\\\\" . ucfirst($version) . "\\Adapter\\" . ucfirst($name) . 'Adapter', get_class($this));
        return new $adapterClass($this);
    }

Usage Example

Exemplo 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);
 }
All Usage Examples Of Scalr\Api\Rest\Controller\ApiController::adapter