Ejemplo n.º 1
0
 /**
  * Start Generating EDMX file.
  *
  * @return EDMX xml object.
  */
 public function generateEDMX()
 {
     $this->xmlWriter->startElementNS(ODataConnectorForMySQLConstants::EDMX_NAMESPACE_PREFIX, ODataConnectorForMySQLConstants::EDMX_ELEMENT, ODataConnectorForMySQLConstants::EDMX_NAMESPACE_1_0);
     $this->xmlWriter->writeAttribute(ODataConnectorForMySQLConstants::EDMX_VERSION, ODataConnectorForMySQLConstants::EDMX_VERSION_VALUE);
     $this->xmlWriter->endAttribute();
     $this->xmlWriter->startElementNS(ODataConnectorForMySQLConstants::EDMX_NAMESPACE_PREFIX, ODataConnectorForMySQLConstants::EDMX_DATASERVICES_ELEMENT, null);
     $this->xmlWriter->startElement(ODataConnectorForMySQLConstants::SCHEMA);
     $this->xmlWriter->writeAttribute(ODataConnectorForMySQLConstants::NAMESPACE1, $this->schema->namespace);
     $this->xmlWriter->writeAttributeNS(ODataConnectorForMySQLConstants::XMLNS_NAMESPACE_PREFIX, ODataConnectorForMySQLConstants::ODATA_NAMESPACE_PREFIX, null, ODataConnectorForMySQLConstants::ODATA_NAMESPACE);
     $this->xmlWriter->writeAttributeNS(ODataConnectorForMySQLConstants::XMLNS_NAMESPACE_PREFIX, ODataConnectorForMySQLConstants::ODATA_METADATA_NAMESPACE_PREFIX, null, ODataConnectorForMySQLConstants::ODATA_METADATA_NAMESPACE);
     $this->xmlWriter->writeAttribute(ODataConnectorForMySQLConstants::XMLNS_NAMESPACE_PREFIX, ODataConnectorForMySQLConstants::CSDL_VERSION_1_0);
     $this->xmlWriter->endAttribute();
     try {
         $this->writeEntityType();
         $this->writeAssociations();
         $this->writeEntityContainer();
         $this->writeEntityInfo();
         $this->writeMappingDetails();
     } catch (Exception $e) {
         ODataConnectorForMySQLException::createInternalServerError();
     }
     $this->xmlWriter->endElement();
     $this->xmlWriter->endElement();
     $this->xmlWriter->endElement();
     $this->xmlWriter->endElement();
     return $this->xmlWriter->outputMemory(true);
 }
 /**
  * Serialize a PlayReadyLicenseResponseTemplate object into a PlayReadyLicenseResponseTemplate XML.
  *
  * @param PlayReadyLicenseResponseTemplate $template
  *
  * @return string The PlayReadyLicenseResponseTemplate XML
  */
 public static function serialize($template)
 {
     self::ValidateLicenseResponseTemplate($template);
     $writer = new \XMLWriter();
     $writer->openMemory();
     $writer->startElementNS(null, 'PlayReadyLicenseResponseTemplate', Resources::PRL_XML_NAMESPACE);
     $writer->writeAttributeNS('xmlns', 'i', null, Resources::XSI_XML_NAMESPACE);
     self::serializeLicenseTemplates($writer, $template->getLicenseTemplates());
     $writer->writeElement('ResponseCustomData', $template->getResponseCustomData());
     $writer->endElement();
     return $writer->outputMemory();
 }
Ejemplo n.º 3
0
 /**
  * Write an attribute with namespace if used
  *
  * @param  \XMLWriter $xmlWriter XMLWriter instance
  * @param  string     $prefix    Namespace prefix if any
  * @param  string     $name      Attribute name
  * @param  string     $namespace The uri of the namespace
  * @param  string     $value     The attribute content
  */
 protected function writeAttribute($xmlWriter, $prefix, $name, $namespace, $value)
 {
     if (empty($namespace)) {
         $xmlWriter->writeAttribute($name, $value);
     } else {
         $xmlWriter->writeAttributeNS($prefix, $name, $namespace, $value);
     }
 }
<?php

