Skip to content

Commit

Permalink
Implement file uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Dec 13, 2020
1 parent 21fac52 commit 7e970b9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/File/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
class Name
{
/**
* File name
*
* @var string
*/
protected $name;
Expand Down
61 changes: 61 additions & 0 deletions src/Files.php
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());
}
}

0 comments on commit 7e970b9

Please sign in to comment.