0
1
Fork 0
hedera-web-mindshore/vn/web/app.php

73 lines
1.6 KiB
PHP
Raw Normal View History

2016-07-22 20:00:27 +00:00
<?php
namespace Vn\Web;
require_once ('vn/lib/app.php');
2016-09-19 06:40:18 +00:00
require_once (__DIR__.'/jwt.php');
2016-07-22 20:00:27 +00:00
/**
* Main class for web applications.
*
* Format for $_REQUEST['srv'] variable:
* - [serviceName]:[requestDir]/[requestFile]
2016-07-22 20:00:27 +00:00
**/
class App extends \Vn\Lib\App
2016-07-22 20:00:27 +00:00
{
2016-08-30 07:43:47 +00:00
protected $conn = NULL;
private $allowedServices =
[
'html',
'rest',
'json'
];
function run ()
2016-07-22 20:00:27 +00:00
{
$this->init ();
2016-07-22 20:00:27 +00:00
$srv = empty ($_REQUEST['srv']) ? '' : $_REQUEST['srv'];
$explode = explode (':', $srv, 2);
2016-07-22 20:00:27 +00:00
if (count ($explode) > 0)
$_REQUEST['service'] = $explode[0];
if (count ($explode) > 1)
$_REQUEST['method'] = $explode[1];
2016-07-22 20:00:27 +00:00
$service = empty ($_REQUEST['service']) ? 'html' : $_REQUEST['service'];
2016-07-22 20:00:27 +00:00
if (in_array ($service, $this->allowedServices, TRUE))
2016-07-22 20:00:27 +00:00
{
$includeFile = __DIR__."/$service-service.php";
require_once ($includeFile);
2016-07-22 20:00:27 +00:00
$className = __NAMESPACE__ .'\\'. hyphenToCamelCase ($service, TRUE) .'Service';
$service = new $className ($this);
$service->run ();
2016-07-22 20:00:27 +00:00
}
else
http_response_code (400);
2016-07-22 20:00:27 +00:00
}
/**
* Gets the configuration file name associated to the current vhost
* or the default config file if isn't defined a file for the vhost.
2016-07-22 20:00:27 +00:00
**/
function getConfigFile ()
{
if (!empty ($_SERVER['SERVER_NAME'])
&& preg_match ('/^[\w\-\.]+$/', $_SERVER['SERVER_NAME']))
{
$hostSplit = explode ('.', $_SERVER['SERVER_NAME']);
$configDir = _CONFIG_DIR .'/'. $this->name;
2016-09-19 06:40:18 +00:00
$hostFile = "$configDir/config/{$hostSplit[0]}.php";
2016-07-22 20:00:27 +00:00
}
if (isset ($hostFile) && file_exists ($hostFile))
return $hostFile;
else
return parent::getConfigFile ();
}
}
?>