示例#1
0
 /**
  * Class contructor attempts to assign authentication parameters
  * from $cfg argument. Authentication parameters may be configured
  * via Auth object or array. The parent constructor handles
  * the included configuration parameters.
  *
  * @param mixed $cfg API configuration potentially containing an 
  *        'auth' key with authentication parameters/object or a
  *        'cfg' key containing configurations to overwrite Config/Config.php.
  */
 public function __construct($cfg = null)
 {
     parent::__construct($cfg);
     // Load auth information if provided
     if (isset($cfg) && isset($cfg['auth'])) {
         if (is_object($cfg['auth']) && is_a($cfg['auth'], 'MyAllocator\\phpsdk\\src\\Object\\Auth')) {
             $this->auth = $cfg['auth'];
         } else {
             if (is_array($cfg['auth'])) {
                 $auth = new Auth();
                 $auth_refl = new \ReflectionClass($auth);
                 $props = $auth_refl->getProperties(\ReflectionProperty::IS_PUBLIC);
                 foreach ($props as $prop) {
                     $name = $prop->getName();
                     if (isset($cfg['auth'][$name])) {
                         $auth->{$name} = $cfg['auth'][$name];
                     }
                 }
                 $this->auth = $auth;
             }
         }
     }
 }
 /**
  * The constructor passes potential configuration parameters to MaBaseClass.
  *
  * @param array $cfg API configuration parameters.
  */
 public function __construct($cfg = null)
 {
     parent::__construct(array('cfg' => $cfg));
     $this->debug_echo("\n\nConfiguration:\n");
     $this->debug_print_r($this->config);
 }
 /**
  * @author nathanhelenihi
  */
 public function testGetConfig()
 {
     $cfg = array('paramValidationEnabled' => true, 'dataFormat' => 'array', 'debugsEnabled' => true);
     $obj = new MaBaseClass(array('cfg' => $cfg));
     // Bad parameters
     $this->assertNull($obj->getConfig(null));
     $this->assertNull($obj->getConfig(false));
     $this->assertNull($obj->getConfig(''));
     // Should succeed
     $this->assertSame($cfg['paramValidationEnabled'], $obj->getConfig('paramValidationEnabled'));
     $this->assertSame($cfg['dataFormat'], $obj->getConfig('dataFormat'));
     $this->assertSame($cfg['debugsEnabled'], $obj->getConfig('debugsEnabled'));
 }