DNEnvironment::Backend PHP Method

Backend() public method

Enforces compliance with the allowed_backends setting; if the DNEnvironment.BackendIdentifier value is illegal then that value is ignored.
public Backend ( ) : DeploymentBackend
return DeploymentBackend
    public function Backend()
    {
        $backends = array_keys($this->config()->get('allowed_backends', Config::FIRST_SET));
        switch (sizeof($backends)) {
            // Nothing allowed, use the default value "DeploymentBackend"
            case 0:
                $backend = "DeploymentBackend";
                break;
                // Only 1 thing allowed, use that
            // Only 1 thing allowed, use that
            case 1:
                $backend = $backends[0];
                break;
                // Multiple choices, use our choice if it's legal, otherwise default to the first item on the list
            // Multiple choices, use our choice if it's legal, otherwise default to the first item on the list
            default:
                $backend = $this->BackendIdentifier;
                if (!in_array($backend, $backends)) {
                    $backend = $backends[0];
                }
        }
        return Injector::inst()->get($backend);
    }

Usage Example

 /**
  * @var array
  * @return \DeploymentStrategy
  */
 protected function createStrategy($options)
 {
     $strategy = $this->environment->Backend()->planDeploy($this->environment, $options);
     $data = $strategy->toArray();
     $interface = $this->project->getRepositoryInterface();
     if ($interface instanceof \ArrayData && $this->canCompareCodeVersions($interface, $data['changes'])) {
         $compareurl = sprintf('%s/compare/%s...%s', $interface->URL, $data['changes']['Code version']['from'], $data['changes']['Code version']['to']);
         $data['changes']['Code version']['compareUrl'] = $compareurl;
         // special case for .platform.yml field so we don't show a huge blob of changes,
         // but rather a link to where the .platform.yml changes were made in the code
         if (isset($data['changes']['.platform.yml other'])) {
             $data['changes']['.platform.yml other']['compareUrl'] = $compareurl;
             $data['changes']['.platform.yml other']['description'] = '';
         }
     }
     $this->extend('updateDeploySummary', $data);
     // Ensure changes that would have been updated are persisted in the object,
     // such as the comparison URL, so that they will be written to the Strategy
     // field on the DNDeployment object as part of {@link createDeployment()}
     $strategy->setChanges($data['changes']);
     return $strategy;
 }