1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace drupol\phpvfs\Node; |
6
|
|
|
|
7
|
|
|
use drupol\phpvfs\Utils\Path; |
8
|
|
|
|
9
|
|
|
class Directory extends Vfs implements DirectoryInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param string $id |
13
|
|
|
* |
14
|
|
|
* @return null|\drupol\phpvfs\Node\DirectoryInterface|\drupol\phpvfs\Node\FileInterface|\drupol\phpvfs\Node\VfsInterface |
15
|
|
|
*/ |
16
|
1 |
|
public function containsAttributeId(string $id): ?VfsInterface |
17
|
|
|
{ |
18
|
|
|
/** @var \drupol\phpvfs\Node\VfsInterface $child */ |
19
|
1 |
|
foreach ($this->children() as $child) { |
20
|
1 |
|
if ($child->getAttribute('id') === $id) { |
|
|
|
|
21
|
1 |
|
return $child; |
|
|
|
|
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
1 |
|
return null; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param string $id |
30
|
|
|
* @param array $attributes |
31
|
|
|
* |
32
|
|
|
* @throws \Exception |
33
|
|
|
* |
34
|
|
|
* @return \drupol\phpvfs\Node\Directory |
35
|
|
|
*/ |
36
|
2 |
|
public static function create(string $id, array $attributes = []) |
37
|
|
|
{ |
38
|
2 |
|
$path = Path::fromString($id); |
39
|
|
|
|
40
|
2 |
|
if (\DIRECTORY_SEPARATOR !== $id && false !== \strpos($id, \DIRECTORY_SEPARATOR)) { |
41
|
2 |
|
if ($path->isAbsolute()) { |
42
|
1 |
|
$firstPart = \DIRECTORY_SEPARATOR; |
43
|
|
|
} else { |
44
|
1 |
|
$firstPart = $path->shift(); |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
$root = self::create($firstPart, $attributes); |
48
|
|
|
|
49
|
2 |
|
foreach ($path->getIterator() as $pathPart) { |
50
|
2 |
|
$child = new self(['id' => $pathPart]); |
51
|
2 |
|
$root->add($child); |
52
|
2 |
|
$root = $child; |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
return $root; |
56
|
|
|
} |
57
|
|
|
|
58
|
2 |
|
$attributes = ['id' => $id] + $attributes; |
59
|
|
|
|
60
|
2 |
|
return new self($attributes); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param string $id |
65
|
|
|
* |
66
|
|
|
* @throws \Exception |
67
|
|
|
* |
68
|
|
|
* @return \drupol\phptree\Node\NodeInterface|\drupol\phpvfs\Node\DirectoryInterface |
69
|
|
|
*/ |
70
|
2 |
|
public function mkdir(string $id) |
71
|
|
|
{ |
72
|
2 |
|
$dir = self::create($id); |
73
|
|
|
|
74
|
2 |
|
return $this->add($dir->root()); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.