Support attachments

This commit is contained in:
Dan Jones 2022-09-10 22:52:40 -05:00
commit 77cf08260a
2 changed files with 68 additions and 3 deletions

View file

@ -13,6 +13,8 @@ class Map
protected string $path;
/** @var Stream[] */
protected array $streams = [];
/** @var Attachment[] */
protected array $attachments = [];
/** @var AbstractProgressListener[] */
protected array $listeners = [];
@ -35,9 +37,8 @@ class Map
return $this;
}
public function stream(callable $callback = null): Stream|static
protected function doStream(Stream $stream, callable $callback = null): Stream|static
{
$stream = new Stream($this);
if (!$callback) {
return $stream;
}
@ -48,8 +49,24 @@ class Map
return $this;
}
public function stream(callable $callback = null): Stream|static
{
return $this->doStream(new Stream($this), $callback);
}
public function attach(string $file = '', callable $callback = null): Attachment|static
{
return $this->doStream(new Attachment($this, $file), $callback);
}
public function saveStream(Stream $stream): static
{
if ($stream instanceof Attachment){
$this->attachments[] = $stream;
return $this;
}
$this->streams[] = $stream;
$format = $stream->getCodec();
if ($format instanceof ProgressableInterface) {
@ -72,7 +89,9 @@ class Map
public function buildCommand(): array
{
$commands = [];
foreach ($this->streams as $idx => $stream) {
$streams = $this->streams;
array_push($streams, ...$this->attachments);
foreach ($streams as $idx => $stream) {
array_push($commands, ...$stream->buildCommand($idx));
}
foreach ($this->metadata as $k => $v) {