1 | <?php |
||
10 | class FileNode extends File implements FileNodeInterface, FormatAwareInterface |
||
11 | { |
||
12 | use FormatAwareTrait; |
||
13 | |||
14 | /** |
||
15 | * @return string |
||
16 | */ |
||
17 | 13 | public function __toString() |
|
21 | |||
22 | /** |
||
23 | * @return mixed |
||
24 | */ |
||
25 | 11 | public function getDirectory() |
|
29 | |||
30 | /** |
||
31 | * @return string |
||
32 | */ |
||
33 | 18 | public function getFilename() |
|
37 | |||
38 | /** |
||
39 | * Returns the contents of the file as an array. |
||
40 | * |
||
41 | * @return array |
||
42 | */ |
||
43 | 21 | public function getContents() |
|
44 | { |
||
45 | 21 | if ($this->exists()) { |
|
46 | 19 | return explode("\n", trim($this->read())); |
|
47 | } else { |
||
48 | 2 | return []; |
|
49 | } |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param string|null $newPath |
||
54 | * |
||
55 | * @return static |
||
56 | * @throws CopyFailedException When it is unable to copy the file |
||
57 | */ |
||
58 | 4 | public function copy($newPath = null) |
|
59 | { |
||
60 | 4 | if (is_null($newPath)) { |
|
61 | 1 | $newPath = $this->path . '-copy'; |
|
62 | 1 | } |
|
63 | |||
64 | 4 | if (@$this->filesystem->copy($this->path, $newPath)) { |
|
65 | 4 | return $this->getClone()->setPath($newPath); |
|
66 | } else { |
||
67 | $lastError = error_get_last(); |
||
68 | throw new CopyFailedException($this, $newPath, $lastError['message']); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Return a clone of this object |
||
74 | * |
||
75 | * @return static |
||
76 | */ |
||
77 | 56 | public function getClone() |
|
81 | |||
82 | /** |
||
83 | * Clone sub objects |
||
84 | */ |
||
85 | 56 | public function __clone() |
|
91 | } |
||
92 |