/**
  * Creates a new operation with from a given annotated php method.
  *
  * @param ReflectionAnnotatedMethod $method An annotated php method
  *
  * @return ckWsdlOperation An operation, which's input corresponds to the parameters and which's output
  *                         corresponds to the return value of the given php method.
  */
 public static function create(ReflectionAnnotatedMethod $method)
 {
     $name = $method->getAnnotation('WSMethod')->getName();
     $result = new ckWsdlOperation();
     $result->setName($name);
     $params = ckDocBlockParser::parseParameters($method->getDocComment());
     $return = ckDocBlockParser::parseReturn($method->getDocComment());
     $headers = $method->getAllAnnotations('WSHeader');
     $result->input = new ckWsdlMessage($name . 'Request');
     $result->output = new ckWsdlMessage($name . 'Response');
     foreach ($headers as $header) {
         $type = ckXsdType::get($header->type);
         $type->setName($header->name);
         ckXsdType::set($header->name, $type);
         ckXsdType::set($header->type, null);
         $result->input->addPart(new ckWsdlPart($header->name, $type, true));
         $result->output->addPart(new ckWsdlPart($header->name, $type, true));
     }
     foreach ($params as $param) {
         $type = ckXsdType::get($param['type']);
         $result->input->addPart(new ckWsdlPart($param['name'], $type));
     }
     if (!empty($return)) {
         $type = ckXsdType::get($return['type']);
         $result->output->addPart(new ckWsdlPart('result', $type));
     }
     return $result;
 }
 /**
  * Generates a webservice definition in the wsdl format and optionally saves it to a given file.
  *
  * @param string $file The name of the file to which to save the generated webservice definition
  *
  * @return string A string containing the generated webservice definition
  */
 public function save($file = null)
 {
     $portType = new ckWsdlPortType();
     $portType->setName($this->context->getName() . 'PortType');
     foreach ($this->methods as $method) {
         $portType->addOperation(ckWsdlOperation::create($method));
     }
     $binding = new ckWsdlSoapBindingDecorator();
     $binding->setName($this->context->getName() . 'Binding');
     $binding->setPortType($portType);
     $port = new ckWsdlSoapPortDecorator();
     $port->setName($this->context->getName() . 'Port');
     $port->setLocation($this->context->getLocation());
     $port->setBinding($binding);
     $service = new ckWsdlService();
     $service->setName($this->context->getName() . 'Service');
     $service->addPort($port);
     $def = new ckWsdlDefinitions();
     $def->setName($this->context->getName());
     $def->addPortType($portType);
     $def->addBinding($binding);
     $def->addService($service);
     $doc = new DOMDocument('1.0', 'utf-8');
     $doc->formatOutput = true;
     $doc->appendChild($def->serialize($doc));
     $content = $doc->saveXML();
     if (!is_null($file)) {
         file_put_contents($file, $content);
     }
     return $content;
 }