219b8036
luigser
DEEP
|
1
|
<?php
|
d69c3e08
Luigi Serra
updates
|
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
|
/*
@license
The MIT License (MIT)
Copyright (c) 2015 Dipartimento di Informatica - Università di Salerno - Italy
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
|
a1b666b7
Luigi Serra
license updates
|
27
28
29
|
/**
* Developed by :
* ROUTE-TO-PA Project - grant No 645860. - www.routetopa.eu
|
a1b666b7
Luigi Serra
license updates
|
30
31
|
*/
|
219b8036
luigser
DEEP
|
32
33
34
35
36
37
|
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
require 'Slim/Slim.php';
|
293da0d3
Luigi Serra
Datalets xml update
|
38
39
40
|
/**
* Class DEEP
*/
|
219b8036
luigser
DEEP
|
41
42
43
44
45
46
|
class DEEP {
private static $instance = null;
private $app;
private $all_datalets;
private $all_controllets;
|
76117121
isisadmin
add deep configur...
|
47
48
49
|
private $controllet_repository_url;
private $datalet_repository_url;
|
219b8036
luigser
DEEP
|
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
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();
|
76117121
isisadmin
add deep configur...
|
66
67
68
|
$this->loadRepositoryUrl("configuration.xml");
$this->all_datalets = $this->loadServices("datalets.xml", $this->datalet_repository_url);
|
219b8036
luigser
DEEP
|
69
70
71
|
$this->app->get('/datalets-list', function(){
$this->app->response()->header("Content-Type", "application/json");
$this->app->response()->header("Access-Control-Allow-Origin", "*");
|
219b8036
luigser
DEEP
|
72
73
74
75
|
echo json_encode($this->all_datalets);
});
|
76117121
isisadmin
add deep configur...
|
76
|
$this->all_controllets = $this->loadServices("controllets.xml", $this->controllet_repository_url);
|
219b8036
luigser
DEEP
|
77
78
79
|
$this->app->get('/controllets-list', function(){
$this->app->response()->header("Content-Type", "application/json");
$this->app->response()->header("Access-Control-Allow-Origin", "*");
|
219b8036
luigser
DEEP
|
80
81
82
83
84
85
86
87
88
89
|
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";
});
}
|
76117121
isisadmin
add deep configur...
|
90
91
92
93
94
95
96
|
public function loadRepositoryUrl($source)
{
$handler_configuration = simplexml_load_file($source) or die("ERROR: cant read Components configuration \n");
$this->datalet_repository_url = $handler_configuration->deep_datalet_configuration->components_repository_url_reference;
$this->controllet_repository_url = $handler_configuration->deep_controllets_configuration->components_repository_url_reference;
}
|
293da0d3
Luigi Serra
Datalets xml update
|
97
98
99
100
|
/**
* @param $source
* @return array
*/
|
76117121
isisadmin
add deep configur...
|
101
|
public function loadServices($source, $repository_url){
|
219b8036
luigser
DEEP
|
102
103
|
$components_array = array();
$handler_configuration = simplexml_load_file($source) or die("ERROR: cant read Components configuration \n");
|
219b8036
luigser
DEEP
|
104
105
106
|
foreach($handler_configuration->components->children() as $component){
//array_push($components_array, $component->name."");
|
76117121
isisadmin
add deep configur...
|
107
|
$component->url = $repository_url . $component->name . "/";
|
219b8036
luigser
DEEP
|
108
|
array_push($components_array, $component);
|
76117121
isisadmin
add deep configur...
|
109
|
$this->app->get('/'.$component->name, function() use($component, $repository_url){
|
219b8036
luigser
DEEP
|
110
111
|
$response = array(
"name" => $component->name."",
|
4faf3f49
Renato De Donato
datalet.dtd
|
112
|
"type" => $component->type."",
|
76117121
isisadmin
add deep configur...
|
113
|
"bridge_link" => $repository_url."",
|
219b8036
luigser
DEEP
|
114
115
116
117
118
119
120
121
122
123
124
125
126
|
"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", "*");
|
219b8036
luigser
DEEP
|
127
128
129
130
131
132
133
134
135
136
137
138
|
echo json_encode($response);
});
}
return $components_array;
}
public function run(){
//run the Slim app
$this->app->run();
}
|
76117121
isisadmin
add deep configur...
|
139
|
}
|