/** * create metadata * * @throws InvalidOperationException * * @return NorthWindMetadata */ public static function create() { $db_name = ServiceConfig::GetServiceInfo('db_name'); DB::connect(ServiceConfig::GetServiceInfo('server'), $db_name, ServiceConfig::GetServiceInfo('user'), ServiceConfig::GetServiceInfo('password')); $metadata = new ServiceBaseMetadata('DefaultEntities', $db_name); $tables = DB::table("select `table_name`,`table_type` from information_schema.tables where `table_schema`='{$db_name}';"); foreach ($tables as $table) { $postsEntityType = $metadata->addEntityType(new ReflectionClass('EmptyEntity'), $table['table_name']); } return $metadata; }
/** * This function is initializes the properties of Dispatcher class. * * @return Object of WebOperationContext class */ function __construct() { try { $this->_dataServiceHost = new DataServiceHost(); } catch (\Exception $exception) { self::_handleException($exception->getMessage(), $exception->getStatusCode()); } try { ServiceConfig::validateAndGetsServiceInfo($this->_getServiceNameFromRequestUri(), $this->_serviceInfo); $this->_dataServiceHost->setAbsoluteServiceUri($this->_serviceInfo['SERVICE_BASEURL']); } catch (ODataException $exception) { self::_handleException($exception->getMessage(), $exception->getStatusCode()); } }
/** * Constructs a new instance of WordPressQueryProvider * */ public function __construct() { DB::Connect(ServiceConfig::GetServiceInfo('server'), ServiceConfig::GetServiceInfo('db_name'), ServiceConfig::GetServiceInfo('user'), ServiceConfig::GetServiceInfo('password')); }
/** * This function perform the following steps: * 1) Resolve and validate the service * 2) Creates the instance of requested service * 3) Calls the handleRequest() to process the request * 4) Calls the handleresponse() to sendback the o/p to the client * * @return void */ public function dispatch() { $dataService = null; try { $reflectionClass = new \ReflectionClass(ServiceConfig::GetServiceInfo("classname")); $dataService = $reflectionClass->newInstance(); } catch (\Exception $exception) { $this->_handleException($exception->getMessage(), HttpStatus::CODE_INTERNAL_SERVER_ERROR); } $interfaces = class_implements($dataService); if (array_key_exists('ODataProducer\\IDataService', $interfaces)) { $dataService->setHost($this->_dataServiceHost); if (array_key_exists('ODataProducer\\IRequestHandler', $interfaces)) { // DataService::handleRequest will never throw an error // All exception that can occur while parsing the request and // serializing the result will be handled by // DataService::handleRequest $dataService->handleRequest(); } else { $this->_handleException(Messages::dispatcherServiceClassShouldImplementIRequestHandler(), HttpStatus::CODE_INTERNAL_SERVER_ERROR); } } else { $this->_handleException(Messages::dispatcherServiceClassShouldImplementIDataService(), HttpStatus::CODE_INTERNAL_SERVER_ERROR); } $this->_writeResponse($dataService->getHost()->getWebOperationContext()->outgoingResponse()); }