You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.9 KiB
Plaintext
69 lines
2.9 KiB
Plaintext
index.php
|
|
web = new NetBiblio()
|
|
parent::__construct(self::$version)
|
|
web->Run() <=> parent->Run()
|
|
| Logger::start(version) // initialize static log array
|
|
| new Renderer::__construct()
|
|
| |---ob_start()
|
|
| $data = []
|
|
| try {
|
|
| $result = this->Call() //1) start session,
|
|
| | //2) call webservice method and params passed in
|
|
| | // http request after doing a few checks
|
|
| | //3) log the request
|
|
| | session_save_path(Configuration::get(session.save_path))
|
|
| | session_start()
|
|
| | $paras = GET or POST
|
|
| | if empty(params) throw NoArguments
|
|
| | if !isset(params["func"]) throw MissingMethod
|
|
| | this->func = params["func"]
|
|
| | unset(params["func"])
|
|
| | Logger::info([
|
|
| | "func" => this->func . '(' . implode(',' params) . ')'
|
|
| | ]) // add func -> string to Logger::data
|
|
| | if !is_callable([this, this->func]) throw BadMethod
|
|
| | // descriptive wrapper for NetBiblio method
|
|
| | $rm = new \ReflectionMethod(this, this->func)
|
|
| | // check whether provided params match required
|
|
| | //TODO here is where the magic happens !!!!!!!!!!!!!!!!!!!!
|
|
| |---return call_user_func_array([this, this->func], params)
|
|
| $data['result'][this->func] = $result
|
|
| } catch (WebException $e) {
|
|
| $data['error'] = ['code' => $e->getCode(), ... ]
|
|
| $this->status = 400
|
|
| Logger::info($e->getName(), 'error') // add to log
|
|
| } catch (\Exception $e) {
|
|
| $data['failure'] = ['code' => $e->getCode(), 'reason' ...]
|
|
| Logger::info($e->getMessage, 'error')
|
|
| }
|
|
| Logger::stop(['status' => $this->status])
|
|
| $renderer->render($this->status, $data) // default status:200
|
|
| | header(sprintf(
|
|
| | 'HTTP/1.0 %s %s',
|
|
| | $status, self::$statusMessages[$status]
|
|
| | ))
|
|
| | header('Access-Control-Allow-Origin: *')
|
|
| | ob_clean()
|
|
| | flush()
|
|
| | $formatter = Formatter::getFormatter();
|
|
| | | self::loadFormatters() // call init on all formatters in dir
|
|
| | | | foreach($files as f) {
|
|
| | | | //infer class name from file name
|
|
| | | | //and if it is not this current class
|
|
| | | | //call init on the class
|
|
| | | | //Ex:
|
|
| | | | Json::init()
|
|
| | | | | self::registerFormats([ //self parent
|
|
| | | | | 'application/json',
|
|
| | | | | 'application/x-json',
|
|
| | | | | ]);
|
|
| | | | | | forach($formats as $f) { // self
|
|
| | | | | | self::$formats[$f] = get_called_class()
|
|
| | | | |---|---}
|
|
| | | | }
|
|
| | | $format = self::getFormatFromHeader();
|
|
| | | |---return 'BSR\Lib\Formatter\Json';
|
|
| | |---return new $format()
|
|
| | $formatter->render($data)
|
|
|---|---|---echo json_encode($data)
|