WfsException.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. // @usage: throw new Api_WfsException("Access Denied to Create field '{$fieldName}' in object '{$typeName}.{$pkObject}'", __LINE__, null, 'MissingFieldPermCreate', 'request');
  3. // <xsd:schema
  4. // targetNamespace="http://www.opengis.net/ogc"
  5. // xmlns:ogc="http://www.opengis.net/ogc"
  6. // xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  7. // elementFormDefault="qualified">
  8. //
  9. // <xsd:element name="ServiceExceptionReport">
  10. // <xsd:complexType>
  11. // <xsd:sequence>
  12. // <xsd:element name="ServiceException"
  13. // type="ogc:ServiceExceptionType"
  14. // minOccurs="0" maxOccurs="unbounded"/>
  15. // </xsd:sequence>
  16. // <xsd:attribute name="version" type="xsd:string" fixed="1.3.0"/>
  17. // </xsd:complexType>
  18. // </xsd:element>
  19. //
  20. // <xsd:complexType name="ServiceExceptionType">
  21. // <xsd:simpleContent>
  22. // <xsd:extension base="xsd:string">
  23. // <xsd:attribute name="code" type="xsd:string"/>
  24. // <xsd:attribute name="locator" type="xsd:string"/>
  25. // </xsd:extension>
  26. // </xsd:simpleContent>
  27. // </xsd:complexType>
  28. // </xsd:schema>
  29. class Api_WfsException extends Exception {
  30. public $wfsCode = '';
  31. public $wfsLocator = '';
  32. public function __construct($message, $code = 0, Exception $previous = null, $wfsCode = '', $wfsLocator = '') {
  33. $this->wfsCode = $wfsCode;
  34. $this->wfsLocator = $wfsLocator;
  35. parent::__construct($message, $code, $previous);
  36. }
  37. public function generateResponseXml() {
  38. $xmlWriter = new XMLWriter();
  39. if (!$xmlWriter) throw new HttpException("Error no XMLWriter", 404);
  40. // $xmlWriter->openUri('php://output');
  41. $xmlWriter->openMemory();
  42. $xmlWriter->setIndent(true);
  43. $xmlWriter->startDocument('1.0','UTF-8');
  44. $xmlWriter->startElement('ServiceExceptionReport');
  45. {
  46. $xmlWriter->writeAttribute('xmlns', 'http://www.opengis.net/ogc');
  47. $xmlWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
  48. $xmlWriter->writeAttribute('xsi:schemaLocation', 'http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd');
  49. $xmlWriter->writeAttribute('version', '1.2.0');
  50. $xmlWriter->startElement('ServiceException');
  51. {
  52. if ($this->wfsCode) $xmlWriter->writeAttribute('code', $this->wfsCode);
  53. if ($this->wfsLocator) $xmlWriter->writeAttribute('locator', $this->wfsLocator);
  54. $xmlWriter->text($this->message);
  55. }
  56. $xmlWriter->endElement();// ServiceException
  57. }
  58. $xmlWriter->endElement();// ServiceExceptionReport
  59. $xmlWriter->endDocument();
  60. return $xmlWriter->outputMemory(true);
  61. }
  62. public function sendResponseXml() {
  63. header('Content-type: application/xml');
  64. echo $this->generateResponseXml();
  65. }
  66. }