/** * 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; }