Skip to content

Commit cd42ebc

Browse files
authored
Add NOP identifier (#58)
* Add NOP identifier * Remove use of unused class
1 parent 897a940 commit cd42ebc

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ project at the moment is [tus](https://tus.io/).
4141
- [simple-uploader.js](#simple-uploader-js-driver)
4242
- [Identifiers](#identifiers)
4343
- [Session identifier](#session-identifier)
44+
- [NOP identifier](#nop-identifier)
4445
- [Contribution](#contribution)
4546
- [License](#license)
4647

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

201203
### Session identifier
202204

203-
This identifier uses the client session and the original file name to create an identifier for the upload file.
205+
This identifier uses the client session and, the original file name to create an identifier for the upload file.
206+
207+
### NOP identifier
208+
209+
This identifier uses the original file name to create an identifier for the upload file. This does not abstract the file
210+
identifier which can be useful for testing.
204211

205212
## Contribution
206213

src/Identifier/NopIdentifier.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace CodingSocks\ChunkUploader\Identifier;
4+
5+
class NopIdentifier extends Identifier
6+
{
7+
public function generateIdentifier(string $data): string
8+
{
9+
return $data;
10+
}
11+
}

src/IdentityManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace CodingSocks\ChunkUploader;
44

5+
use CodingSocks\ChunkUploader\Identifier\NopIdentifier;
56
use CodingSocks\ChunkUploader\Identifier\SessionIdentifier;
67
use Illuminate\Support\Manager;
78

@@ -12,6 +13,11 @@ public function createSessionDriver()
1213
return new SessionIdentifier();
1314
}
1415

16+
public function createNopDriver()
17+
{
18+
return new NopIdentifier();
19+
}
20+
1521
/**
1622
* Get the default driver name.
1723
*
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace CodingSocks\ChunkUploader\Tests\Identifier;
4+
5+
use CodingSocks\ChunkUploader\Identifier\NopIdentifier;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class NopIdentifierTest extends TestCase
9+
{
10+
/**
11+
* @var \CodingSocks\ChunkUploader\Identifier\SessionIdentifier
12+
*/
13+
private $identifier;
14+
15+
protected function setUp(): void
16+
{
17+
parent::setUp();
18+
19+
$this->identifier = new NopIdentifier();
20+
}
21+
22+
public function testGenerateIdentifier()
23+
{
24+
$identifier = $this->identifier->generateIdentifier('any_string');
25+
$this->assertEquals('any_string', $identifier);
26+
}
27+
28+
public function testUploadedFileIdentifierName()
29+
{
30+
$identifier = $this->identifier->generateFileIdentifier(200, 'any_filename.ext');
31+
$this->assertEquals('200_any_filename.ext', $identifier);
32+
}
33+
}

0 commit comments

Comments
 (0)