/* $Id$ */
$xw = new XMLWriter();
$xw->openMemory();
$xw->setIndent(TRUE);
$xw->setIndentString('   ');
$xw->startDocument('1.0', "UTF-8");
$xw->startElement('root');
$xw->startElementNS('ns1', 'child1', 'urn:ns1');
$xw->writeAttributeNS('ns1', 'att1', 'urn:ns1', '<>"\'&');
$xw->writeElement('chars', "special characters: <>\"'&");
$xw->endElement();
$xw->endDocument();
// Force to write and empty the buffer
$output = $xw->flush(true);
print $output;
Ejemplo n.º 5
0
/**
 * Construct the catalog entry
 *
 * @param XmlWriter $xml XML stream to write to
 * @param array $data data-blob of i18n and config variables
 * @param array $dataset array of the dataset identifiers
 */
function writeCatalog(XMLWriter $xml, array $data, array $dataset)
{
    $xml->startElementNS('rdf', 'Description', null);
    $xml->writeAttributeNS('rdf', 'about', null, $data['config']['uri'] . '#catalog');
    $xml->startElementNS('rdf', 'type', null);
    $xml->writeAttributeNS('rdf', 'resource', null, 'http://www.w3.org/ns/dcat#Catalog');
    $xml->endElement();
    $xml->startElementNS('dcterms', 'license', null);
    $xml->writeAttributeNS('rdf', 'resource', null, $data['config']['catalog-license']);
    $xml->endElement();
    $xml->startElementNS('dcat', 'themeTaxonomy', null);
    $xml->writeAttributeNS('rdf', 'resource', null, 'http://eurovoc.europa.eu/');
    $xml->endElement();
    $xml->writeElementNS('foaf', 'homepage', null, $data['config']['catalog-homepage']);
    $xml->startElementNS('dcterms', 'modified', null);
    $xml->writeAttributeNS('rdf', 'datatype', null, 'http://www.w3.org/2001/XMLSchema#date');
    $xml->text(date('Y-m-d'));
    $xml->endElement();
    $xml->startElementNS('dcterms', 'issued', null);
    $xml->writeAttributeNS('rdf', 'datatype', null, 'http://www.w3.org/2001/XMLSchema#date');
    $xml->text($data['config']['catalog-issued']);
    $xml->endElement();
    $xml->startElementNS('dcterms', 'publisher', null);
    $xml->writeAttributeNS('rdf', 'nodeID', null, $data['ids']['publisher']);
    $xml->endElement();
    // add language, title and description in each language
    writeCatalogI18n($xml, $data);
    // add datasets
    foreach ($dataset as $key => $value) {
        $xml->startElementNS('dcat', 'dataset', null);
        $xml->writeAttributeNS('rdf', 'resource', null, $value);
        $xml->endElement();
    }
    $xml->endElement();
}
 /**
  * Serialize a TokenRestrictionTemplate object into a TokenRestrictionTemplate XML
  * @param TokenRestrictionTemplate $tokenRestriction
  * @return string The TokenRestrictionTemplate XML
  */
 public static function serialize($tokenRestriction)
 {
     if (empty($tokenRestriction->getPrimaryVerificationKey()) && ($tokenRestriction->getOpenIdConnectDiscoveryDocument() == null || empty($tokenRestriction->getOpenIdConnectDiscoveryDocument()->getOpenIdDiscoveryUri()))) {
         throw new \RuntimeException("Both PrimaryVerificationKey and OpenIdConnectDiscoveryDocument are null");
     }
     if (empty($tokenRestriction->getAudience())) {
         throw new \RuntimeException("TokenRestrictionTemplate Serialize: Audience is required");
     }
     if (empty($tokenRestriction->getIssuer())) {
         throw new \RuntimeException("TokenRestrictionTemplate Serialize: Issuer is required");
     }
     $writer = new \XMLWriter();
     $writer->openMemory();
     $writer->startElementNS(null, 'TokenRestrictionTemplate', Resources::TRT_XML_NAMESPACE);
     $writer->writeAttributeNS('xmlns', 'i', null, Resources::XSI_XML_NAMESPACE);
     if (!empty($tokenRestriction->getAlternateVerificationKeys())) {
         TokenRestrictionTemplateSerializer::serializeAlternateVerificationKeys($writer, $tokenRestriction->getAlternateVerificationKeys());
     }
     $writer->writeElement("Audience", $tokenRestriction->getAudience());
     $writer->writeElement("Issuer", $tokenRestriction->getIssuer());
     if (!empty($tokenRestriction->getPrimaryVerificationKey())) {
         $writer->startElement('PrimaryVerificationKey');
         TokenRestrictionTemplateSerializer::serializeTokenVerificationKey($writer, $tokenRestriction->getPrimaryVerificationKey());
         $writer->endElement();
     }
     if (!empty($tokenRestriction->getRequiredClaims())) {
         TokenRestrictionTemplateSerializer::serializeRequiredClaims($writer, $tokenRestriction->getRequiredClaims());
     }
     if (!empty($tokenRestriction->getTokenType())) {
         $writer->writeElement('TokenType', $tokenRestriction->getTokenType());
     }
     if (!empty($tokenRestriction->getOpenIdConnectDiscoveryDocument())) {
         TokenRestrictionTemplateSerializer::serializeOpenIdConnectDiscoveryDocument($writer, $tokenRestriction->getOpenIdConnectDiscoveryDocument());
     }
     $writer->endElement();
     return $writer->outputMemory();
 }
