moved code from client to common
This commit is contained in:
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapCommon.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Converter;
|
||||
|
||||
use BeSimple\SoapCommon\SoapKernel;
|
||||
|
||||
/**
|
||||
* Internal type converter interface.
|
||||
*
|
||||
* @author Andreas Schamberger <mail@andreass.net>
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
interface InternalTypeConverterInterface
|
||||
{
|
||||
/**
|
||||
* Get type namespace.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getTypeNamespace();
|
||||
|
||||
/**
|
||||
* Get type name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getTypeName();
|
||||
|
||||
/**
|
||||
* Convert given XML string to PHP type.
|
||||
*
|
||||
* @param string $data XML string
|
||||
* @param \BeSimple\SoapCommon\SoapKernel $soapKernel SoapKernel instance
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function convertXmlToPhp($data, SoapKernel $soapKernel);
|
||||
|
||||
/**
|
||||
* Convert PHP type to XML string.
|
||||
*
|
||||
* @param mixed $data PHP type
|
||||
* @param \BeSimple\SoapCommon\SoapKernel $soapKernel SoapKernel instance
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function convertPhpToXml($data, SoapKernel $soapKernel);
|
||||
}
|
96
src/BeSimple/SoapCommon/Converter/MtomTypeConverter.php
Normal file
96
src/BeSimple/SoapCommon/Converter/MtomTypeConverter.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapClient.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Converter;
|
||||
|
||||
use BeSimple\SoapCommon\Helper;
|
||||
use BeSimple\SoapCommon\Mime\Part as MimePart;
|
||||
use BeSimple\SoapCommon\SoapKernel;
|
||||
use BeSimple\SoapCommon\SoapRequest as CommonSoapRequest;
|
||||
use BeSimple\SoapCommon\SoapResponse as CommonSoapResponse;
|
||||
use BeSimple\SoapCommon\Converter\InternalTypeConverterInterface;
|
||||
|
||||
/**
|
||||
* MTOM type converter.
|
||||
*
|
||||
* @author Andreas Schamberger <mail@andreass.net>
|
||||
*/
|
||||
class MtomTypeConverter implements InternalTypeConverterInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getTypeNamespace()
|
||||
{
|
||||
return 'http://www.w3.org/2001/XMLSchema';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getTypeName()
|
||||
{
|
||||
return 'base64Binary';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function convertXmlToPhp($data, SoapKernel $soapKernel)
|
||||
{
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadXML($data);
|
||||
|
||||
$includes = $doc->getElementsByTagNameNS(Helper::NS_XOP, 'Include');
|
||||
$include = $includes->item(0);
|
||||
|
||||
// convert href -> myhref for external references as PHP throws exception in this case
|
||||
// http://svn.php.net/viewvc/php/php-src/branches/PHP_5_4/ext/soap/php_encoding.c?view=markup#l3436
|
||||
$ref = $include->getAttribute('myhref');
|
||||
|
||||
if ('cid:' === substr($ref, 0, 4)) {
|
||||
$contentId = urldecode(substr($ref, 4));
|
||||
|
||||
if (null !== ($part = $soapKernel->getAttachment($contentId))) {
|
||||
|
||||
return $part->getContent();
|
||||
} else {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function convertPhpToXml($data, SoapKernel $soapKernel)
|
||||
{
|
||||
$part = new MimePart($data);
|
||||
$contentId = trim($part->getHeader('Content-ID'), '<>');
|
||||
|
||||
$soapKernel->addAttachment($part);
|
||||
|
||||
$doc = new \DOMDocument();
|
||||
$node = $doc->createElement($this->getTypeName());
|
||||
$doc->appendChild($node);
|
||||
|
||||
// add xop:Include element
|
||||
$xinclude = $doc->createElementNS(Helper::NS_XOP, Helper::PFX_XOP . ':Include');
|
||||
$xinclude->setAttribute('href', 'cid:' . $contentId);
|
||||
$node->appendChild($xinclude);
|
||||
|
||||
return $doc->saveXML();
|
||||
}
|
||||
}
|
82
src/BeSimple/SoapCommon/Converter/SwaTypeConverter.php
Normal file
82
src/BeSimple/SoapCommon/Converter/SwaTypeConverter.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the BeSimpleSoapClient.
|
||||
*
|
||||
* (c) Christian Kerl <christian-kerl@web.de>
|
||||
* (c) Francis Besset <francis.besset@gmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
namespace BeSimple\SoapCommon\Converter;
|
||||
|
||||
use BeSimple\SoapCommon\Helper;
|
||||
use BeSimple\SoapCommon\Mime\Part as MimePart;
|
||||
use BeSimple\SoapCommon\SoapKernel;
|
||||
use BeSimple\SoapCommon\Converter\InternalTypeConverterInterface;
|
||||
|
||||
/**
|
||||
* SwA type converter.
|
||||
*
|
||||
* @author Andreas Schamberger <mail@andreass.net>
|
||||
*/
|
||||
class SwaTypeConverter implements InternalTypeConverterInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getTypeNamespace()
|
||||
{
|
||||
return 'http://www.w3.org/2001/XMLSchema';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getTypeName()
|
||||
{
|
||||
return 'base64Binary';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function convertXmlToPhp($data, SoapKernel $soapKernel)
|
||||
{
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadXML($data);
|
||||
|
||||
// convert href -> myhref for external references as PHP throws exception in this case
|
||||
// http://svn.php.net/viewvc/php/php-src/branches/PHP_5_4/ext/soap/php_encoding.c?view=markup#l3436
|
||||
$ref = $doc->documentElement->getAttribute('myhref');
|
||||
|
||||
if ('cid:' === substr($ref, 0, 4)) {
|
||||
$contentId = urldecode(substr($ref, 4));
|
||||
|
||||
if (null !== ($part = $soapKernel->getAttachment($contentId))) {
|
||||
|
||||
return $part->getContent();
|
||||
} else {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function convertPhpToXml($data, SoapKernel $soapKernel)
|
||||
{
|
||||
$part = new MimePart($data);
|
||||
$contentId = trim($part->getHeader('Content-ID'), '<>');
|
||||
|
||||
$soapKernel->addAttachment($part);
|
||||
|
||||
return sprintf('<%s href="%s"/>', $this->getTypeName(), $contentId);
|
||||
}
|
||||
}
|
@ -13,15 +13,41 @@
|
||||
namespace BeSimple\SoapCommon\Converter;
|
||||
|
||||
/**
|
||||
* Type converter interface.
|
||||
*
|
||||
* @author Christian Kerl <christian-kerl@web.de>
|
||||
*/
|
||||
interface TypeConverterInterface
|
||||
{
|
||||
/**
|
||||
* Get type namespace.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getTypeNamespace();
|
||||
|
||||
/**
|
||||
* Get type name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getTypeName();
|
||||
|
||||
/**
|
||||
* Convert given XML string to PHP type.
|
||||
*
|
||||
* @param string $data XML string
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function convertXmlToPhp($data);
|
||||
|
||||
/**
|
||||
* Convert PHP type to XML string.
|
||||
*
|
||||
* @param mixed $data PHP type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function convertPhpToXml($data);
|
||||
}
|
Reference in New Issue
Block a user