-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsourceparser.class.php
69 lines (62 loc) · 1.67 KB
/
sourceparser.class.php
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
*
* @author David Raison <[email protected]>
* @file smwparser.class.php
* @version 0.1
*
*/
class SourceParser {
public static function retrieve( $format, $dsn ) {
global $config;
switch ( $format ) {
case 'smw':
$parts = parse_url( $dsn );
$source = $parts['scheme'];
$type = $parts['user'];
$content = $parts['host'];
$rawpath = $parts['path'];
switch ( $source ) {
case 'file':
try {
// currently ignoring $content and just presuming it to be a url
$filename = basename( $rawpath );
$filepath = dirname(__FILE__) . DS . 'config' . DS . $filename;
$config['debug'] && printf("Retrieving url from file \"%s\"\n", $filepath );
if ( $type === 'php' ) {
$cmd = sprintf('`which php` %s', $filepath );
$input = shell_exec( $cmd );
} elseif ( $type === 'plain' ) {
$input = file_get_contents( $filepath );
}
} catch (Exception $e) {
print($e->getTraceAsString());
}
break;
case 'http':
$config['debug'] && printf("Loading data from url %s\n", $dsn );
$input = $dsn;
break;
}
$source = new WikiApiClient;
$data = $source->getInitialData( $input );
break;
case 'pdo':
// in this case, we need to map the fields from the database to the properties we're accustomed to use
try {
$source = new PDOMapper;
$data = $source->getInitialData();
} catch ( Exception $e ) {
print( $e->getMessage() . "\n" );
print( $e->getTraceAsString() . "\n" );
}
break;
default:
throw new Exception( sprintf('No such datasource adapter: %s', $format) );
break;
}
if( $data )
return $data;
else throw new Exception( "Unable to retrieve data!" );
}
}