-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAbstractCollection.php
More file actions
40 lines (32 loc) · 993 Bytes
/
AbstractCollection.php
File metadata and controls
40 lines (32 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace PHPSu\ShellCommandBuilder\Collection;
use PHPSu\ShellCommandBuilder\Exception\ShellBuilderException;
use PHPSu\ShellCommandBuilder\ShellInterface;
/**
* @internal
* @psalm-internal PHPSu\ShellCommandBuilder
*/
abstract class AbstractCollection implements ShellInterface
{
protected CollectionTuple|null $tuple = null;
protected function toTuple(ShellInterface|string $command, string $join): CollectionTuple
{
return CollectionTuple::create($command, $join);
}
/**
* @return array<ShellInterface|string|array<mixed>>
* @throws ShellBuilderException
*/
public function __toArray(): array
{
if ($this->tuple === null) {
throw new ShellBuilderException('Tuple has not been set yet - collection cannot be parsed to array');
}
return $this->tuple->__toArray();
}
public function __toString(): string
{
return (string)$this->tuple;
}
}