1 | <?php |
||
21 | class FileNode extends File implements FileNodeInterface, FormatAwareInterface |
||
22 | { |
||
23 | use FormatAwareTrait; |
||
24 | |||
25 | /** |
||
26 | * @return string |
||
27 | */ |
||
28 | 14 | public function __toString() |
|
29 | { |
||
30 | 14 | return $this->getPath(); |
|
31 | 1 | } |
|
32 | |||
33 | /** |
||
34 | * @return mixed |
||
35 | */ |
||
36 | 10 | public function getDirectory() |
|
40 | |||
41 | /** |
||
42 | * @return string |
||
43 | */ |
||
44 | 18 | public function getFilename() |
|
48 | |||
49 | /** |
||
50 | * Returns the contents of the file as an array. |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | 21 | public function getContents() |
|
62 | |||
63 | /** |
||
64 | * @param string|null $newPath |
||
65 | * |
||
66 | * @return static |
||
67 | * @throws CopyFailedException When it is unable to copy the file |
||
68 | */ |
||
69 | 4 | public function copy($newPath = null) |
|
70 | { |
||
71 | 4 | if (is_null($newPath)) { |
|
72 | 1 | $newPath = $this->path . '-copy'; |
|
73 | 1 | } |
|
74 | |||
75 | 4 | if (@$this->filesystem->copy($this->path, $newPath)) { |
|
76 | 3 | return $this->getClone()->setPath($newPath); |
|
77 | } else { |
||
78 | 1 | $lastError = error_get_last(); |
|
79 | 1 | throw new CopyFailedException($this, $newPath, $lastError['message']); |
|
80 | } |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Return a clone of this object |
||
85 | * |
||
86 | * @return static |
||
87 | */ |
||
88 | 56 | public function getClone() |
|
92 | |||
93 | /** |
||
94 | * Clone sub objects |
||
95 | */ |
||
96 | 56 | public function __clone() |
|
102 | } |
||
103 |