-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectoryLink.php
86 lines (76 loc) · 2.39 KB
/
DirectoryLink.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace Aternos\IO\System\Link;
use Aternos\IO\Exception\DeleteException;
use Aternos\IO\Exception\GetTargetException;
use Aternos\IO\Exception\SetTargetException;
use Aternos\IO\Interfaces\Features\GetPathInterface;
use Aternos\IO\Interfaces\Types\DirectoryInterface;
use Aternos\IO\Interfaces\Types\Link\DirectoryLinkInterface;
use Aternos\IO\System\Directory\Directory;
use Generator;
/**
* Class DirectoryLink
*
* Filesystem link to a directory
*
* @package Aternos\IO\System\Link
*/
class DirectoryLink extends Link implements DirectoryLinkInterface
{
/**
* @inheritDoc
* @throws GetTargetException
*/
public function getTarget(): DirectoryInterface
{
if ($this->target) {
return $this->target;
}
$targetPath = $this->getTargetPath();
if (!$this->targetExists()) {
return $this->target = new Directory($targetPath);
}
$target = static::getIOElementFromPath($targetPath);
if (!$target instanceof DirectoryInterface) {
throw new GetTargetException("Could not get directory link target because link target is not a directory (" . $this->path . ")", $this);
}
return $this->target = $target;
}
/**
* @inheritDoc
* @throws SetTargetException
* @throws DeleteException
*/
public function setTarget(GetPathInterface $target): static
{
if (!$target instanceof DirectoryInterface) {
throw new SetTargetException("Could not set directory link target because target is not a directory (" . $this->path . " -> " . $target->getPath() . ")", $this);
}
return parent::setTarget($target);
}
/**
* @inheritDoc
* @throws GetTargetException
*/
public function create(): static
{
$this->getTarget()->create();
return $this;
}
/**
* @inheritDoc
* @throws GetTargetException
*/
public function getChildren(bool $allowOutsideLinks = false): Generator
{
yield from $this->getTarget()->getChildren($allowOutsideLinks);
}
/**
* @inheritDoc
* @throws GetTargetException
*/
public function getChildrenRecursive(bool $allowOutsideLinks = false, bool $followLinks = true, int $currentDepth = 0): Generator
{
yield from $this->getTarget()->getChildrenRecursive($allowOutsideLinks, $followLinks, $currentDepth);
}
}