Skip to content

Commit

Permalink
Add new methods to Files class
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Dec 15, 2020
1 parent dfd4992 commit 0eec207
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Files
/**
* Files constructor
*
* @param FilesystemAdapter $adapter
* @param FilesystemAdapter $fileSystemAdapter
*/
public function __construct(FilesystemAdapter $fileSystemAdapter)
{
Expand Down Expand Up @@ -49,6 +49,17 @@ public function upload(string $filenamePath, string $contents): void
$this->fileSystemAdapter->write($filenamePath, $contents, new Config());
}

/**
* @param string $filenamePath
* @param string $contents
* @param FormatterInterface $formatter
* @throws FilesystemException
*/
public function uploadFormatted(string $filenamePath, string $contents, FormatterInterface $formatter): void
{
$this->upload($this->makeFormattedPath($filenamePath, $formatter), $contents);
}

/**
* @param string $filenamePath
* @param $resource
Expand All @@ -58,4 +69,31 @@ public function uploadStream(string $filenamePath, $resource): void
{
$this->fileSystemAdapter->writeStream($filenamePath, $resource, new Config());
}

/**
* @param string $filenamePath
* @param $resource
* @param FormatterInterface $formatter
* @throws FilesystemException
*/
public function uploadStreamFormatted(string $filenamePath, $resource, FormatterInterface $formatter): void
{
$this->uploadStream($this->makeFormattedPath($filenamePath, $formatter), $resource);
}

/**
* @param string $filenamePath
* @param FormatterInterface $formatter
* @return string
*/
private function makeFormattedPath(string $filenamePath, FormatterInterface $formatter): string
{
$pathParts = explode(DIRECTORY_SEPARATOR, $filenamePath);
$pathOnly = array_pop($pathParts);

$filename = end($pathParts);
$filename = $this->setFormattedName($filename, $formatter);

return $pathOnly . DIRECTORY_SEPARATOR . $filename;
}
}

0 comments on commit 0eec207

Please sign in to comment.