Skip to content

Commit fd5f4da

Browse files
return not echo
1 parent b48cbaf commit fd5f4da

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/GetFiles.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,32 @@
44

55
class GetFiles {
66

7-
private $files;
7+
private $path;
8+
private $order;
9+
private $exclude;
810

9-
public function __construct( $path = '' ) {
10-
$this->files = [];
11-
foreach (array_diff(scandir($path), ['.', '..']) as $file) {
12-
$this->files[$file] = filemtime($path . '/' . $file);
13-
}
11+
public function __construct( $path = '', $order = '', $exclude = '' ) {
12+
$this->path = $path;
13+
$this->order = $order;
14+
$this->exclude = $exclude;
1415
}
1516

16-
public function sortDate( $direction = '' ) {
17-
if ($direction == 'DESC') {
18-
arsort($this->files); // newest first
19-
} elseif ($direction == 'ASC') {
20-
asort($this->files); // oldest first
17+
public function sortDate() {
18+
$files = [];
19+
foreach (array_diff(scandir($this->path), $this->exclude) as $file) {
20+
$files[$file] = filemtime($this->path . '/' . $file);
21+
}
22+
23+
if ($this->order == 'DESC') {
24+
arsort($files); // newest first
25+
} elseif ($this->order == 'ASC') {
26+
asort($files); // oldest first
2127
} else {
2228
// alphabetical/default
2329
}
24-
$this->files = array_keys($this->files);
25-
print_r( ($this->files) ? $this->files : false);
30+
$files = array_keys($files);
31+
32+
return json_encode($files);
2633
}
2734

2835
}

0 commit comments

Comments
 (0)