コード例 #1
0
 /**
  * Get an item out of the context.
  *
  * @todo Should there be an option to NOT query the Bootstrap::conf()?
  *
  * @param string $name    The name to look up. First look it up in the context,
  *                        then look it up in the Bootstrap config.
  * @param mixed  $default The default value to return if no config param was
  *                        found.
  *
  * @return mixed The discovered result, or $default if specified, or null if
  *               no $default is specified.
  */
 protected function cxt($name, $default = null)
 {
     // Lazilly populate the context array.
     if (is_resource($this->context) && empty($this->contextArray)) {
         $cxt = stream_context_get_options($this->context);
         // If a custom scheme name has been set, use that.
         if (!empty($cxt[$this->schemeName])) {
             $this->contextArray = $cxt[$this->schemeName];
         } elseif (!empty($cxt[self::DEFAULT_SCHEME])) {
             $this->contextArray = $cxt[self::DEFAULT_SCHEME];
         }
     }
     // Should this be array_key_exists()?
     if (isset($this->contextArray[$name])) {
         return $this->contextArray[$name];
     }
     // Check to see if the value can be gotten from
     // \OpenStack\Bootstrap.
     $val = \OpenStack\Bootstrap::config($name, null);
     if (isset($val)) {
         return $val;
     }
     return $default;
 }
コード例 #2
0
 /**
  * Test the bootstrap identity factory.
  * @depends testAuthenticateAsUser
  */
 public function testBootstrap()
 {
     // We need to save the config settings and reset the bootstrap to this.
     // It does not remove the old settings. The means the identity fall through
     // for different settings may not happen because of ordering. So, we cache
     // and reset back to the default for each test.
     $reset = Bootstrap::$config;
     // Test authenticating as a user.
     $settings = ['username' => self::conf('openstack.identity.username'), 'password' => self::conf('openstack.identity.password'), 'endpoint' => self::conf('openstack.identity.url'), 'tenantid' => self::conf('openstack.identity.tenantId'), 'transport' => self::conf('transport'), 'transport.debug' => self::conf('transport.debug', false), 'transport.ssl_verify' => self::conf('transport.ssl', true)];
     if (self::conf('transport.timeout')) {
         $setting['transport.timeout'] = self::conf('transport.timeout');
     }
     if (self::conf('transport.proxy')) {
         $setting['transport.proxy'] = self::conf('transport.proxy');
     }
     Bootstrap::setConfiguration($settings);
     $is = Bootstrap::identity(true);
     $this->assertInstanceOf('\\OpenStack\\Identity\\v2\\IdentityService', $is);
     // Test getting a second instance from the cache.
     $is2 = Bootstrap::identity();
     $this->assertEquals($is, $is2);
     // Test that forcing a refresh does so.
     $is2 = Bootstrap::identity(true);
     $this->assertNotEquals($is, $is2);
     Bootstrap::$config = $reset;
     // Test with tenant name
     $settings = ['username' => self::conf('openstack.identity.username'), 'password' => self::conf('openstack.identity.password'), 'endpoint' => self::conf('openstack.identity.url'), 'tenantname' => self::conf('openstack.identity.tenantName'), 'transport' => self::conf('transport'), 'transport.debug' => self::conf('transport.debug', false), 'transport.ssl_verify' => self::conf('transport.ssl', true)];
     if (self::conf('transport.timeout')) {
         $setting['transport.timeout'] = self::conf('transport.timeout');
     }
     if (self::conf('transport.proxy')) {
         $setting['transport.proxy'] = self::conf('transport.proxy');
     }
     Bootstrap::setConfiguration($settings);
     $is = Bootstrap::identity(true);
     $this->assertInstanceOf('\\OpenStack\\Identity\\v2\\IdentityService', $is);
 }