Skip to content

Commit

Permalink
Bug stream context (#2)
Browse files Browse the repository at this point in the history
Check is_resource before requesting stream_context_get_options
  • Loading branch information
sebastianblum authored May 14, 2018
1 parent 17784cc commit d40cf89
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
24 changes: 24 additions & 0 deletions Tests/Visionline/Crm/WebApi/FileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Tests\Visionline\Crm\WebApi;

use PHPUnit\Framework\TestCase;
use Visionline\Crm\WebApi\Connection;
use Visionline\Crm\WebApi\WebApi;

class FileTest extends TestCase
{
public function testGetFileWithDefaultStreamContext()
{
$connection = new Connection('app2.visionline.at', 5000, 'testUser', 'testPassword');

$webApi = new WebApi('https://app2.visionline.at:8443/WebApi/WebApi.asmx?WSDL', $connection, [
'debug' => true,
]);

$this->expectException(\Exception::class);
$this->expectExceptionMessage('Could not get file extension from https://app2.visionline.at:8443/WebApi/GetFile.ashx?host=app2.visionline.at&port=5000&username=testUser&password=testPassword&id=1');

$webApi->getFile(1);
}
}
8 changes: 4 additions & 4 deletions Visionline/Crm/WebApi/WebApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ public function getFile($documents, $width = null, $height = null, $resizeMode =
{
$op = new FileGetOperation($this, $this->getFileUrl, $this->connection, $this->bufferSize);

return $op->exec($documents, \stream_context_get_options($this->stream_context), $width, $height, $resizeMode);
return $op->exec($documents, \is_resource($this->stream_context) ? \stream_context_get_options($this->stream_context) : [], $width, $height, $resizeMode);
}

/**
Expand All @@ -1372,7 +1372,7 @@ public function saveFile($document, $directory, $forceDownload = false, $width =
{
$op = new FileSaveOperation($this, $this->getFileUrl, $this->connection, $this->bufferSize, $directory, $forceDownload);

return $op->exec($document, \stream_context_get_options($this->stream_context), $width, $height, $resizeMode);
return $op->exec($document, \is_resource($this->stream_context) ? \stream_context_get_options($this->stream_context) : [], $width, $height, $resizeMode);
}

/**
Expand All @@ -1391,7 +1391,7 @@ public function saveFile($document, $directory, $forceDownload = false, $width =
public function saveFiles($documents, $directory, $forceDownload = false, $width = null, $height = null, $resizeMode = null)
{
$op = new FileSaveOperation($this, $this->getFileUrl, $this->connection, $this->bufferSize, $directory, $forceDownload);
$result = $op->execMultiple($documents, \stream_context_get_options($this->stream_context), $width, $height, $resizeMode);
$result = $op->execMultiple($documents, \is_resource($this->stream_context) ? \stream_context_get_options($this->stream_context) : [], $width, $height, $resizeMode);
$this->debug('saveFiles: result = ', $result);

return $result;
Expand All @@ -1413,7 +1413,7 @@ public function saveFiles($documents, $directory, $forceDownload = false, $width
public function passthruFile($document, $sendHeaders = false, $width = null, $height = null, $resizeMode = null, $attachment = false)
{
$op = new FilePassthruOperation($this, $this->getFileUrl, $this->connection, $this->bufferSize, $sendHeaders, $attachment);
$op->exec($document, \stream_context_get_options($this->stream_context), $width, $height, $resizeMode);
$op->exec($document, \is_resource($this->stream_context) ? \stream_context_get_options($this->stream_context) : [], $width, $height, $resizeMode);
}

/**
Expand Down

0 comments on commit d40cf89

Please sign in to comment.