2011-12-17 20:36:56 +01:00
|
|
|
<?php
|
2011-10-16 19:49:24 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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\SoapClient;
|
|
|
|
|
2017-02-03 15:22:37 +01:00
|
|
|
use BeSimple\SoapClient\Curl\Curl;
|
2017-07-18 18:52:52 +02:00
|
|
|
use BeSimple\SoapClient\Xml\RemoteFileResolver;
|
|
|
|
use BeSimple\SoapClient\Xml\XmlFileDomDocumentProcessor;
|
2013-07-24 23:18:41 +02:00
|
|
|
use BeSimple\SoapCommon\Cache;
|
2011-12-11 21:20:35 +01:00
|
|
|
use BeSimple\SoapCommon\Helper;
|
2017-02-03 15:22:37 +01:00
|
|
|
use DOMDocument;
|
|
|
|
use DOMElement;
|
|
|
|
use DOMXPath;
|
|
|
|
use Exception;
|
2011-11-02 12:48:51 +01:00
|
|
|
|
2011-10-16 19:49:24 +02:00
|
|
|
/**
|
2011-11-02 12:48:51 +01:00
|
|
|
* Downloads WSDL files with cURL. Uses the WSDL_CACHE_* constants and the
|
|
|
|
* 'soap.wsdl_*' ini settings. Does only file caching as SoapClient only
|
|
|
|
* supports a file name parameter. The class also resolves remote XML schema
|
|
|
|
* includes.
|
2011-10-16 19:49:24 +02:00
|
|
|
*
|
2011-10-22 11:28:15 +02:00
|
|
|
* @author Andreas Schamberger <mail@andreass.net>
|
2011-10-16 19:49:24 +02:00
|
|
|
*/
|
|
|
|
class WsdlDownloader
|
|
|
|
{
|
2017-07-18 18:52:52 +02:00
|
|
|
public static function instantiateDownloader()
|
|
|
|
{
|
|
|
|
return new self();
|
|
|
|
}
|
|
|
|
|
2011-10-16 19:49:24 +02:00
|
|
|
/**
|
2016-11-08 15:42:52 +01:00
|
|
|
* @param Curl $curl
|
2017-02-03 15:22:37 +01:00
|
|
|
* @param string $wsdlPath WSDL file URL/path
|
|
|
|
* @param int $wsdCacheType = Cache::TYPE_NONE|Cache::WSDL_CACHE_DISK|Cache::WSDL_CACHE_BOTH|Cache::WSDL_CACHE_MEMORY
|
2016-11-08 15:42:52 +01:00
|
|
|
* @param boolean $resolveRemoteIncludes
|
2017-02-03 15:22:37 +01:00
|
|
|
* @return string
|
2011-10-16 19:49:24 +02:00
|
|
|
*/
|
2017-02-03 15:22:37 +01:00
|
|
|
public function getWsdlPath(Curl $curl, $wsdlPath, $wsdCacheType, $resolveRemoteIncludes = true)
|
2011-10-16 19:49:24 +02:00
|
|
|
{
|
2017-07-18 18:52:52 +02:00
|
|
|
$isRemoteFile = RemoteFileResolver::instantiateResolver()->isRemoteFile($wsdlPath);
|
2017-02-03 15:22:37 +01:00
|
|
|
$isCacheEnabled = $wsdCacheType === Cache::TYPE_NONE ? false : Cache::isEnabled();
|
|
|
|
if ($isCacheEnabled === true) {
|
2017-07-18 18:52:52 +02:00
|
|
|
$cacheFilePath = Cache::getDirectory() . DIRECTORY_SEPARATOR . 'wsdl_' . md5($wsdlPath) . '.cache';
|
2017-02-03 15:22:37 +01:00
|
|
|
$isCacheExisting = file_exists($cacheFilePath);
|
|
|
|
if ($isCacheExisting) {
|
|
|
|
$fileModificationTime = filemtime($cacheFilePath);
|
|
|
|
if ($fileModificationTime === false) {
|
|
|
|
throw new Exception('File modification time could not be get for wsdl path: ' . $cacheFilePath);
|
|
|
|
}
|
|
|
|
$isCacheValid = ($fileModificationTime + Cache::getLifetime()) >= time();
|
|
|
|
} else {
|
|
|
|
$isCacheExisting = $isCacheValid = false;
|
|
|
|
}
|
|
|
|
if ($isCacheExisting === false || $isCacheValid === false) {
|
2017-07-18 18:52:52 +02:00
|
|
|
XmlFileDomDocumentProcessor::writeCacheFile($curl, $wsdCacheType, $wsdlPath, $cacheFilePath, $resolveRemoteIncludes, $isRemoteFile);
|
2017-02-03 15:22:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getLocalWsdlPath($cacheFilePath);
|
2013-07-24 23:18:41 +02:00
|
|
|
|
2017-02-03 15:22:37 +01:00
|
|
|
}
|
|
|
|
if ($isRemoteFile === true) {
|
2017-07-18 18:52:52 +02:00
|
|
|
return $wsdlPath;
|
2011-10-16 19:49:24 +02:00
|
|
|
}
|
2017-07-18 18:52:52 +02:00
|
|
|
|
|
|
|
return $this->getLocalWsdlPath($wsdlPath);
|
2017-02-03 15:22:37 +01:00
|
|
|
}
|
2013-07-24 23:18:41 +02:00
|
|
|
|
2017-02-03 15:22:37 +01:00
|
|
|
private function getLocalWsdlPath($wsdlPath)
|
|
|
|
{
|
|
|
|
if (file_exists($wsdlPath)) {
|
|
|
|
|
|
|
|
return realpath($wsdlPath);
|
|
|
|
|
|
|
|
}
|
2017-06-07 15:50:04 +02:00
|
|
|
|
2017-07-18 18:52:52 +02:00
|
|
|
throw new Exception('Could not download WSDL: local file does not exist: ' . $wsdlPath);
|
2011-10-16 19:49:24 +02:00
|
|
|
}
|
2013-07-24 23:18:41 +02:00
|
|
|
}
|