Skip to content

Commit

Permalink
Actualizado el método stream_context, opciones predeterminadas agrupadas
Browse files Browse the repository at this point in the history
Todas las opciones predeterminadas se han agrupado y se ha actualizado el método stream_context ().

Ahora es posible pasar en las opciones parámetros específicos del stream_context como un array, pasarle un stream_context propio o anular las opciones por defecto del stream_context.
  • Loading branch information
alphp committed May 5, 2021
1 parent dce47b4 commit 1131c12
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fawno/aeat",
"version": "1.0.3",
"version": "1.0.4",
"description": "Clases para los servicios web de la AEAT",
"license": "MIT",
"authors": [
Expand Down
42 changes: 30 additions & 12 deletions src/wsdlVNif.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,44 @@ class wsdlVNif extends SoapClient {
protected $location = 'https://www1.agenciatributaria.gob.es/wlpl/BURT-JDIT/ws/VNifV2SOAP';

public function __construct ($local_cert, $passphrase, $options = [], $ssl_verifypeer = true) {
$options['local_cert'] = $local_cert;
$options['passphrase'] = $passphrase;
if (empty($options['stream_context'])) {
$options['stream_context'] = $this->stream_context($ssl_verifypeer);
}
$options += [
'local_cert' => $local_cert,
'passphrase' => $passphrase,
'stream_context' => [
'http' => [
'user_agent' => 'PHPSoapClient',
],
'ssl' => [
'ciphers' => 'DEFAULT@SECLEVEL=1',
],
],
];

$options['stream_context'] = $this->stream_context($options['stream_context'], $ssl_verifypeer);

return parent::__construct($this->wsdl, $options);
}

protected function stream_context ($ssl_verifypeer = true, $options = []) {
$options['http']['user_agent'] = 'PHPSoapClient';
$options['ssl']['ciphers'] = 'DEFAULT@SECLEVEL=1';
protected function stream_context ($options = [], $ssl_verifypeer = true) {
switch (gettype($options)) {
case 'array':
$context = stream_context_create($options);
break;
case 'resource':
$context = $options;
}

if (!$ssl_verifypeer) {
$options['ssl']['verify_peer'] = false;
$options['ssl']['verify_peer_name'] = false;
$options['ssl']['allow_self_signed'] = true;
stream_context_set_option($context, [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true,
],
]);
}

return stream_context_create($options);
return $context;
}

public function __doRequest ($request, $location, $action, $version, $one_way = 0) {
Expand Down

0 comments on commit 1131c12

Please sign in to comment.