Ejemplo n.º 7
0
 public function wsdl()
 {
     /************************
      ** SETUP XML
      ************************/
     $uri = sprintf("http://%s/api/soap", $_SERVER['HTTP_HOST']);
     $xml = new XMLWriter();
     $xml->openMemory();
     $xml->setIndent(TRUE);
     $xml->startDocument('1.0', 'UTF-8');
     $xml->startElementNS('wsdl', 'definitions', 'http://schemas.xmlsoap.org/wsdl/');
     $xml->writeAttributeNS('xmlns', 'soap', NULL, "http://schemas.xmlsoap.org/wsdl/soap/");
     #$xml->writeAttributeNS('xmlns', 'schema', NULL, $uri);
     $xml->writeAttributeNS('xmlns', 'xsd', NULL, "http://www.w3.org/2001/XMLSchema");
     $xml->writeAttributeNS('xmlns', 'xsi', NULL, "http://www.w3.org/2001/XMLSchema-instance");
     $xml->writeAttributeNS('xmlns', 'tns', NULL, "{$uri}");
     $xml->writeAttribute('targetNamespace', "{$uri}");
     #$xml->writeAttribute('name', $this->name);
     $xml->startElementNS('wsdl', 'documentation', NULL);
     $xml->text(sprintf('Auto Generated WSDL For %s Class By Quick_WSDL', $this->name));
     $xml->endElement();
     /************************
      ** TYPES
      ************************/
     $xml->startElementNS('wsdl', 'types', NULL);
     $xml->startElementNS('xsd', 'schema', NULL);
     $xml->writeAttribute('targetNamespace', "{$uri}");
     foreach (array_keys($this->ctes) as $n) {
         $xml->startElementNS('xsd', 'element', NULL);
         $xml->writeAttribute('name', $n);
         $xml->startElementNS('xsd', 'complexType', NULL);
         $xml->startElementNS('xsd', 'sequence', NULL);
         foreach ($this->ctes[$n] as $p) {
             $xml->startElementNS('xsd', 'element', NULL);
             $xml->writeAttribute('name', $p->name);
             $xml->writeAttribute('type', $p->type);
             if ($p->mand) {
                 $xml->writeAttribute('minOccurs', '1');
                 $xml->writeAttribute('maxOccurs', '1');
             } else {
                 $xml->writeAttribute('minOccurs', '0');
                 $xml->writeAttribute('maxOccurs', '1');
             }
             $xml->endElement();
             //element
         }
         $xml->endElement();
         //sequence
         $xml->endElement();
         //complexType
         $xml->endElement();
         //element
     }
     foreach ($this->oper as $o) {
         if (!isset($this->ctes[$o])) {
             $xml->startElementNS('xsd', 'element', NULL);
             $xml->writeAttribute('name', sprintf('%s', $o));
             $xml->startElementNS('xsd', 'complexType', NULL);
             $xml->startElementNS('xsd', 'sequence', NULL);
             foreach ($this->msgs[$o] as $p) {
                 $xml->startElementNS('xsd', 'element', NULL);
                 $xml->writeAttribute('name', $p->name);
                 $xml->writeAttribute('type', $p->type);
                 if ($p->mand) {
                     $xml->writeAttribute('minOccurs', '1');
                     $xml->writeAttribute('maxOccurs', '1');
                 } else {
                     $xml->writeAttribute('minOccurs', '0');
                     $xml->writeAttribute('maxOccurs', '1');
                 }
                 $xml->endElement();
             }
             $xml->endElement();
             //sequence
             $xml->endElement();
             //complexType
             $xml->endElement();
             //element
         }
         if (!isset($this->ctes[sprintf('%sResponse', $o)])) {
             $xml->startElementNS('xsd', 'element', NULL);
             $xml->writeAttribute('name', sprintf('%sResponse', $o));
             $xml->startElementNS('xsd', 'complexType', NULL);
             $xml->startElementNS('xsd', 'sequence', NULL);
             $xml->startElementNS('xsd', 'element', NULL);
             $xml->writeAttribute('name', $this->rets[$o]->name);
             $xml->writeAttribute('type', $this->rets[$o]->type);
             if ($p->mand) {
                 $xml->writeAttribute('minOccurs', '1');
                 $xml->writeAttribute('maxOccurs', '1');
             } else {
                 $xml->writeAttribute('minOccurs', '0');
                 $xml->writeAttribute('maxOccurs', '1');
             }
             $xml->endElement();
             $xml->endElement();
             //sequence
             $xml->endElement();
             //complexType
             $xml->endElement();
             //message
         }
     }
     $xml->endElement();
     //schema
     $xml->endElement();
     //types
     /************************
      ** MESSAGES
      ************************/
     foreach ($this->oper as $o) {
         $xml->startElementNS('wsdl', 'message', NULL);
         $xml->writeAttribute('name', sprintf('%sIn', $o));
         $xml->startElementNS('wsdl', 'part', NULL);
         $xml->writeAttribute('name', 'parameters');
         $xml->writeAttribute('element', sprintf('tns:%s', $o));
         $xml->endElement();
         $xml->endElement();
         //message
         $xml->startElementNS('wsdl', 'message', NULL);
         $xml->writeAttribute('name', sprintf('%sOut', $o));
         $xml->startElementNS('wsdl', 'part', NULL);
         $xml->writeAttribute('name', 'parameters');
         $xml->writeAttribute('element', sprintf('tns:%sResponse', $o));
         $xml->endElement();
         $xml->endElement();
         //message
     }
     /************************
      ** PORTTYPE
      ************************/
     $xml->startElementNS('wsdl', 'portType', NULL);
     $xml->writeAttribute('name', sprintf('Class_%s', $this->name));
     foreach ($this->oper as $o) {
         $xml->startElementNS('wsdl', 'operation', NULL);
         $xml->writeAttribute('name', $o);
         $xml->startElementNS('wsdl', 'documentation', NULL);
         $xml->text('TODO: Add Documentation');
         $xml->endElement();
         $xml->startElementNS('wsdl', 'input', NULL);
         $xml->writeAttribute('message', sprintf('tns:%sIn', $o));
         $xml->endElement();
         $xml->startElementNS('wsdl', 'output', NULL);
         $xml->writeAttribute('message', sprintf('tns:%sOut', $o));
         $xml->endElement();
         $xml->endElement();
         //operation
     }
     $xml->endElement();
     //portType
     /************************
      ** BINDING
      ************************/
     $xml->startElementNS('wsdl', 'binding', NULL);
     $xml->writeAttribute('name', sprintf('Bind_%s', $this->name));
     $xml->writeAttribute('type', sprintf('tns:Class_%s', $this->name));
     $xml->startElementNS('soap', 'binding', NULL);
     $xml->writeAttribute('style', 'document');
     $xml->writeAttribute('transport', 'http://schemas.xmlsoap.org/soap/http');
     //$xml->writeAttribute('namespace', "$uri");
     $xml->endElement();
     foreach ($this->oper as $o) {
         $xml->startElementNS('wsdl', 'operation', NULL);
         $xml->writeAttribute('name', $o);
         $xml->startElementNS('soap', 'operation', NULL);
         $xml->writeAttribute('soapAction', "{$uri}/{$o}");
         $xml->endElement();
         $xml->startElementNS('wsdl', 'input', NULL);
         $xml->startElementNS('soap', 'body', NULL);
         $xml->writeAttribute('use', 'literal');
         //$xml->writeAttribute('namespace',"$uri/$o");
         $xml->endElement();
         $xml->endElement();
         $xml->startElementNS('wsdl', 'output', NULL);
         $xml->startElementNS('soap', 'body', NULL);
         $xml->writeAttribute('use', 'literal');
         $xml->endElement();
         $xml->endElement();
         $xml->endElement();
         //wsdl:operation
     }
     $xml->endElement();
     //wsdl:binding
     /************************
      ** SERVICE
      ************************/
     $xml->startElementNS('wsdl', 'service', NULL);
     $xml->writeAttribute('name', $this->name);
     $xml->startElementNS('wsdl', 'port', NULL);
     $xml->writeAttribute('name', sprintf('%sEndpoint', $this->name));
     $xml->writeAttribute('binding', sprintf('tns:Bind_%s', $this->name));
     $xml->startElementNS('soap', 'address', NULL);
     $xml->writeAttribute('location', "{$uri}/index.php");
     $xml->endElement();
     $xml->endElement();
     //port
     $xml->endElement();
     //service
     /************************
      ** CLEANUP
      ************************/
     $xml->endElement();
     //definitions
     $xml->endDocument();
     header('Content-type: text/xml; charset=UTF-8');
     echo $xml->outputMemory(TRUE);
 }
