Blame view

DEEP.php 4.73 KB
219b8036   luigser   DEEP
1
2
  <?php

  /**

d69c3e08   Luigi Serra   updates
3
4
5
6
7
8
   * Created by :

   * Luigi Serra - luigser@gmail.com

   * Andrea Petta - andrpet@gmail.com

   *

   * Copyright (c) 2015 Dipartimento di Informatica - Università di Salerno - Italy

   *

219b8036   luigser   DEEP
9
   */

d69c3e08   Luigi Serra   updates
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
  

  /*

  @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.

  */

  

219b8036   luigser   DEEP
36
37
38
39
40
41
  ini_set('display_errors',1);

  ini_set('display_startup_errors',1);

  error_reporting(-1);

  

  require 'Slim/Slim.php';

  

293da0d3   Luigi Serra   Datalets xml update
42
43
44
  /**

   * Class DEEP

   */

219b8036   luigser   DEEP
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
  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";

          });

      }

  

293da0d3   Luigi Serra   Datalets xml update
89
90
91
92
      /**

       * @param $source

       * @return array

       */

219b8036   luigser   DEEP
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
      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();

      }

  

  

  }

  ?>