StackFormation\Profile\Manager::getClient PHP Method

getClient() public method

public getClient ( string $client, string $profile = null, array $args = [] ) : Aws\AwsClientInterface
$client string
$profile string
$args array
return Aws\AwsClientInterface
    public function getClient($client, $profile = null, array $args = [])
    {
        if (!is_string($client)) {
            throw new \InvalidArgumentException('Client parameter must be a string');
        }
        if (getenv('AWS_UNSET_PROFILE')) {
            $profile = '';
        }
        if (!is_null($profile) && !is_string($profile)) {
            throw new \InvalidArgumentException('Profile parameter must be a string');
        }
        $cacheKey = md5(json_encode([$client, $profile, $args]));
        if (!isset($this->clients[$cacheKey])) {
            if ($profile && !isset($args['credentials'])) {
                $args['credentials'] = $this->credentialProvider->getCredentialsForProfile($profile);
            }
            $this->printDebug($client, $profile);
            $this->clients[$cacheKey] = $this->getSdk()->createClient($client, $args);
        }
        return $this->clients[$cacheKey];
    }

Usage Example

 public function testLoadProfile()
 {
     chdir(FIXTURE_ROOT . 'ProfileManager/fixture_basic');
     putenv("AWS_DEFAULT_REGION=eu-west-1");
     $cfnClient = $this->profileManager->getClient('CloudFormation', 'test1');
     $credentials = $cfnClient->getCredentials()->wait(true);
     $this->assertEquals('TESTACCESSKEY1', $credentials->getAccessKeyId());
     $this->assertEquals('TESTSECRETKEY1', $credentials->getSecretKey());
 }