DEEP.php
3.34 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* Created by PhpStorm.
* User: Luigi Serra
* Date: 31/03/2015
* Time: 17.25
*/
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
require 'Slim/Slim.php';
class DEEP {
private static $instance = null;
private $app;
private $all_datalets;
private $all_controllets;
public static function getInstance()
{
if(self::$instance == null)
{
$c = __CLASS__;
self::$instance = new $c;
}
return self::$instance;
}
private function __construct()
{
\Slim\Slim::registerAutoloader();
$this->app = new \Slim\Slim();
$this->all_datalets = $this->loadServices("datalets.xml");
$this->app->get('/datalets-list', function(){
$this->app->response()->header("Content-Type", "application/json");
$this->app->response()->header("Access-Control-Allow-Origin", "*");
echo json_encode($this->all_datalets);
});
$this->all_controllets = $this->loadServices("controllets.xml");
$this->app->get('/controllets-list', function(){
$this->app->response()->header("Content-Type", "application/json");
$this->app->response()->header("Access-Control-Allow-Origin", "*");
echo json_encode($this->all_controllets);
});
//main service
$this->app->get('/', function(){
echo "Hello from web compoments RESTful service, call /datalets-list to get datalets list";
});
}
public function loadServices($source){
$components_array = array();
$handler_configuration = simplexml_load_file($source) or die("ERROR: cant read Components configuration \n");
$deep_configuration = $handler_configuration->deep_handler_configuration;
foreach($handler_configuration->components->children() as $component){
//array_push($components_array, $component->name."");
$component->url = $handler_configuration->deep_handler_configuration->components_repository_url_reference . $component->name . "/";
array_push($components_array, $component);
$this->app->get('/'.$component->name, function() use($component, $deep_configuration ){
$response = array(
"name" => $component->name."",
"bridge_link" => $deep_configuration->components_repository_url_reference."",
"component_link" => $component->name."/".$component->name.".html",
"idm" => $component->idm
);
if(isset($component->attributes)) {
$response['attributes'] = array();
foreach ($component->attributes->children() as $attribute) {
array_push($response['attributes'], $attribute->name."");
}
}
$this->app->response()->header("Content-Type", "application/json");
$this->app->response()->header("Access-Control-Allow-Origin", "*");
echo json_encode($response);
});
}
return $components_array;
}
public function run(){
//run the Slim app
$this->app->run();
}
}
?>