I am trying to call a 3rd party soap api and when i am creating an object for soapclient in my helper class its showing as class not found.
soapclient class.
class NTLMSoapClient extends SoapClient {
function __doRequest($request, $location, $action, $version, $one_way = 0) {
$headers = array(
'Method: POST',
'Connection: Keep-Alive',
'User-Agent: PHP-SOAP-CURL',
'Content-Type: text/xml; charset=utf-8',
'SOAPAction: "' . $action . '"',
);
$this->__last_request_headers = $headers;
$ch = curl_init($location);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($ch, CURLOPT_USERPWD, USERNAME . ':' . PASSWORD);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLINFO_HEADER_OUT, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
if(is_null($response)) {
$logger->info('ERP class_soap: '.curl_error($ch), null, 'soap.log');
}
$response = preg_replace( '/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\xFE\xFF|\xFF\xFE|\xEF\xBB\xBF)/', "", $response );
$errors = curl_error($ch);
$details = curl_getinfo($ch);
return $response;
}
function __getLastRequestHeaders() {
return implode("\n", $this->__last_request_headers) . "\n";
}
}
Am trying to create an object in helper class i.e. connect.php
<?php
namespace Curocarte\Erp\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\Module\Dir;
class Connect extends AbstractHelper
{
protected $_moduleReader;
protected $_helper;
protected $_dir;
// protected $_NTLMSoapClient;
public function __construct(
\Curocarte\Erp\Helper\Data $helper,
// \Curocarte\Erp\lib\NTLMSoapClient $NTLMSoapClient,
\Magento\Framework\Module\Dir\Reader $moduleReader,
\Magento\Framework\Filesystem\DirectoryList $dir,
\Magento\Framework\Webapi\Soap\ClientFactory $soapClientFactory,
array $data = []
) {
$this->_moduleReader = $moduleReader;
$this->_helper = $helper;
$this->_dir = $dir;
// $this->_NTLMSoapClient=$NTLMSoapClient;
$this->soapClientFactory = $soapClientFactory;
}
public function getConnection() {
try{
$path = $this->_moduleReader->getModuleDir('', 'Curocarte_Erp');
include_once $path . '/lib/class_soap.php';
// include_once $this->_dir->getRoot().'/library/class_soap.php'
set_time_limit( 300 );
$config = json_decode(file_get_contents($this->_dir->getRoot().'/config.json'), true);
$erpIndex = array_search('erp_'.$config[0]['mode'], $this->_helper->customArrayColumn($config, 'option'));
define('USERNAME', $config[$erpIndex]["username"]);
define('PASSWORD', $config[$erpIndex]["password"]);
stream_wrapper_unregister('http');
stream_wrapper_register('http', 'NTLMStream') or die("Failed to register protocol");
$faultString = "";
$url = $config[$erpIndex]["url"];
$client = new NTLMSoapClient($url, array('trace' => 1, 'soap_version' => SOAP_1_1, 'cache_wsdl' => WSDL_CACHE_NONE));
// $client = $this->_NTLMSoapClient($url, array('trace' => 1, 'soap_version' => SOAP_1_1, 'cache_wsdl' => WSDL_CACHE_NONE));
return $client;
}
catch (SoapFault $fault) {
$faultString = str_replace(chr(10), " ", $fault->faultstring);
$faultString = str_replace(chr(13), " ", $faultString);
$faultString = html_entity_decode($faultString);
}
}
}
NTLMSoapClient class is in class_soap.php which i have included
when i run am getting the error as
[2019-06-18 05:53:27] main.CRITICAL: Class Curocarte\Erp\lib\NTLMSoapClient does not exist {"exception":"[object] (ReflectionException(code: 0): Class Curocarte\Erp\lib\NTLMSoapClient does not exist at C:\xampp\htdocs\Magento\vendor\magento\framework\Code\Reader\ClassReader.php:37, ReflectionException(code: 0): Class Curocarte\Erp\lib\NTLMSoapClient does not exist at C:\xampp\htdocs\Magento\vendor\magento\framework\Code\Reader\ClassReader.php:29)"} []
Can anyone provide me some solution how am i supposed to overcome this issue. Thanks in advance.