Skip to content

Commit

Permalink
Drop removeExtension function
Browse files Browse the repository at this point in the history
This is nonsense
  • Loading branch information
williamdes committed Dec 7, 2023
1 parent e2c41ad commit a09ba7a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ $resumable->process();

```

## More ##
### Setting custom filename(s) ###
## More

### Setting custom filename(s)

```php
// custom filename (extension from original file will be magically removed and re-appended)
$originalName = $resumable->getOriginalFilename(Resumable::WITHOUT_EXTENSION); // will give you "original Name" instead of "original Name.png"
// NOTE: this fork removed the getOriginalFilename() parameter to return without an extension.
$originalName = $resumable->getOriginalFilename(); // will give you the original end-user file-name

// do some slugification or whatever you need...
$slugifiedname = my_slugify($originalName); // this is up to you, it as ported out of the library.
Expand Down
35 changes: 9 additions & 26 deletions src/Resumable.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ class Resumable
'totalSize' => 'totalSize',
];

public const WITHOUT_EXTENSION = true;

public function __construct(
ServerRequestInterface $request,
ResponseInterface $response,
Expand Down Expand Up @@ -129,8 +127,8 @@ public function preProcess(): void
{
if (!empty($this->resumableParams())) {
if (!empty($this->request->getUploadedFiles())) {
$this->extension = $this->findExtension($this->resumableParam('filename'));
$this->originalFilename = $this->resumableParam('filename');
$this->extension = $this->findExtension($this->originalFilename);
$this->log(
'Defined extension',
[
Expand Down Expand Up @@ -195,12 +193,8 @@ public function getFilename(): string
*
* @return string Final filename
*/
public function getOriginalFilename(bool $withoutExtension = false): string
public function getOriginalFilename(): string
{
if ($withoutExtension === static::WITHOUT_EXTENSION) {
return $this->removeExtension($this->originalFilename);
}

return $this->originalFilename;
}

Expand Down Expand Up @@ -233,12 +227,16 @@ public function getExtension(): string
*/
private function createSafeFilename(string $filename, string $originalFilename): string
{
$filename = $this->removeExtension($filename);
$extension = $this->findExtension($originalFilename);

return sprintf('%s.%s', $filename, $extension);
}

private function findExtension(string $filename): string
{
$parts = explode('.', basename($filename));

return end($parts);
}

/**
* @return ResponseInterface
* @see https://github.com/23/resumable.js/blob/v1.1.0/README.md#handling-get-or-test-requests
Expand Down Expand Up @@ -467,21 +465,6 @@ private function log(string $msg, array $ctx = []): void
}
}

private function findExtension(string $filename): string
{
$parts = explode('.', basename($filename));

return end($parts);
}

private function removeExtension(string $filename): string
{
$ext = $this->findExtension($filename);

// remove extension from filename if any
return str_replace(sprintf('.%s', $ext), '', $filename);
}

public function setDebug(bool $debug): void
{
$this->debug = $debug;
Expand Down

0 comments on commit a09ba7a

Please sign in to comment.