BeSimpleSoap/src/BeSimple/SoapClient/WsdlDownloader.php

88 lines
2.9 KiB
PHP
Raw Normal View History

<?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;
use BeSimple\SoapClient\Curl\Curl;
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;
use DOMDocument;
use DOMElement;
use DOMXPath;
use Exception;
2011-10-16 19:49:24 +02: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
{
public static function instantiateDownloader()
{
return new self();
}
2011-10-16 19:49:24 +02:00
/**
* @param Curl $curl
* @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
* @param boolean $resolveRemoteIncludes
* @return string
2011-10-16 19:49:24 +02:00
*/
public function getWsdlPath(Curl $curl, $wsdlPath, $wsdCacheType, $resolveRemoteIncludes = true)
2011-10-16 19:49:24 +02:00
{
$isRemoteFile = RemoteFileResolver::instantiateResolver()->isRemoteFile($wsdlPath);
$isCacheEnabled = $wsdCacheType === Cache::TYPE_NONE ? false : Cache::isEnabled();
if ($isCacheEnabled === true) {
$cacheFilePath = Cache::getDirectory() . DIRECTORY_SEPARATOR . 'wsdl_' . md5($wsdlPath) . '.cache';
$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) {
XmlFileDomDocumentProcessor::writeCacheFile($curl, $wsdCacheType, $wsdlPath, $cacheFilePath, $resolveRemoteIncludes, $isRemoteFile);
}
return $this->getLocalWsdlPath($cacheFilePath);
2013-07-24 23:18:41 +02:00
}
if ($isRemoteFile === true) {
return $wsdlPath;
2011-10-16 19:49:24 +02:00
}
return $this->getLocalWsdlPath($wsdlPath);
}
2013-07-24 23:18:41 +02:00
private function getLocalWsdlPath($wsdlPath)
{
if (file_exists($wsdlPath)) {
return realpath($wsdlPath);
}
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
}