<?php /** * Created by IntelliJ IDEA. * User: tueda * Date: 15/09/10 * Time: 11:18 */ include_once __DIR__ . "/env.php"; require_once LIBRARY_PATH . "/etc/ApiConfig.php"; require_once LIBRARY_PATH . "/common/ClassLoader.php"; ClassLoader::addPath(array(LIBRARY_PATH . '/' . ApiConfig::$API_ETC, LIBRARY_PATH . '/' . ApiConfig::$API_COMMON, LIBRARY_PATH . '/' . ApiConfig::$API_ABST, LIBRARY_PATH . '/' . ApiConfig::$API_OBJECTS, LIBRARY_PATH . '/' . ApiConfig::$API_IMPLE, LIBRARY_PATH . '/' . ApiConfig::$LOG4PHP_DIR)); spl_autoload_register(array('ClassLoader', '_autoLoad')); ApiLogger::__init(array('log4php.properties')); try { $strApi = $_GET["api"]; $api = new $strApi(); $api->action(); } catch (Exception $e) { ApiLogger::fatal($e); }
/** * API実行 */ public function action() { ApiLogger::trace("ApiBase#action start : " . get_class($this)); session_name(Constant::$SESSION_NAME); session_start(); $argRequest = $this->getParamsObject(); /* * Response オブジェクトの作成 */ $apiResponse = new RestSampleResponse(); if ($argRequest !== null) { try { if ($this->isAuthenticationRequired()) { ApiLogger::debug("Authentication is required."); if (!$this->isAuthenticated()) { throw new AuthenticationException("Authentication Error"); } } if ($this->validate()) { $apiTelegram = $this->execute($argRequest); } else { /* * validateion error 時の処理 */ } } catch (AuthenticationException $e) { ApiLogger::debug("Authentication Exception is caucht."); } catch (Exception $e) { ApiLogger::debug("General Exception is caught."); ApiLogger::fatal($e); } } else { ApiLogger::debug("data cannot get."); } if (count($this->getApiErrorItems()) !== 0) { ApiLogger::debug("ApiBase: Error detected : " . count($this->getApiErrorItems())); /* * Error detected * エラーの取り扱いについては別途実装のこと */ } $regResponse = $this->regularizeResponse($apiResponse); $jsonString = json_encode($regResponse); ApiLogger::debug("Response json : " . $jsonString . "\n"); if (isset($jsonString)) { print $jsonString; } }