Ejemplo n.º 8
0
 /**
  * @param string $prefix
  * @param string $name
  * @param string $uri
  * @param string $content
  * @return bool
  */
 public function writeAttributeNS($prefix, $name, $uri = null, $content)
 {
     if (!$this->hasNSPrefix($prefix)) {
         $this->nsArray[$prefix] = $uri;
     }
     return parent::writeAttributeNS($prefix, $name, $uri, $content);
 }
Ejemplo n.º 9
0
 /**
  * Packages the message currently stored in the object into a valid GovTalk
  * envelope ready for sending.
  *
  * @return mixed The XML package (as a string) in GovTalk format, or false on failure.
  */
 protected function _packageGovTalkEnvelope()
 {
     // Firstly check we have everything we need to build the envelope...
     if (isset($this->_messageClass) && isset($this->_messageQualifier)) {
         if (isset($this->_govTalkSenderId) && isset($this->_govTalkPassword)) {
             if (isset($this->_messageAuthType)) {
                 // Generate the transaction ID...
                 $this->_generateTransactionId();
                 if (isset($this->_messageBody)) {
                     // Create the XML document (in memory)...
                     $package = new XMLWriter();
                     $package->openMemory();
                     $package->setIndent(true);
                     // Packaging...
                     $package->startElement('GovTalkMessage');
                     $xsiSchemaLocation = 'http://www.govtalk.gov.uk/documents/envelope-v2-0.xsd';
                     if ($this->_additionalXsiSchemaLocation !== null) {
                         $xsiSchemaLocation .= ' ' . $this->_additionalXsiSchemaLocation;
                     }
                     $package->writeAttribute('xmlns', 'http://www.govtalk.gov.uk/CM/envelope');
                     $package->writeAttributeNS('xsi', 'schemaLocation', 'http://www.w3.org/2001/XMLSchema-instance', $xsiSchemaLocation);
                     $package->writeElement('EnvelopeVersion', '2.0');
                     // Header...
                     $package->startElement('Header');
                     // Message details...
                     $package->startElement('MessageDetails');
                     $package->writeElement('Class', $this->_messageClass);
                     $package->writeElement('Qualifier', $this->_messageQualifier);
                     if ($this->_messageFunction !== null) {
                         $package->writeElement('Function', $this->_messageFunction);
                     }
                     $package->writeElement('TransactionID', $this->_transactionId);
                     if ($this->_messageCorrelationId !== null) {
                         $package->writeElement('CorrelationID', $this->_messageCorrelationId);
                     }
                     if ($this->_messageTransformation !== 'XML') {
                         $package->writeElement('Transformation', $this->_messageTransformation);
                     }
                     $package->writeElement('GatewayTest', $this->_govTalkTest);
                     $package->endElement();
                     # MessageDetails
                     // Sender details...
                     $package->startElement('SenderDetails');
                     // Authentication...
                     $package->startElement('IDAuthentication');
                     $package->writeElement('SenderID', $this->_govTalkSenderId);
                     $package->startElement('Authentication');
                     switch ($this->_messageAuthType) {
                         case 'alternative':
                             if ($authenticationArray = $this->generateAlternativeAuthentication($this->_transactionId)) {
                                 $package->writeElement('Method', $authenticationArray['method']);
                                 $package->writeElement('Value', $authenticationArray['token']);
                             } else {
                                 return false;
                             }
                             break;
                         case 'clear':
                             $package->writeElement('Method', 'clear');
                             $package->writeElement('Value', $this->_govTalkPassword);
                             break;
                     }
                     $package->endElement();
                     # Authentication
                     $package->endElement();
                     # IDAuthentication
                     if ($this->_senderEmailAddress !== null) {
                         $package->writeElement('EmailAddress', $this->_senderEmailAddress);
                     }
                     $package->endElement();
                     # SenderDetails
                     $package->endElement();
                     # Header
                     // GovTalk details...
                     $package->startElement('GovTalkDetails');
                     // Keys...
                     if (count($this->_govTalkKeys) > 0) {
                         $package->startElement('Keys');
                         foreach ($this->_govTalkKeys as $keyPair) {
                             $package->startElement('Key');
                             $package->writeAttribute('Type', $keyPair['type']);
                             $package->text($keyPair['value']);
                             $package->endElement();
                             # Key
                         }
                         $package->endElement();
                         # Keys
                     }
                     // Target details...
                     if (count($this->_messageTargetDetails) > 0) {
                         $package->startElement('TargetDetails');
                         foreach ($this->_messageTargetDetails as $targetOrganisation) {
                             $package->writeElement('Organisation', $targetOrganisation);
                         }
                         $package->endElement();
                         # TargetDetails
                     }
                     // Channel routing...
                     $channelRouteArray = $this->_messageChannelRouting;
                     $channelRouteArray[] = array('uri' => 'http://code.google.com/p/php-govtalk/', 'product' => 'php-govtalk', 'version' => '1.0', 'timestamp' => date('c'));
                     foreach ($channelRouteArray as $channelRoute) {
                         $package->startElement('ChannelRouting');
                         $package->startElement('Channel');
                         $package->writeElement('URI', $channelRoute['uri']);
                         if (array_key_exists('product', $channelRoute)) {
                             $package->writeElement('Product', $channelRoute['product']);
                         }
                         if (array_key_exists('version', $channelRoute)) {
                             $package->writeElement('Version', $channelRoute['version']);
                         }
                         $package->endElement();
                         # Channel
                         if (array_key_exists('id', $channelRoute) && is_array($channelRoute['id'])) {
                             foreach ($channelRoute['id'] as $channelRouteId) {
                                 $package->startElement('ID');
                                 $package->writeAttribute('type', $channelRouteId['type']);
                                 $package->text($channelRouteId['value']);
                                 $package->endElement();
                                 # ID
                             }
                         }
                         $package->writeElement('Timestamp', $channelRoute['timestamp']);
                         $package->endElement();
                         # ChannelRouting
                     }
                     $package->endElement();
                     # GovTalkDetails
                     // Body...
                     $package->startElement('Body');
                     if (is_string($this->_messageBody)) {
                         $package->writeRaw("\n" . trim($this->_messageBody) . "\n");
                     } else {
                         if (is_a($this->_messageBody, 'XMLWriter')) {
                             $package->writeRaw("\n" . trim($this->_messageBody->outputMemory()) . "\n");
                         }
                     }
                     $package->endElement();
                     # Body
                     $package->endElement();
                     # GovTalkMessage
                     // Flush the buffer, run any extension-specific digests, validate the schema
                     // and return the XML...
                     $xmlPackage = $this->packageDigest($package->flush());
                     $validXMLRequest = true;
                     if (isset($this->_additionalXsiSchemaLocation) && $this->_schemaValidation == true) {
                         $validation = new DOMDocument();
                         $validation->loadXML($xmlPackage);
                         if (!$validation->schemaValidate($this->_additionalXsiSchemaLocation)) {
                             $validXMLRequest = false;
                         }
                     }
                     if ($validXMLRequest === true) {
                         return $xmlPackage;
                     } else {
                         return false;
                     }
                 } else {
                     return false;
                 }
             } else {
                 return false;
             }
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 10
0
 public function writeAttributeNS($prefix, $name, $uri, $content)
 {
     $this->xmlWriter->writeAttributeNS($prefix, $name, $uri, $content);
 }
Ejemplo n.º 11
0
 function fiskalsve()
 {
     $zahtjev = $this->input->post('request');
     $msg = '';
     $uspjelo = 0;
     $nijeuspjelo = 0;
     //$firma = $this->fiskal->getById('firma', 'fi_id', $this->session->userdata('firmaID'));
     $firma = $this->fiskal->getFirma();
     //dohvati podatke za sve  nefiskalizirane
     $nefiskalizirani = $this->fiskal->getNefiskalizirane();
     //foreach ID
     if ($nefiskalizirani) {
         foreach ($nefiskalizirani as $dokument) {
             //dohvati pojedinacno
             $prikaziStavke = $this->fiskal->getstavke($dokument->do_id);
             $zaglavlje = $this->fiskal->getDokumentZag($dokument->do_id);
             $rekapitualcijaporeza = $this->fiskal->rekapitulacijaporeza($dokument->do_id);
             //Init XML
             $doc = new DOMDocument();
             $doc->formatOutput = true;
             //XML
             $ns = 'tns';
             $writer = new XMLWriter();
             $writer->openMemory();
             $writer->startDocument('1.0', 'UTF-8');
             $writer->setIndent(True);
             $writer->startElementNs($ns, 'RacunZahtjev', null);
             $writer->writeAttributeNS("xmlns", "tns", null, "http://www.apis-it.hr/fin/2012/types/f73");
             $writer->writeAttributeNS("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
             $writer->startElementNs($ns, 'Racun', null);
             $writer->writeElementNs($ns, 'Oib', null, $firma->fi_oib);
             $writer->writeElementNs($ns, 'USustPdv', null, $firma->fi_usustavuPDV);
             $writer->writeElementNs($ns, 'DatVrijeme', null, date("d.m.Y", strtotime($zaglavlje->do_datum)) . date("\\Th:i:s", strtotime($zaglavlje->do_vrijeme)));
             // date('d.m.Y\Th:i:s'));
             $writer->writeElementNs($ns, 'OznSlijed', null, 'N');
             /* P ili N => P na nivou Poslovnog prostora, N na nivou naplatnog uredaja */
             $writer->startElementNs($ns, 'BrRac', null);
             $writer->writeElementNs($ns, 'BrOznRac', null, $zaglavlje->do_broj);
             $writer->writeElementNs($ns, 'OznPosPr', null, $zaglavlje->PP);
             $writer->writeElementNs($ns, 'OznNapUr', null, $zaglavlje->NU);
             $writer->endElement();
             /* #BrRac */
             $writer->startElementNs($ns, 'Pdv', null);
             if (!empty($rekapitualcijaporeza)) {
                 $rank = 0;
                 foreach ($rekapitualcijaporeza as $porez) {
                     $writer->startElementNs($ns, 'Porez', null);
                     $writer->writeElementNs($ns, 'Stopa', null, $porez->porez_pz_posto);
                     $writer->writeElementNs($ns, 'Osnovica', null, $porez->sumaIznosa);
                     $writer->writeElementNs($ns, 'Iznos', null, number_format($porez->sumaPorez, 2, '.', ''));
                     $writer->endElement();
                     /* #Porez */
                 }
             }
             $writer->endElement();
             /* #Pdv */
             if (!empty($rekapitualcijaporeza)) {
                 $rank = 0;
                 foreach ($rekapitualcijaporeza as $porez) {
                     if ($porez->porez_pz_posto == "0") {
                         $writer->writeElementNs($ns, 'IznosOslobPdv', null, number_format($porez->sumaIznosa + $porez->sumaPorez, 2, '.', ''));
                     }
                 }
             }
             //$writer->writeElementNs($ns, 'IznosNePodlOpor', null, number_format($zaglavlje->do_iznos + $zaglavlje->do_iznosPDV,  2,'.',''));
             $writer->writeElementNs($ns, 'IznosUkupno', null, number_format($zaglavlje->do_iznos + $zaglavlje->do_iznosPDV, 2, '.', ''));
             $writer->writeElementNs($ns, 'NacinPlac', null, $zaglavlje->sp_oznaka);
             $writer->writeElementNs($ns, 'OibOper', null, $zaglavlje->op_oib);
             $writer->writeElementNs($ns, 'NakDost', null, '1');
             $writer->endElement();
             /* #Racun */
             $writer->endElement();
             /* #RacunZahtjev */
             $writer->endDocument();
             $XMLRequest = $writer->outputMemory();
             $doc->loadXML($XMLRequest);
             //file_put_contents("racun".$dokument->do_id.".xml",$XMLRequest);
             //fiskaliziraj
             if ($firma != FALSE) {
                 try {
                     $fis = new Fiskalizator($firma->fi_certifikat, $this->decrypt($firma->fi_pass));
                     //Produkcijski mode
                     //$fis->setProductionMode();
                     $fis->doRequest($doc);
                     #custom timeout and number of retries on network error, default is 3 retries and 5 seconds timeout tolerance
                     #$fis->doRequest($doc, 10, 5.2);
                     if ($fis->getRequestType() == 'RacunZahtjev') {
                         //echo 'JIR: '.$fis->getJIR().'<br>';
                         //echo 'ZKI: '.$fis->getZKI().'<br>';
                         $msg = '<pre class="bg-success">Uspje&#353;no fiskalizirani svi dokument!</pre>';
                         $uspjelo = $uspjelo + 1;
                         //update raèun
                         $dok['do_zki'] = $fis->getZKI();
                         $dok['do_jir'] = $fis->getJIR();
                         $this->fiskal->update("dokument", "do_id", $zaglavlje->do_id, $dok);
                     }
                 } catch (Exception $e) {
                     if ($zahtjev == 'RacunZahtjev') {
                         //update raèun
                         $dok['do_zki'] = $fis->getZKI();
                         $dok['do_sifragreske'] = $e->getMessage();
                         $this->fiskal->update("dokument", "do_id", $zaglavlje->do_id, $dok);
                     }
                     $msg = '<pre class="bg-danger">Gre&#353;ka </br>' . $e->getMessage() . '</pre>';
                     $nijeuspjelo = $nijeuspjelo + 1;
                 }
             }
         }
     }
     if ($nijeuspjelo == 0) {
         echo json_encode(array('uspjelo' => $uspjelo, 'poruka' => '<div class="alert alert-success">Uspje&#353;no fiskaliziranih ra&#269;una: <b>' . $uspjelo . '!</b></div>'));
     } else {
         echo json_encode(array('uspjelo' => $uspjelo, 'poruka' => '<div class="alert alert-danger">Nespje&#353;no fiskaliziranih ra&#269;una: <b>' . $nijeuspjelo . '</b> , uspje&#353;no fiskalizirano <b>' . $uspjelo . '</b></div>'));
     }
 }
Ejemplo n.º 12
0
}
try {
    $xmlWriter = new \XMLWriter();
    /**
     *  @throws  Exception
     */
    if (false === $xmlWriter->openMemory()) {
        throw new Exception('Can not start XMLWriter memory');
    }
    /**
     *  @throws  Exception
     */
    if (false === $xmlWriter->startElement('map')) {
        throw new Exception('Can not start map element');
    }
    $xmlWriter->writeAttributeNS('xmlns', 'xsi', null, 'https://raw.githubusercontent.com/jeschkec/GozintograPHP/master/src/main/ressources/schema/gozintographp.xsd');
} catch (Exception $exception) {
    fwrite(STDERR, $exception->getMessage());
    exit(3);
}
/**
 *
 */
foreach ($files as $File) {
    try {
        $gozintographp = new Application($File);
        $gozintographp->read();
        $gozintographp->parse();
        $gozintographp->dump(new \XMLWriter());
    } catch (Exception $exception) {
        fwrite(STDERR, $exception->getMessage());