Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 17 additions & 72 deletions src/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,51 @@

namespace TsfCorp\Email;

class Attachment implements \JsonSerializable
{
/**
* @var null|string
*/
private $path = null;
/**
* @var null|string
*/
private $disk = null;
/**
* @var null|string
*/
private $name = null;

/**
* @param $path
* @param $name
* @return static
*/
public static function path($path, $name = null)
{
return (new static())->setPath($path, $name);
}
use JsonSerializable;

/**
* @param $disk
* @return static
*/
public static function disk($disk)
{
return (new static())->setDisk($disk);
}
class Attachment implements JsonSerializable
{
private string $path;
private ?string $name;
private string $disk;

/**
* @param $path
* @param $name
* @return static
*/
public function setPath($path, $name = null)
public function __construct(string $path, ?string $name = null, ?string $disk = 'local')
{
$this->path = $path;
$this->name = $name;

return $this;
$this->disk = $disk;
}

/**
* @param $disk
* @return static
*/
public function setDisk($disk)
public function setName(string $name): static
{
$this->disk = $disk;
$this->name = $name;

return $this;
}

/**
* @param $name
* @return static
*/
public function setName($name)
public function setDisk(string $disk): static
{
$this->name = $name;
$this->disk = $disk;

return $this;
}

/**
* @return string|null
*/
public function getPath()
public function getPath(): ?string
{
return $this->path;
}

/**
* @return string
*/
public function getDisk()
public function getDisk(): string
{
return $this->disk ?? 'local';
}

/**
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name ?? basename($this->path);
}

/**
* @return array
*/
public function toArray()
public function toArray(): array
{
return [
'path' => $this->getPath(),
Expand All @@ -107,10 +55,7 @@ public function toArray()
];
}

/**
* @return array
*/
public function jsonSerialize()
public function jsonSerialize(): array
{
return $this->toArray();
}
Expand Down
Loading