/**
  * {@inheritdoc}
  */
 public function factory($name, array $args = array())
 {
     $command = $this->description->getOperation($name);
     // If an inflector was passed, then attempt to get the command using snake_case inflection
     if (!$command && $this->inflector) {
         $command = $this->description->getOperation($this->inflector->snake($name));
     }
     if ($command) {
         $class = $command->getClass();
         return new $class($args, $command, $this->description);
     }
 }
예제 #2
0
 public function testAllowsRawResponses()
 {
     $description = new ServiceDescription(array('operations' => array('foo' => array('responseClass' => 'bar', 'responseType' => 'model')), 'models' => array('bar' => array())));
     $op = new OperationCommand(array(OperationCommand::RESPONSE_PROCESSING => OperationCommand::TYPE_RAW), $description->getOperation('foo'));
     $op->setClient(new Client());
     $request = $op->prepare();
     $response = new Response(200, array('Content-Type' => 'application/xml'), '<Foo><Baz>Bar</Baz></Foo>');
     $request->setResponse($response, true);
     $this->assertSame($response, $op->execute());
 }
예제 #3
0
 /**
  * Apply a bespoke operation command class to a given method, or all methods
  * @param string name of command using this class, or "" for all.
  * @param string full class name for operation class field
  * @return Swizzle
  * @throws \Exception
  */
 public function registerCommandClass($name, $class)
 {
     $this->commandClasses[$name] = $class;
     // set retrospectively if method already encountered
     if ($this->service) {
         if ($name) {
             $op = $this->service->getOperation($name) and $op->setClass($class);
         } else {
             throw new \Exception('Too late to register a global command class');
         }
     }
     return $this;
 }
예제 #4
0
 public function testReturnsNullWhenRetrievingMissingOperation()
 {
     $s = new ServiceDescription(array());
     $this->assertNull($s->getOperation('foo'));
 }