Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Recca Tsai committed Oct 23, 2016
1 parent 69a6455 commit 8b28285
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
14 changes: 8 additions & 6 deletions src/ApiAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Recca0120\Upload;

use Closure;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Arr;
use Recca0120\Upload\Apis\Api;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -70,7 +69,7 @@ public function receive($name, Closure $closure)
$startOffset = $this->api->getStartOffset();
$partialName = $path.$this->api->getPartialName();
$filesystem->updateStream($partialName, $resource, [
'startOffset' => $startOffset
'startOffset' => $startOffset,
]);

if ($this->api->isCompleted() === false) {
Expand All @@ -94,9 +93,10 @@ public function receive($name, Closure $closure)
return $response;
}

protected function createUploadedFile($path, $originalName, $mimeType = null, $size = null) {
protected function createUploadedFile($path, $originalName, $mimeType = null, $size = null)
{
$class = class_exists('Illuminate\Http\UploadedFile') ?
'Illuminate\Http\UploadedFile':
'Illuminate\Http\UploadedFile' :
'Symfony\Component\HttpFoundation\File\UploadedFile';

return new $class($path, $originalName, $mimeType, $size, UPLOAD_ERR_OK, true);
Expand Down Expand Up @@ -126,7 +126,8 @@ public function removeOldData($path, $maxFileAge = 600)
*
* @return string
*/
public function getPath() {
public function getPath()
{
$filesystem = $this->getFilsystem();
$diskPath = Arr::get($this->config, 'path');
if ($filesystem->isDirectory($diskPath) === false) {
Expand All @@ -136,7 +137,8 @@ public function getPath() {
return $diskPath;
}

public function getFilsystem() {
public function getFilsystem()
{
return $this->filesystem;
}
}
3 changes: 2 additions & 1 deletion src/Apis/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ abstract public function getResourceName();
*
* @return resource
*/
public function getResource() {
public function getResource()
{
return fopen($this->getResourceName(), 'rb');
}
}
4 changes: 2 additions & 2 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function createFileapiDriver()

return $this->app->make(ApiAdapter::class, [
$this->app->make(FileAPI::class),
'config' => $config
'config' => $config,
]);
}

Expand All @@ -44,7 +44,7 @@ protected function createPluploadDriver()

return $this->app->make(ApiAdapter::class, [
$this->app->make(Plupload::class),
'config' => $config
'config' => $config,
]);
}
}
5 changes: 3 additions & 2 deletions tests/ApiAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function test_receive_chunked_file()
$api
->shouldReceive('setName')->with($name)->once()->andReturn(false)
->shouldReceive('hasChunks')->once()->andReturn(true)
->shouldReceive('getResource')->once()->andReturnUsing(function() {
->shouldReceive('getResource')->once()->andReturnUsing(function () {
return fopen(__FILE__, 'rb');
})
->shouldReceive('getStartOffset')->once()->andReturn(10)
Expand Down Expand Up @@ -141,7 +141,7 @@ public function test_receive_chunked_file_completed()
$api
->shouldReceive('setName')->with($name)->once()->andReturn(false)
->shouldReceive('hasChunks')->once()->andReturn(true)
->shouldReceive('getResource')->once()->andReturnUsing(function() {
->shouldReceive('getResource')->once()->andReturnUsing(function () {
return fopen(__FILE__, 'rb');
})
->shouldReceive('getStartOffset')->once()->andReturn(10)
Expand All @@ -163,6 +163,7 @@ public function test_receive_chunked_file_completed()
} else {
$this->assertInstanceOf('Symfony\Component\HttpFoundation\File\UploadedFile', $file);
}

return $response;
});
}
Expand Down
3 changes: 2 additions & 1 deletion tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function test_service_provider()
}
}

function storage_path() {
function storage_path()
{
return __DIR__;
}

0 comments on commit 8b28285

Please sign in to comment.