summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
Diffstat (limited to 'library')
-rwxr-xr-xlibrary/SSRS/Object/Abstract.php48
-rwxr-xr-xlibrary/SSRS/Object/ArrayIterator.php41
-rwxr-xr-xlibrary/SSRS/Object/CatalogItem.php10
-rwxr-xr-xlibrary/SSRS/Object/CatalogItems.php26
-rwxr-xr-xlibrary/SSRS/Object/ExecutionInfo.php19
-rwxr-xr-xlibrary/SSRS/Object/ExecutionParameter.php10
-rwxr-xr-xlibrary/SSRS/Object/ExecutionParameters.php38
-rwxr-xr-xlibrary/SSRS/Object/Extension.php10
-rwxr-xr-xlibrary/SSRS/Object/Extensions.php26
-rwxr-xr-xlibrary/SSRS/Object/ItemDefinition.php22
-rwxr-xr-xlibrary/SSRS/Object/Report.php14
-rwxr-xr-xlibrary/SSRS/Object/ReportOutput.php25
-rwxr-xr-xlibrary/SSRS/Object/ReportParameter.php10
-rwxr-xr-xlibrary/SSRS/Object/ReportParameters.php26
-rwxr-xr-xlibrary/SSRS/Report.php297
-rwxr-xr-xlibrary/SSRS/Report/Exception.php3
-rwxr-xr-xlibrary/SSRS/Soap/Exception.php3
-rwxr-xr-xlibrary/SSRS/Soap/NTLM.php164
18 files changed, 792 insertions, 0 deletions
diff --git a/library/SSRS/Object/Abstract.php b/library/SSRS/Object/Abstract.php
new file mode 100755
index 0000000..40482a0
--- /dev/null
+++ b/library/SSRS/Object/Abstract.php
@@ -0,0 +1,48 @@
+<?php
+
+/**
+ * SSRS_Object_Abstract
+ *
+ * @author arron
+ */
+class SSRS_Object_Abstract {
+
+ public $data = array();
+
+ public function __construct($data = null) {
+ $this->init();
+ $this->setData($data);
+ }
+
+ public function init() {
+
+ }
+
+ public function setData($data) {
+ if ($data instanceof stdClass) {
+ $data = get_object_vars($data);
+ }
+
+ if (is_array($data)) {
+ foreach ($data AS $key => $value) {
+ $this->$key = $value;
+ }
+ }
+
+ return $this;
+ }
+
+ public function __set($key, $value) {
+ $methodName = 'set' . ucfirst($key);
+ if (method_exists($this, $methodName)) {
+ $this->$methodName($value);
+ } else {
+ $this->data[$key] = $value;
+ }
+ }
+
+ public function __get($key) {
+ return isset($this->data[$key]) ? $this->data[$key] : null;
+ }
+
+} \ No newline at end of file
diff --git a/library/SSRS/Object/ArrayIterator.php b/library/SSRS/Object/ArrayIterator.php
new file mode 100755
index 0000000..ad53ad5
--- /dev/null
+++ b/library/SSRS/Object/ArrayIterator.php
@@ -0,0 +1,41 @@
+<?php
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ * Description of Iterator
+ *
+ * @author andrew
+ */
+class SSRS_Object_ArrayIterator extends SSRS_Object_Abstract implements Iterator {
+
+ public $iteratorKey = 'Array';
+
+ public function next() {
+ return next($this->data[$this->iteratorKey]);
+ }
+
+ public function prev() {
+ return prev($this->data[$this->iteratorKey]);
+ }
+
+ public function key() {
+ return key($this->data[$this->iteratorKey]);
+ }
+
+ public function current() {
+ return current($this->data[$this->iteratorKey]);
+ }
+
+ public function valid() {
+ return isset($this->data[$this->iteratorKey][$this->key()]);
+ }
+
+ public function rewind() {
+ return reset($this->data[$this->iteratorKey]);
+ }
+
+} \ No newline at end of file
diff --git a/library/SSRS/Object/CatalogItem.php b/library/SSRS/Object/CatalogItem.php
new file mode 100755
index 0000000..cf0e25d
--- /dev/null
+++ b/library/SSRS/Object/CatalogItem.php
@@ -0,0 +1,10 @@
+<?php
+
+/**
+ * SSRS_Object_Abstract
+ *
+ * @author arron
+ */
+class SSRS_Object_CatalogItem extends SSRS_Object_Abstract {
+
+}
diff --git a/library/SSRS/Object/CatalogItems.php b/library/SSRS/Object/CatalogItems.php
new file mode 100755
index 0000000..c68a964
--- /dev/null
+++ b/library/SSRS/Object/CatalogItems.php
@@ -0,0 +1,26 @@
+<?php
+
+/**
+ * SSRS_Object_Abstract
+ *
+ * @author arron
+ */
+class SSRS_Object_CatalogItems extends SSRS_Object_ArrayIterator {
+
+ public $iteratorKey = 'CatalogItems';
+
+ public function init() {
+ $this->data['CatalogItems'] = array();
+ }
+
+ public function setCatalogItems(stdClass $items) {
+ foreach ($items->CatalogItem AS $item) {
+ $this->addCatalogItem(new SSRS_Object_CatalogItem($item));
+ }
+ }
+
+ public function addCatalogItem(SSRS_Object_CatalogItem $item) {
+ $this->data['CatalogItems'][] = $item;
+ }
+
+}
diff --git a/library/SSRS/Object/ExecutionInfo.php b/library/SSRS/Object/ExecutionInfo.php
new file mode 100755
index 0000000..42b8c31
--- /dev/null
+++ b/library/SSRS/Object/ExecutionInfo.php
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * SSRS_Object_Abstract
+ *
+ * @author arron
+ */
+class SSRS_Object_ExecutionInfo extends SSRS_Object_Abstract {
+
+ public function setExecutionInfo(stdClass $info) {
+ $this->setData($info);
+ }
+
+ public function setParameters(stdClass $params){
+ $this->data['Parameters'] = new SSRS_Object_ReportParameters();
+ $this->data['Parameters']->setParameters($params->ReportParameter);
+ }
+
+}
diff --git a/library/SSRS/Object/ExecutionParameter.php b/library/SSRS/Object/ExecutionParameter.php
new file mode 100755
index 0000000..36680e9
--- /dev/null
+++ b/library/SSRS/Object/ExecutionParameter.php
@@ -0,0 +1,10 @@
+<?php
+
+/**
+ * Description of ExecutionParameters
+ *
+ * @author andrew
+ */
+class SSRS_Object_ExecutionParameter extends SSRS_Object_Abstract {
+
+}
diff --git a/library/SSRS/Object/ExecutionParameters.php b/library/SSRS/Object/ExecutionParameters.php
new file mode 100755
index 0000000..b107438
--- /dev/null
+++ b/library/SSRS/Object/ExecutionParameters.php
@@ -0,0 +1,38 @@
+<?php
+
+/**
+ * Description of ExecutionParameters
+ *
+ * @author andrew
+ */
+class SSRS_Object_ExecutionParameters extends SSRS_Object_ArrayIterator{
+
+ public $iteratorKey = 'Parameters';
+
+ public function init() {
+ $this->data['Parameters'] = array();
+ }
+
+ public function setParameters(SSRS_Object_ReportParameters $parameters) {
+ foreach ($parameters AS $parameter) {
+ if (($parameters instanceof SSRS_Object_ExecutionParameter) === false) {
+ $parameter = new SSRS_Object_ExecutionParameter($parameter);
+ }
+
+ $this->data['Parameters'][] = $parameter;
+ }
+ }
+
+ public function getParameterArrayForSoapCall(){
+ $execParams = array();
+ foreach ($this AS $parameter) {
+ $execParams[] = array(
+ 'Name' => $parameter->Name,
+ 'Value' => $parameter->Value,
+ );
+ }
+
+ return $execParams;
+ }
+
+}
diff --git a/library/SSRS/Object/Extension.php b/library/SSRS/Object/Extension.php
new file mode 100755
index 0000000..efae2dd
--- /dev/null
+++ b/library/SSRS/Object/Extension.php
@@ -0,0 +1,10 @@
+<?php
+
+/**
+ * SSRS_Object_Abstract
+ *
+ * @author arron
+ */
+class SSRS_Object_Extension extends SSRS_Object_Abstract {
+
+}
diff --git a/library/SSRS/Object/Extensions.php b/library/SSRS/Object/Extensions.php
new file mode 100755
index 0000000..786c1b6
--- /dev/null
+++ b/library/SSRS/Object/Extensions.php
@@ -0,0 +1,26 @@
+<?php
+
+/**
+ * SSRS_Object_Abstract
+ *
+ * @author arron
+ */
+class SSRS_Object_Extensions extends SSRS_Object_ArrayIterator {
+
+ public $iteratorKey = 'Extension';
+
+ public function init() {
+ $this->data['Extension'] = array();
+ }
+
+ public function setExtensions(stdClass $items) {
+ foreach ($items->Extension AS $item) {
+ $this->addExtension(new SSRS_Object_Extension($item));
+ }
+ }
+
+ public function addExtension(SSRS_Object_Extension $item) {
+ $this->data['Extension'][] = $item;
+ }
+
+}
diff --git a/library/SSRS/Object/ItemDefinition.php b/library/SSRS/Object/ItemDefinition.php
new file mode 100755
index 0000000..f63d57e
--- /dev/null
+++ b/library/SSRS/Object/ItemDefinition.php
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * Description of ExecutionParameters
+ *
+ * @author andrew
+ */
+class SSRS_Object_ItemDefinition extends SSRS_Object_Abstract {
+
+ public function getXMLString() {
+ return $this->Definition;
+ }
+
+ public function getSimpleXML() {
+ return new SimpleXMLElement($this->getXMLString());
+ }
+
+ public function __toString() {
+ return $this->getXMLString();
+ }
+
+}
diff --git a/library/SSRS/Object/Report.php b/library/SSRS/Object/Report.php
new file mode 100755
index 0000000..6733e28
--- /dev/null
+++ b/library/SSRS/Object/Report.php
@@ -0,0 +1,14 @@
+<?php
+
+/**
+ * Description of ExecutionParameters
+ *
+ * @author andrew
+ */
+class SSRS_Object_Report extends SSRS_Object_Abstract{
+
+ public function setExecutionInfo(stdClass $info){
+ $this->data['executionInfo'] = new SSRS_Object_ExecutionInfo($info);
+ }
+
+}
diff --git a/library/SSRS/Object/ReportOutput.php b/library/SSRS/Object/ReportOutput.php
new file mode 100755
index 0000000..81f8598
--- /dev/null
+++ b/library/SSRS/Object/ReportOutput.php
@@ -0,0 +1,25 @@
+<?php
+
+/**
+ * Description of ExecutionParameters
+ *
+ * @author andrew
+ */
+class SSRS_Object_ReportOutput extends SSRS_Object_Abstract {
+
+ public function download($filename){
+ header("Cache-Control: public");
+ header("Content-Description: File Transfer");
+ header("Content-Disposition: attachment; filename=$filename");
+ header("Content-Type: " . $this->mimeType);
+ header("Content-Transfer-Encoding: binary");
+ header("Content-Length: " . strlen($this->Result));
+
+ die($this->Result);
+ }
+
+ public function __toString(){
+ return $this->Result;
+ }
+
+}
diff --git a/library/SSRS/Object/ReportParameter.php b/library/SSRS/Object/ReportParameter.php
new file mode 100755
index 0000000..346b082
--- /dev/null
+++ b/library/SSRS/Object/ReportParameter.php
@@ -0,0 +1,10 @@
+<?php
+
+/**
+ * Description of ExecutionParameters
+ *
+ * @author andrew
+ */
+class SSRS_Object_ReportParameter extends SSRS_Object_Abstract {
+
+}
diff --git a/library/SSRS/Object/ReportParameters.php b/library/SSRS/Object/ReportParameters.php
new file mode 100755
index 0000000..dc9b7b3
--- /dev/null
+++ b/library/SSRS/Object/ReportParameters.php
@@ -0,0 +1,26 @@
+<?php
+
+/**
+ * Description of ExecutionParameters
+ *
+ * @author andrew
+ */
+class SSRS_Object_ReportParameters extends SSRS_Object_ArrayIterator{
+
+ public $iteratorKey = 'Parameters';
+
+ public function init() {
+ $this->data['Parameters'] = array();
+ }
+
+ public function setParameters($parameters) {
+ foreach ($parameters AS $parameter) {
+ if (($parameters instanceof SSRS_Object_ReportParameter) === false) {
+ $parameter = new SSRS_Object_ReportParameter($parameter);
+ }
+
+ $this->data['Parameters'][] = $parameter;
+ }
+ }
+
+}
diff --git a/library/SSRS/Report.php b/library/SSRS/Report.php
new file mode 100755
index 0000000..c3f48ba
--- /dev/null
+++ b/library/SSRS/Report.php
@@ -0,0 +1,297 @@
+<?php
+
+require_once('Soap/NTLM.php');
+require_once('Soap/Exception.php');
+require_once('Object/Abstract.php');
+require_once('Object/ArrayIterator.php');
+require_once('Object/CatalogItems.php');
+require_once('Object/CatalogItem.php');
+require_once('Object/ItemDefinition.php');
+require_once('Object/ExecutionParameter.php');
+require_once('Object/ExecutionParameters.php');
+require_once('Object/ExecutionInfo.php');
+require_once('Object/Extensions.php');
+require_once('Object/Extension.php');
+require_once('Object/ReportParameter.php');
+require_once('Object/ReportParameters.php');
+require_once('Object/Report.php');
+require_once('Object/ReportOutput.php');
+require_once('Report/Exception.php');
+
+/**
+ * Description of SSRSReport
+ *
+ * @author Andrew Lowe
+ */
+class SSRS_Report {
+
+ public $servicePath = 'ReportService2010.asmx';
+ public $executionPath = 'ReportExecution2005.asmx';
+ protected $_baseUri;
+ protected $_username;
+ protected $_passwd;
+ protected $_soapService;
+ protected $_soapExecution;
+ protected $_executionNameSpace = 'http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices';
+ protected $_headerExecutionLayout = '<ExecutionHeader xmlns="%s"><ExecutionID>%s</ExecutionID></ExecutionHeader>';
+ protected $_sessionId;
+
+ /**
+ *
+ * @param string $baseUri
+ * @param array $options
+ */
+ public function __construct($baseUri, $options = array()) {
+ $this->_baseUri = rtrim($baseUri, '/');
+
+ if (array_key_exists('username', $options)) {
+ $this->setUsername($options['username']);
+ }
+
+ if (array_key_exists('password', $options)) {
+ $this->setPassword($options['password']);
+ }
+ }
+
+ /**
+ * Sets the Soap client class with the Execution Uri so that the connection to the web service can be made.
+ * Should be the custom SOAP NTLM class to bypass NTLM security.
+ *
+ * @param SoapClient $client
+ */
+ public function setSoapExecution(SoapClient $client) {
+ $this->_soapExecution = $client;
+ return $this;
+ }
+
+ /**
+ * Sets the Soap client class with the Service Uri so that the connection to the web service can be made.
+ * Should be the custom SOAP NTLM class to bypass NTLM security.
+ *
+ * @param SoapClient $client
+ */
+ public function setSoapService(SoapClient $client) {
+ $this->_soapService = $client;
+ return $this;
+ }
+
+ /**
+ * Returns the SOAP client Execution object so that methods of the web service can be run.
+ * If the SOAP Execution object is undefined then it will be set.
+ *
+ * @return SoapClient
+ */
+ public function getSoapExecution($runInit = true) {
+ if ($this->_soapExecution === null) {
+ $options = array('username' => $this->_username, 'password' => $this->_passwd);
+ $client = new SSRS_Soap_NTLM($this->_baseUri . '/' . $this->executionPath, $options);
+ if ($runInit) {
+ $client->init();
+ }
+
+ $this->setSoapExecution($client);
+ }
+
+ return $this->_soapExecution;
+ }
+
+ /**
+ * Returns the SOAP client Service object so that methods of the web service can be run.
+ * If the SOAP Service object is undefined then it will be set.
+ *
+ * @return SoapClient
+ */
+ public function getSoapService($runInit = true) {
+ if ($this->_soapService === null) {
+ $options = array('username' => $this->_username, 'password' => $this->_passwd);
+ $client = new SSRS_Soap_NTLM($this->_baseUri . '/' . $this->servicePath, $options);
+ if ($runInit) {
+ $client->init();
+ }
+
+ $this->setSoapService($client);
+ }
+
+ return $this->_soapService;
+ }
+
+ /**
+ * Sets username property
+ *
+ * @param string $username
+ * @return SSRS_Report
+ */
+ public function setUsername($username) {
+ $this->_username = (string) $username;
+ return $this;
+ }
+
+ /**
+ * Sets password property
+ *
+ * @param string $password
+ * @return SSRS_Report
+ */
+ public function setPassword($password) {
+ $this->_passwd = (string) $password;
+ return $this;
+ }
+
+ /**
+ * Returns username property value
+ *
+ * @return string
+ */
+ public function getUsername() {
+ return $this->_username;
+ }
+
+ /**
+ * Returns password property value
+ *
+ * @return string
+ */
+ public function getPassword() {
+ return $this->_passwd;
+ }
+
+ /**
+ * Sets Session ID, taken from the LoadReport method under property 'ExecutionID'.
+ * Required for later methods to produce report.
+ * Adds to the main SOAP header through the SOAP Execution object.
+ *
+ * @param string $id
+ */
+ public function setSessionId($id) {
+ $client = $this->getSoapExecution();
+ $parameters = array(array('name' => 'ExecutionID', 'value' => $id));
+
+ $headerStr = sprintf($this->_headerExecutionLayout, $this->_executionNameSpace, $id);
+ $soapVar = new SoapVar($headerStr, XSD_ANYXML, null, null, null);
+
+ $soapHeader = new SoapHeader($this->_executionNameSpace, 'ExecutionHeader', $soapVar);
+ $client->__setSoapHeaders(array($soapHeader));
+
+ $this->_sessionId = $id;
+ return $this;
+ }
+
+ /**
+ * Returns a list of all child items from a specified location.
+ * Used to show all reports available.
+ *
+ * @param string $itemPath
+ * @param boolean $recursive
+ * @return SSRS_Object_CatalogItems
+ */
+ public function listChildren($itemPath, $recursive = false) {
+ $params = array(
+ 'ItemPath' => $itemPath,
+ 'Recursive' => $recursive
+ );
+
+ $result = $this->getSoapService()->ListChildren($params);
+ return new SSRS_Object_CatalogItems($result);
+ }
+
+ /**
+ * Returns item definition details in a XML string.
+ * Used to backup report definitions into a XML based RDL file.
+ *
+ * @param string $itemPath
+ * @return SSRS_Object_ItemDefinition
+ */
+ public function getItemDefinition($itemPath) {
+ $params = array(
+ 'ItemPath' => $itemPath,
+ );
+ $result = $this->getSoapService()->GetItemDefinition($params);
+ return new SSRS_Object_ItemDefinition($result);
+ }
+
+ /**
+ * Returns a list of all render types to output reports to, such as XML, HTML & PDF.
+ *
+ * @return SSRS_Object_Extensions
+ */
+ public function listRenderingExtensions() {
+ return new SSRS_Object_Extensions($this->getSoapExecution()->ListRenderingExtensions());
+ }
+
+ /**
+ * Loads all details relating to a report including all available search parameters
+ *
+ * @param string $Report
+ * @param string $HistoryId
+ * @return SSRS_Object_Report
+ */
+ public function loadReport($Report, $HistoryId = null) {
+ $params = array(
+ 'Report' => $Report,
+ 'HistoryID' => $HistoryId
+ );
+
+ $result = $this->getSoapExecution()->LoadReport($params);
+ return new SSRS_Object_Report($result);
+ }
+
+ /**
+ * Sets all search parameters for the report to render.
+ * Pass details from 'LoadReport' method to set the search parameters.
+ * Requires the Session/Execution ID to be set.
+ *
+ * @param SSRS_Object_ExecutionParameters $request
+ * @param string $id
+ * @return SSRS_Object_ExecutionInfo
+ */
+ public function setExecutionParameters(SSRS_Object_ExecutionParameters $parameters, $parameterLanguage = 'en-us') {
+ $this->checkSessionId();
+
+ $options = array(
+ 'Parameters' => $parameters->getParameterArrayForSoapCall(),
+ 'ParameterLanguage' => $parameterLanguage,
+ );
+
+ $result = $this->getSoapExecution()->SetExecutionParameters($options);
+ return new SSRS_Object_ExecutionInfo($result);
+ }
+
+ /**
+ * Renders and outputs report depending on $format variable.
+ *
+ * @param string $format
+ * @param string $PaginationMode
+ * @return SSRS_Object_ReportOutput
+ */
+ public function render($format, $PaginationMode='Estimate') {
+ $this->checkSessionId();
+
+ $renderParams = array(
+ 'Format' => $format,
+ 'DeviceInfo' => '<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>',
+ 'PaginationMode' => $PaginationMode
+ );
+
+ $result = $this->getSoapExecution()->Render2($renderParams);
+ return new SSRS_Object_ReportOutput($result);
+ }
+
+ /**
+ * Checks if there is a valid Session ID set.
+ *
+ */
+ public function checkSessionId() {
+ if ($this->hasValidSessionId() === false) {
+ throw new SSRS_Report_Exception('Session ID not set');
+ }
+ }
+
+ /**
+ * Checks to see if the Session ID is not empty and returns boolean value
+ *
+ */
+ public function hasValidSessionId() {
+ return (!empty($this->_sessionId));
+ }
+
+}
diff --git a/library/SSRS/Report/Exception.php b/library/SSRS/Report/Exception.php
new file mode 100755
index 0000000..a6afac5
--- /dev/null
+++ b/library/SSRS/Report/Exception.php
@@ -0,0 +1,3 @@
+<?php
+
+class SSRS_Report_Exception extends Exception{} \ No newline at end of file
diff --git a/library/SSRS/Soap/Exception.php b/library/SSRS/Soap/Exception.php
new file mode 100755
index 0000000..c2c0977
--- /dev/null
+++ b/library/SSRS/Soap/Exception.php
@@ -0,0 +1,3 @@
+<?php
+
+class SSRS_Soap_Exception extends Exception{} \ No newline at end of file
diff --git a/library/SSRS/Soap/NTLM.php b/library/SSRS/Soap/NTLM.php
new file mode 100755
index 0000000..951b14b
--- /dev/null
+++ b/library/SSRS/Soap/NTLM.php
@@ -0,0 +1,164 @@
+<?php
+
+class SSRS_Soap_NTLM extends SoapClient {
+
+ protected $_uri;
+ protected $_username;
+ protected $_passwd;
+ protected $_cachePath;
+ protected $_cacheExpiry;
+ protected $_lastRequest;
+ protected $_lastResponse;
+
+ function __construct($wsdl, $options = array()) {
+ if (!array_key_exists('cache_wsdl_path', $options)) {
+ $options['cache_wsdl_path'] = '/tmp/' . md5($wsdl) . '.wsdl';
+ }
+
+ if (array_key_exists('username', $options)) {
+ $this->setUsername($options['username']);
+ }
+
+ if (array_key_exists('password', $options)) {
+ $this->setPassword($options['password']);
+ }
+
+ $this->setUri($wsdl);
+ $this->setCachePath($options['cache_wsdl_path']);
+ }
+
+ public function init() {
+ $this->fetchWSDL();
+
+ $options['cache_wsdl'] = WSDL_CACHE_MEMORY;
+ $options['login'] = $this->_username;
+ $options['password'] = $this->_passwd;
+
+ parent::__construct($this->_cachePath, $options);
+ return $this;
+ }
+
+ public function setUri($uri) {
+ $this->_uri = $uri;
+ return $this;
+ }
+
+ public function getUri() {
+ return $this->_uri;
+ }
+
+ public function setCacheExpiry($cacheExpiry=86400) {
+ $this->_cacheExpiry = $cacheExpiry;
+ return $this;
+ }
+
+ public function getCacheExpiry() {
+ return $this->_cacheExpiry;
+ }
+
+ public function isCacheValid() {
+ $checkTime = time() - $this->getCacheExpiry();
+ return (file_exists($this->getCachePath()) && filemtime($this->getCachePath()) > $checkTime);
+ }
+
+ public function setUsername($username) {
+ $this->_username = (string) $username;
+ return $this;
+ }
+
+ public function setPassword($password) {
+ $this->_passwd = (string) $password;
+ return $this;
+ }
+
+ public function setCachePath($path) {
+ $folder = dirname($path);
+
+ if (!is_dir($folder)) {
+ throw new SSRS_Soap_Exception('WSDL cache path is not valid');
+ }
+
+ if (!is_writeable($folder)) {
+ throw new SSRS_Soap_Exception('WSDL cache path not writeable');
+ }
+
+ $this->_cachePath = $path;
+ return $this;
+ }
+
+ public function getCachePath() {
+ return $this->_cachePath;
+ }
+
+ public function cacheWSDL($fileContents) {
+ $result = file_put_contents($this->_cachePath, $fileContents);
+ if ($result) {
+ $this->setCacheWSDLPermission(0666 );
+ }
+ }
+
+ public function setCacheWSDLPermission($oct = 0666) {
+ @chmod($this->_cachePath, 0666);
+ }
+
+ public function getCacheWSDL() {
+ return file_get_contents($this->getCachePath());
+ }
+
+ public function fetchWSDL() {
+ if ($this->isCacheValid() === false) {
+ $wsdlContent = $this->_callCurl($this->_uri);
+ $this->cacheWSDL($wsdlContent);
+ }
+ }
+
+ public function __doRequest($data, $url, $action) {
+ $this->_lastRequest = (string) $data;
+ $this->_lastResponse = $this->_callCurl($url, $data, $action);
+ return $this->_lastResponse;
+ }
+
+ protected function _callCurl($url, $data = null, $action = null) {
+ $handle = curl_init();
+ curl_setopt($handle, CURLOPT_URL, $url);
+ curl_setopt($handle, CURLOPT_FAILONERROR, false);
+ curl_setopt($handle, CURLOPT_USERAGENT, 'PHP SOAP-NTLM Client');
+ curl_setopt($handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
+ curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($handle, CURLOPT_USERPWD, $this->_username . ':' . $this->_passwd);
+ curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
+ curl_setopt($handle, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
+
+ $headers = array(
+ 'Method: POST',
+ 'Connection: Keep-Alive',
+ 'User-Agent: PHP-SOAP-CURL',
+ 'Content-Type: text/xml; charset=utf-8',
+ 'Content-Length: ' . strlen($data),
+ 'SOAPAction: "' . $action . '"',
+ );
+ curl_setopt($handle, CURLOPT_HTTPHEADER, $headers);
+
+ if ($data !== null) {
+ curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
+ }
+
+ $response = curl_exec($handle);
+ if (empty($response)) {
+ throw new SSRS_Soap_Exception('CURL error: ' . curl_error($handle), curl_errno($handle));
+ }
+ curl_close($handle);
+
+ $this->_lastResponse = (string) $response;
+ return $response;
+ }
+
+ public function getLastRequest() {
+ return $this->_lastRequest;
+ }
+
+ public function getLastResponse() {
+ return $this->_lastResponse;
+ }
+
+} \ No newline at end of file