/**
  * Constructor
  *
  * @param array|Collection $parameters (optional) Collection of parameters
  *      to set on the command
  * @param ApiCommand $apiCommand (optional) Command definition from description
  */
 public function __construct($parameters = null, ApiCommand $apiCommand = null)
 {
     parent::__construct($parameters);
     // Add arguments and defaults to the command
     if ($apiCommand) {
         $this->apiCommand = $apiCommand;
         Inspector::getInstance()->validateConfig($apiCommand->getParams(), $this, false, false);
     } else {
         Inspector::getInstance()->validateClass(get_class($this), $this, false, false);
     }
     if (!$this->get('headers') instanceof Collection) {
         $this->set('headers', new Collection((array) $this->get('headers')));
     }
     $this->init();
 }
 /**
  * Constructor
  *
  * @param array|Collection    $parameters Collection of parameters to set on the command
  * @param ApiCommandInterface $apiCommand Command definition from description
  */
 public function __construct($parameters = null, ApiCommandInterface $apiCommand = null)
 {
     parent::__construct($parameters);
     $this->apiCommand = $apiCommand ?: ApiCommand::fromCommand(get_class($this));
     $this->initConfig();
     $headers = $this->get(self::HEADERS_OPTION);
     if (!$headers instanceof Collection) {
         $this->set(self::HEADERS_OPTION, new Collection((array) $headers));
     }
     // You can set a command.on_complete option in your parameters as a
     // convenience method for setting an onComplete function
     $onComplete = $this->get('command.on_complete');
     if ($onComplete) {
         $this->remove('command.on_complete');
         $this->setOnComplete($onComplete);
     }
     $this->init();
 }
 /**
  * @covers Guzzle\Service\Description\ApiCommand::toArray
  */
 public function testConvertsToArray()
 {
     $data = array('name' => 'test', 'class' => 'Guzzle\\Service\\Command\\ClosureCommand', 'doc' => 'test', 'method' => 'PUT', 'uri' => '/', 'params' => array('p' => new ApiParam(array('name' => 'foo'))));
     $c = new ApiCommand($data);
     $this->assertEquals($data, $c->toArray());
 }
Exemple #4
0
 /**
  * @covers Guzzle\Service\Description\ApiCommand::removeParam
  */
 public function testCanRemoveParams()
 {
     $c = new ApiCommand(array());
     $c->addParam(new ApiParam(array('name' => 'foo')));
     $this->assertTrue($c->hasParam('foo'));
     $c->removeParam('foo');
     $this->assertFalse($c->hasParam('foo'));
 }
 /**
  * @covers Guzzle\Service\Description\ApiCommand::validate
  * @expectedException Guzzle\Service\Exception\ValidationException
  * @expectedExceptionMessage Validation errors: Requires that the data argument be supplied.
  */
 public function testValidatesRequiredFieldsAreSet()
 {
     $command = new ApiCommand(array('params' => array('data' => new ApiParam(array('required' => true)))));
     $command->validate(new Collection());
 }