1: <?php
2:
3: require_once 'TranscriptDB/db.php';
4:
5: 6: 7:
8: abstract class WebService {
9:
10: 11: 12: 13:
14: abstract public function execute($data);
15:
16: 17: 18: 19:
20: public static function output($dataArray) {
21: echo json_encode($dataArray, defined('JSON_PRETTY_PRINT')?JSON_PRETTY_PRINT:0);
22: }
23:
24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36: public static function factory($servicePath) {
37: $serviceBasePath = __DIR__ . DIRECTORY_SEPARATOR . 'webservices';
38:
39: $path = explode('/', $servicePath);
40: $filepath = $serviceBasePath . DIRECTORY_SEPARATOR . $path[0];
41: $serviceNamespace = '\\webservices\\' . $path[0];
42: $args = array();
43: for ($i = 1; $i < count($path); $i++) {
44: $classname = ucfirst($path[$i]);
45: $filename = $filepath . DIRECTORY_SEPARATOR . $classname . '.php';
46: if (file_exists($filename)) {
47: for ($j = $i + 1; $j < count($path); $j++) {
48: $args['query' . ($j - $i)] = $path[$j];
49: }
50: break;
51: }
52: $filepath .= DIRECTORY_SEPARATOR . strtolower($path[$i]);
53: $serviceNamespace .= '\\' . strtolower($path[$i]);
54: }
55:
56:
57: if (!isset($filename) || !file_exists($filename)) {
58: return array(null, null);
59: }
60:
61: if (!(strpos(realpath($filename), realpath($serviceBasePath)) === 0)) {
62: return array(null, null);
63: }
64: require_once $filename;
65:
66: $class = $serviceNamespace . '\\' . $classname;
67: if (!class_exists($class)) {
68: return array(null, null);
69: }
70:
71: return array(new $class, $args);
72: }
73:
74:
75: }
76:
77: ?>
78: