Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SoapBase.php #18

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "nfephp-org/sped-nfse-ginfes",
"name": "jvkrypton/sped-nfse-ginfes",
"type": "library",
"description": "API para geração e comunicação de RPS e NFSe no padão Ginfes.",
"keywords": ["nfe","nfse","sped","nfephp"],
"homepage": "https://github.com/nfephp-org/sped-nfse-ginfes",
"homepage": "https://github.com/jvkrypton/sped-nfse-ginfes",
"license": ["LGPL-3.0-or-later", "GPL-3.0-or-later", "MIT"],
"authors": [
{
Expand All @@ -14,13 +14,13 @@
},
{
"name": "Comunidade NFePHP",
"homepage": "https://github.com/nfephp-org/sped-nfe/graphs/contributors"
"homepage": "https://github.com/jvkrypton/sped-nfe/graphs/contributors"
}
],
"require": {
"php" : ">= 7.1",
"nfephp-org/sped-common" : "^5.0",
"justinrainbow/json-schema": "^5.2",
"league/flysystem": "^3.23",
"ext-zlib": "*",
"ext-dom": "*",
"ext-openssl": "*",
Expand Down
53 changes: 30 additions & 23 deletions src/Common/Soap/SoapBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
use NFePHP\Common\Exception\RuntimeException;
use NFePHP\Common\Strings;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Local\LocalFilesystemAdapter;
use Psr\Log\LoggerInterface;
use Illuminate\Support\Facades\File;

abstract class SoapBase implements SoapInterface
{
Expand Down Expand Up @@ -99,7 +100,7 @@ abstract class SoapBase implements SoapInterface
*/
protected $disableCertValidation = false;
/**
* @var \League\Flysystem\Adapter\Local
* @var \League\Flysystem\Local\LocalFilesystemAdapter;
*/
protected $adapter;
/**
Expand Down Expand Up @@ -158,9 +159,9 @@ public function __construct(
) {
$this->logger = $logger;
$this->certificate = $this->checkCertValidity($certificate);
$this->setTemporaryFolder(sys_get_temp_dir() . '/sped/');
$this->setTemporaryFolder(storage_path('nfe') . '/');
}

/**
* Check if certificate is valid
* @param Certificate $certificate
Expand All @@ -181,7 +182,7 @@ private function checkCertValidity(Certificate $certificate = null)
}
return $certificate;
}

/**
* Destructor
* Clean temporary files
Expand All @@ -190,7 +191,7 @@ public function __destruct()
{
$this->removeTemporarilyFiles();
}

/**
* Disables the security checking of host and peer certificates
* @param bool $flag
Expand All @@ -200,7 +201,7 @@ public function disableSecurity($flag = false)
$this->disablesec = $flag;
return $this->disablesec;
}

/**
* ONlY for tests
* @param bool $flag
Expand All @@ -222,7 +223,7 @@ public function loadCA($capath)
$this->casefaz = $capath;
}
}

/**
* Set option to encript private key before save in filesystem
* for an additional layer of protection
Expand All @@ -233,7 +234,7 @@ public function setEncriptPrivateKey($encript = true)
{
return $this->encriptPrivateKey = $encript;
}

/**
* Set another temporayfolder for saving certificates for SOAP utilization
* @param string $folderRealPath
Expand All @@ -243,15 +244,15 @@ public function setTemporaryFolder($folderRealPath)
$this->tempdir = $folderRealPath;
$this->setLocalFolder($folderRealPath);
}

/**
* Set Local folder for flysystem
* @param string $folder
*/
protected function setLocalFolder($folder = '')
{
$this->adapter = new Local($folder);
$this->filesystem = new Filesystem($this->adapter);
//$this->adapter = new LocalFilesystemAdapter($folder);
$this->filesystem = new \NFePHP\Common\Files($folder);
}

/**
Expand All @@ -263,7 +264,7 @@ public function setDebugMode($value = false)
{
return $this->debugmode = $value;
}

/**
* Set certificate class for SSL comunications
* @param Certificate $certificate
Expand All @@ -272,7 +273,7 @@ public function loadCertificate(Certificate $certificate)
{
$this->certificate = $this->checkCertValidity($certificate);
}

/**
* Set logger class
* @param LoggerInterface $logger
Expand All @@ -281,7 +282,7 @@ public function loadLogger(LoggerInterface $logger)
{
return $this->logger = $logger;
}

/**
* Set timeout for communication
* @param int $timesecs
Expand All @@ -290,7 +291,7 @@ public function timeout($timesecs)
{
return $this->soaptimeout = $timesecs;
}

/**
* Set security protocol
* @param int $protocol
Expand All @@ -300,7 +301,7 @@ public function protocol($protocol = self::SSL_DEFAULT)
{
return $this->soapprotocol = $protocol;
}

/**
* Set prefixes
* @param array $prefixes
Expand All @@ -310,7 +311,7 @@ public function setSoapPrefix($prefixes)
{
return $this->prefixes = $prefixes;
}

/**
* Set proxy parameters
* @param string $ip
Expand All @@ -325,7 +326,7 @@ public function proxy($ip, $port, $user, $password)
$this->proxyUser = $user;
$this->proxyPass = $password;
}

/**
* Send message to webservice
*/
Expand All @@ -336,7 +337,7 @@ abstract public function send(
$envelope,
$parameters
);

/**
* Mount soap envelope
* @param string $request
Expand Down Expand Up @@ -372,7 +373,7 @@ protected function makeEnvelopeSoap(
. "</$prefix:Envelope>";
return $envelope;
}

/**
* Temporarily saves the certificate keys for use cURL or SoapClient
*/
Expand All @@ -383,10 +384,12 @@ public function saveTemporarilyKeyFiles()
'Certificate not found.'
);
}

$this->certsdir = $this->certificate->getCnpj() . '/certs/';
$this->prifile = $this->certsdir. Strings::randomString(10).'.pem';
$this->pubfile = $this->certsdir . Strings::randomString(10).'.pem';
$this->certfile = $this->certsdir . Strings::randomString(10).'.pem';

$ret = true;
$private = $this->certificate->privateKey;
if ($this->encriptPrivateKey) {
Expand All @@ -401,10 +404,12 @@ public function saveTemporarilyKeyFiles()
$this->temppass
);
}

$ret &= $this->filesystem->put(
$this->prifile,
$private
);

$ret &= $this->filesystem->put(
$this->pubfile,
$this->certificate->publicKey
Expand All @@ -418,8 +423,10 @@ public function saveTemporarilyKeyFiles()
'Unable to save temporary key files in folder.'
);
}

$this->removeTemporarilyFiles();
}

/**
* Delete all files in folder
*/
Expand Down Expand Up @@ -457,7 +464,7 @@ public function removeTemporarilyFiles()
}
}
}

/**
* Save request envelope and response for debug reasons
* @param string $operation
Expand Down