From f59bc054211a539134fcb46372883f897ba5c326 Mon Sep 17 00:00:00 2001 From: Gergely POLONKAI Date: Sun, 4 Nov 2012 14:59:50 +0100 Subject: [PATCH] Started configuration implementation --- web/json_sms.php | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/web/json_sms.php b/web/json_sms.php index 54167bb..4452cec 100644 --- a/web/json_sms.php +++ b/web/json_sms.php @@ -9,12 +9,37 @@ use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Exception\MethodNotAllowedException; +use Symfony\Component\Yaml\Yaml; -use SmsGateway\Sender\FileSender; -use SmsGateway\Logger\FileLogger; -use SmsGateway\Auth\FileAuth; use SmsGateway\RpcServer; +$configFile = __DIR__ . '/../app/config/config.yml'; + +$globalConfig = Yaml::parse($configFile); +if (!array_key_exists('sms_gateway', $globalConfig)) { + error_log($configFile . ' does not contain the sms_gateway level!'); + die('Invalid configuration file!'); +} + +$config = $globalConfig['sms_gateway']; +if (!array_key_exists('sender_class', $config)) { + error_log($configFile . ' does not specify sender_class!'); + die('Invalid configuration file!'); +} +$senderClass = $config['sender_class']; + +if (!array_key_exists('auth_class', $config)) { + error_log($configFile . ' does not specify auth_class!'); + die('Invalid configuration file!'); +} +$authClass = $config['auth_class']; + +if (!array_key_exists('logger_class', $config)) { + error_log($configFile . ' does not specify logger_class!'); + die('Invalid configuration file!'); +} +$loggerClass = $config['logger_class']; + $request = Request::createFromGlobals(); $routes = new RouteCollection(); @@ -56,7 +81,7 @@ if (!array_key_exists('method', $jsonData) || !array_key_exists('params', $jsonD $wantResponse = (!empty($jsonData['id'])); try { - $sender = new FileSender('/var/www/html/smsgateway/app/cache/sms_spool'); + $sender = new $senderClass('/var/www/html/smsgateway/app/cache/sms_spool'); } catch (Exception $e) { $response = new Response('Internal Server Error: Sender cannot be instantiated.', 500); $response->send(); @@ -64,7 +89,7 @@ try { } try { - $logger = new FileLogger('/var/www/html/smsgateway/app/logs/sms-message.log', '/var/www/html/smsgateway/app/logs/sms-audit.log'); + $logger = new $loggerClass('/var/www/html/smsgateway/app/logs/sms-message.log', '/var/www/html/smsgateway/app/logs/sms-audit.log'); } catch (LogicException $e) { $response = new Response('Internal Server Error: Logger cannot be instantiated.', 500); $response->send(); @@ -72,7 +97,7 @@ try { } try { - $auth = new FileAuth('/var/www/html/smsgateway/senders', '/var/www/html/smsgateway/app/cache/tokens'); + $auth = new $authClass('/var/www/html/smsgateway/senders', '/var/www/html/smsgateway/app/cache/tokens'); } catch (Exception $e) { $response = new Response('Internal Server Error: Authenticator cannot be instantiated.', 500); $response->send();