Skip to content
Merged
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
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ project at the moment is [tus](https://tus.io/).
- [simple-uploader.js](#simple-uploader-js-driver)
- [Identifiers](#identifiers)
- [Session identifier](#session-identifier)
- [NOP identifier](#nop-identifier)
- [Contribution](#contribution)
- [License](#license)

Expand Down Expand Up @@ -197,10 +198,16 @@ file for a specific client. Without the identifier collisions can happen.
Service | Driver name
------------------------------------------|-------------
[Session identifier](#session-identifier) | `session`
[NOP identifier](#nop-identifier) | `nop`

### Session identifier

This identifier uses the client session and the original file name to create an identifier for the upload file.
This identifier uses the client session and, the original file name to create an identifier for the upload file.

### NOP identifier

This identifier uses the original file name to create an identifier for the upload file. This does not abstract the file
identifier which can be useful for testing.

## Contribution

Expand Down
11 changes: 11 additions & 0 deletions src/Identifier/NopIdentifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace CodingSocks\ChunkUploader\Identifier;

class NopIdentifier extends Identifier
{
public function generateIdentifier(string $data): string
{
return $data;
}
}
6 changes: 6 additions & 0 deletions src/IdentityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CodingSocks\ChunkUploader;

use CodingSocks\ChunkUploader\Identifier\NopIdentifier;
use CodingSocks\ChunkUploader\Identifier\SessionIdentifier;
use Illuminate\Support\Manager;

Expand All @@ -12,6 +13,11 @@ public function createSessionDriver()
return new SessionIdentifier();
}

public function createNopDriver()
{
return new NopIdentifier();
}

/**
* Get the default driver name.
*
Expand Down
33 changes: 33 additions & 0 deletions tests/Identifier/NopIdentifierTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace CodingSocks\ChunkUploader\Tests\Identifier;

use CodingSocks\ChunkUploader\Identifier\NopIdentifier;
use PHPUnit\Framework\TestCase;

class NopIdentifierTest extends TestCase
{
/**
* @var \CodingSocks\ChunkUploader\Identifier\SessionIdentifier
*/
private $identifier;

protected function setUp(): void
{
parent::setUp();

$this->identifier = new NopIdentifier();
}

public function testGenerateIdentifier()
{
$identifier = $this->identifier->generateIdentifier('any_string');
$this->assertEquals('any_string', $identifier);
}

public function testUploadedFileIdentifierName()
{
$identifier = $this->identifier->generateFileIdentifier(200, 'any_filename.ext');
$this->assertEquals('200_any_filename.ext', $identifier);
}
}