Skip to content

Commit a35259f

Browse files
committed
Allow importing multiple files or stdin
1 parent 002fc42 commit a35259f

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

bin/import.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77

88
$importer = ImporterFactory::create();
99

10-
if ($argc <= 1) {
11-
throw new RuntimeException('Missing input filename');
12-
}
10+
if ($argc > 1) {
11+
foreach (array_splice($argv, 1) as $file) {
12+
if (!is_readable($file)) {
13+
throw new RuntimeException("{$file} isn't readable");
14+
}
1315

14-
$filename = $argv[1];
15-
if (!is_readable($filename)) {
16-
throw new RuntimeException($filename . ' isn\'t readable');
16+
$fp = fopen($file, 'r');
17+
if (!$fp) {
18+
throw new RuntimeException("Can't open {$file}");
19+
}
20+
$importer->import($fp);
21+
fclose($fp);
22+
}
23+
} else {
24+
$importer->import(STDIN);
1725
}
1826

19-
$fp = fopen($filename, 'r');
20-
if (!$fp) {
21-
throw new RuntimeException('Can\'t open ' . $filename);
22-
}
23-
$importer->import($fp);
24-
fclose($fp);

0 commit comments

Comments
 (0)