-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
class Name | ||
{ | ||
/** | ||
* File name | ||
* | ||
* @var string | ||
*/ | ||
protected $name; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phlexus\Files; | ||
|
||
use League\Flysystem\Config; | ||
use League\Flysystem\FilesystemAdapter; | ||
use League\Flysystem\FilesystemException; | ||
use Phlexus\Files\File\Name; | ||
use Phlexus\Files\Formatter\FormatterInterface; | ||
|
||
class Files | ||
{ | ||
protected $fileSystemAdapter; | ||
|
||
/** | ||
* Files constructor | ||
* | ||
* @param FilesystemAdapter $adapter | ||
*/ | ||
public function __construct(FilesystemAdapter $fileSystemAdapter) | ||
{ | ||
$this->fileSystemAdapter = $fileSystemAdapter; | ||
} | ||
|
||
/** | ||
* @param string $filename | ||
* @param FormatterInterface|null $formatter | ||
* @return string | ||
*/ | ||
public function setFormattedName(string $filename, ?FormatterInterface $formatter = null): string | ||
{ | ||
$name = new Name($filename); | ||
if ($formatter !== null) { | ||
$name->setFormatter($formatter); | ||
} | ||
|
||
return $name->getFormattedName(); | ||
} | ||
|
||
/** | ||
* @param string $filenamePath | ||
* @param string $contents | ||
* @throws FilesystemException | ||
*/ | ||
public function upload(string $filenamePath, string $contents): void | ||
{ | ||
$this->fileSystemAdapter->write($filenamePath, $contents, new Config()); | ||
} | ||
|
||
/** | ||
* @param string $filenamePath | ||
* @param $resource | ||
* @throws FilesystemException | ||
*/ | ||
public function uploadStream(string $filenamePath, $resource): void | ||
{ | ||
$this->fileSystemAdapter->writeStream($filenamePath, $resource, new Config()); | ||
} | ||
} |