-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparser.php
More file actions
45 lines (36 loc) · 1.13 KB
/
parser.php
File metadata and controls
45 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
include 'includes.php';
// global variables
$GLOBALS['header'] = ['make', 'model', 'condition', 'grade', 'capacity', 'colour', 'network'];
$GLOBALS['hashes'] = [];
$GLOBALS['values'] = [];
$GLOBALS['column_size'] = sizeof($GLOBALS['header']);
// get options
$options = getopt(null, ["file:", "unique-combinations::"]);
// check file parameter
if (!isset($options['file'])) {
print 'File parameter must be required.';
return false;
}
$file = $options['file'];
// check if file exists
if (!isFileExists($file)) {
print 'File not found.';
return false;
}
// get an extension of file
$extension = pathinfo($file, PATHINFO_EXTENSION);
if (!isExtensionAllowed($extension)) {
print 'File extension must be csv,json or xml.';
return false;
}
// call class by extensions
$class = getClassName($extension);
$type = new $class();
if ($type->readData($file)) {
// output file
$output_file = isset($options['unique-combinations']) ? $options['unique-combinations'] : 'combination_count.csv';
// call function for put data into csv
$csv = Csv::putData($output_file, $GLOBALS['header'], $GLOBALS['values']);
}
?>