Scalr\Model\Entity\CloudCredentials::bindEnvironment PHP Méthode

bindEnvironment() public méthode

Sets environment binding
public bindEnvironment ( integer $envId ) : EnvironmentCloudCredentials
$envId integer Environment identifier
Résultat EnvironmentCloudCredentials Returns new binding
    public function bindEnvironment($envId)
    {
        if (empty($this->id)) {
            throw new UnderflowException();
        }
        $envCloudCreds = new EnvironmentCloudCredentials();
        $envCloudCreds->cloudCredentialsId = $this->id;
        $envCloudCreds->envId = $envId;
        $envCloudCreds->cloud = $this->cloud;
        $this->_envBinds[$envCloudCreds->envId] = $envCloudCreds;
        return $envCloudCreds;
    }

Usage Example

Exemple #1
0
 /**
  * Gets cloud credentials for listed clouds
  *
  * @param   string[]    $clouds             optional Clouds list
  * @param   array       $credentialsFilter  optional Criteria to filter by CloudCredentials properties
  * @param   array       $propertiesFilter   optional Criteria to filter by CloudCredentialsProperties
  * @param   bool        $cacheResult        optional Cache result
  *
  * @return Entity\CloudCredentials[]
  */
 public function cloudCredentialsList(array $clouds = null, array $credentialsFilter = [], array $propertiesFilter = [], $cacheResult = true)
 {
     if (!is_array($clouds)) {
         $clouds = (array) $clouds;
     }
     $cloudCredentials = new Entity\CloudCredentials();
     $envCloudCredentials = new Entity\EnvironmentCloudCredentials();
     $cloudCredProps = new Entity\CloudCredentialsProperty();
     $criteria = array_merge($credentialsFilter, [\Scalr\Model\AbstractEntity::STMT_FROM => $cloudCredentials->table(), \Scalr\Model\AbstractEntity::STMT_WHERE => '']);
     if (!empty($clouds)) {
         $criteria[\Scalr\Model\AbstractEntity::STMT_FROM] .= "\n                JOIN {$envCloudCredentials->table('cecc')} ON\n                    {$cloudCredentials->columnId()} = {$envCloudCredentials->columnCloudCredentialsId('cecc')} AND\n                    {$cloudCredentials->columnCloud()} = {$envCloudCredentials->columnCloud('cecc')}\n            ";
         $clouds = implode(", ", array_map(function ($cloud) use($envCloudCredentials) {
             return $envCloudCredentials->qstr('cloud', $cloud);
         }, $clouds));
         $criteria[\Scalr\Model\AbstractEntity::STMT_WHERE] = "\n                {$envCloudCredentials->columnEnvId('cecc')} = {$envCloudCredentials->qstr('envId', $this->id)} AND\n                {$envCloudCredentials->columnCloud('cecc')} IN ({$clouds})\n            ";
     }
     if (!empty($propertiesFilter)) {
         foreach ($propertiesFilter as $property => $propCriteria) {
             $criteria[\Scalr\Model\AbstractEntity::STMT_FROM] .= "\n                    LEFT JOIN {$cloudCredProps->table('ccp')} ON\n                        {$cloudCredentials->columnId()} = {$cloudCredProps->columnCloudCredentialsId('ccp')} AND\n                        {$cloudCredProps->columnName('ccp')} = {$cloudCredProps->qstr('name', $property)}\n                ";
             $conjunction = empty($criteria[\Scalr\Model\AbstractEntity::STMT_WHERE]) ? "" : "AND";
             $criteria[\Scalr\Model\AbstractEntity::STMT_WHERE] .= "\n                    {$conjunction} {$cloudCredProps->_buildQuery($propCriteria, 'AND', 'ccp')}\n                ";
         }
     }
     /* @var $cloudsCredentials Entity\CloudCredentials[] */
     $cloudsCredentials = Entity\CloudCredentials::find($criteria);
     $result = [];
     $cont = \Scalr::getContainer();
     foreach ($cloudsCredentials as $cloudCredentials) {
         $result[$cloudCredentials->cloud] = $cloudCredentials;
         if ($cacheResult) {
             $cloudCredentials->bindEnvironment($this->id);
             $cloudCredentials->cache($cont);
         }
     }
     return $result;
 }
All Usage Examples Of Scalr\Model\Entity\CloudCredentials::bindEnvironment