1 <?php
2
3 4 5 6
7 class MagratheaServer {
8
9 10 11
12 public function MagratheaServer(){
13 }
14
15 16 17 18
19 public function AllowAll(){
20 header('Access-Control-Allow-Origin: *');
21 header('Access-Control-Allow-Methods: GET, POST');
22 header('Access-Control-Max-Age: 1000');
23 header('Access-Control-Allow-Headers: Content-Type');
24 return $this;
25 }
26
27 28 29
30 public function Start(){
31 $get = $_GET;
32 $args = null;
33 $action = "Wsdl";
34
35 if(!empty($get)){
36 $action=array_keys($get)[0];
37 $args = array_shift($get);
38 }
39 $this->$action($args);
40 }
41
42 43 44 45
46 protected function Json($response){
47 header('Content-Type: application/json');
48 echo json_encode($response);
49 die;
50 }
51
52 53 54
55 protected function Wsdl(){
56 header('Content-Type: text/plain; charset=utf-8');
57 $className = get_called_class();
58 $methods = $this->getDeclaredMethods($className);
59 $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
60 echo "=== * * { ".$className." } * * ==========================================================[MagratheaServer]=\n";
61 echo "===\n";
62 echo "=== CALLS:\n";
63 foreach ($methods as $m) {
64 echo "=== \t[".$url."?".$m."] \n";
65 }
66 echo "===\n===\n";
67 }
68
69 private function getDeclaredMethods($className) {
70 $reflector = new ReflectionClass($className);
71 $methodNames = array();
72 $lowerClassName = strtolower($className);
73 foreach ($reflector->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
74 if (strtolower($method->class) == $lowerClassName) {
75 $methodNames[] = $method->name;
76 }
77 }
78 return $methodNames;
79 }
80
81 }
82
83 ?>