app = new \Slim\Slim(); $this->loadRepositoryUrl("configuration.xml"); $this->all_datalets = $this->loadServices("datalets.xml", $this->datalet_repository_url); $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->controllet_repository_url); $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 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; } /** * @param $source * @return array */ public function loadServices($source, $repository_url){ $components_array = array(); $handler_configuration = simplexml_load_file($source) or die("ERROR: cant read Components configuration \n"); foreach($handler_configuration->components->children() as $component){ //array_push($components_array, $component->name.""); $component->url = $repository_url . $component->name . "/"; array_push($components_array, $component); $this->app->get('/'.$component->name, function() use($component, $repository_url){ $response = array( "name" => $component->name."", "type" => $component->type."", "bridge_link" => $repository_url."", "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(); } }