Proyectos de Subversion LeadersLinked - Services

Rev

Rev 339 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 339 Rev 747
Línea 74... Línea 74...
74
    {
74
    {
75
        $this->adapter = $adapter;
75
        $this->adapter = $adapter;
76
        $this->hasNetwork = false;
76
        $this->hasNetwork = false;
77
        $networkMapper = NetworkMapper::getInstance($adapter);
77
        $networkMapper = NetworkMapper::getInstance($adapter);
Línea 78... Línea -...
78
        
-
 
-
 
78
        
-
 
79
        // Primero, intentamos determinar la red a partir de la URI de la solicitud.
79
        
80
        // Esto es útil para los servicios internos o las llamadas a la API que pueden no tener un encabezado Host/Origin claro.
80
        $request_uri = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'];
81
        $request_uri = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'];
Línea 81... Línea 82...
81
        if($request_uri) {
82
        if($request_uri) {
82
            
83
            
83
            if(substr($request_uri, 0, 1) == '/') {
84
            if(substr($request_uri, 0, 1) == '/') {
Línea 84... Línea 85...
84
                $request_uri = substr($request_uri, 1);
85
                $request_uri = substr($request_uri, 1);
-
 
86
            }
-
 
87
        
85
            }
88
            $parts = explode('/', $request_uri);
Línea 86... Línea 89...
86
        
89
 
87
            $parts = explode('/', $request_uri);
90
            // Si la URI comienza con 'services', asumimos que es una llamada interna y cargamos la red predeterminada.
88
            if($parts[0] == 'services') {
91
            if($parts[0] == 'services') {
89
                
92
                
90
                $this->network = $networkMapper->fetchOneByDefault();
93
                $this->network = $networkMapper->fetchOneByDefault();
91
                if($this->network) {
94
                if($this->network) {
92
                    $this->hostname = $this->network->main_hostname;
-
 
93
                    $this->hasNetwork = true;
-
 
94
                }
-
 
95
            }
-
 
96
        
95
                    $this->hostname = $this->network->main_hostname;
Línea -... Línea 96...
-
 
96
                    $this->hasNetwork = true;
-
 
97
                }
97
        
98
            } 
Línea -... Línea 99...
-
 
99
        }
-
 
100
       
98
       
101
        // Si no se encontró una red a través de la URI, intentamos determinarla a partir del nombre de host.
Línea 99... Línea 102...
99
        
102
        // Esto es para las solicitudes front-end estándar del navegador.
100
        }
-
 
-
 
103
        if(!$this->hasNetwork) {
101
       
104
            
Línea 102... Línea 105...
102
        if(!$this->hasNetwork) {
105
            // Intentamos obtener el nombre de host de varias cabeceras HTTP en orden de preferencia.
-
 
106
            // HTTP_ORIGIN es el más fiable para las solicitudes de API (CORS).
103
            
107
            $hostname = empty($_SERVER['HTTP_ORIGIN']) ? '' : $_SERVER['HTTP_ORIGIN'];
Línea 104... Línea 108...
104
            $hostname = empty($_SERVER['HTTP_ORIGIN']) ? '' : $_SERVER['HTTP_ORIGIN'];
108
            
105
            
109
            if(empty($hostname)) {
Línea -... Línea 110...
-
 
110
                // HTTP_REFERER es una alternativa si el origen no está presente.
106
            if(empty($hostname)) {
111
                $hostname = empty($_SERVER['HTTP_REFERER']) ?  '' : $_SERVER['HTTP_REFERER'];
Línea 107... Línea 112...
107
            
112
                
Línea -... Línea 113...
-
 
113
                if(empty($hostname)) {
108
                $hostname = empty($_SERVER['HTTP_REFERER']) ?  '' : $_SERVER['HTTP_REFERER'];
114
                    // HTTP_HOST es el último recurso, que indica la máquina host de la solicitud.
Línea 109... Línea 115...
109
                
115
                    $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
Línea -... Línea 116...
-
 
116
        
110
                if(empty($hostname)) {
117
                }
111
                    $hostname = empty($_SERVER['HTTP_HOST']) ?  '' : $_SERVER['HTTP_HOST'];
118
            }
Línea 112... Línea 119...
112
        
119
            
Línea -... Línea 120...
-
 
120
            // Limpiamos el nombre de host eliminando el protocolo.
113
                }
121
            $hostname = trim(str_replace(['https://', 'http://'], '', $hostname));
114
            }
122
            
115
            
123
            
116
            $hostname = trim(str_replace(['https://', 'http://'], '', $hostname));
124
            //echo $hostname; exit;
117
            
125