Scalr\Model\Entity\CloudCredentials::cache PHP Method

cache() public method

Cache self in specified container
public cache ( )
    public function cache()
    {
        $container = \Scalr::getContainer();
        $contCloudCredId = "keychain.cloud_creds.{$this->id}";
        $container->setShared($contCloudCredId, function () {
            return $this;
        });
        if (isset($this->_envBinds)) {
            foreach ($this->_envBinds as $envCloudCreds) {
                $envCloudCredId = "keychain.env_cloud_creds.{$envCloudCreds->envId}.{$this->cloud}";
                $container->setShared($envCloudCredId, function () {
                    return $this->id;
                });
            }
        }
    }

Usage Example

Exemplo n.º 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::cache