/** * Configure the output handler. This will find the most suitable output * handler based on the request, and set the object's handler accordingly. * If none are found, defaults are used. * * @param string $param The output handler parameter * @param string $default The default output handler * @param array $request_params Pointer to request parameters array * @return bool */ public function configure_handler($param, $default, array &$request_params) { $index = \veneer\util::header_to_index($param); if (array_key_exists($index, $_SERVER)) { $class = sprintf('\\veneer\\output\\handler\\%s', $_SERVER[$index]); $this->set_output_handler($_SERVER[$index]); } if (is_null($this->get_output_handler())) { foreach ($request_params as $name => $value) { if ($name == $param) { $this->set_output_handler($value); unset($request_params[$name]); } } } if (is_null($this->get_output_handler())) { $this->set_output_handler($default); } }
/** * Parse through the request and evaluate raw HTTP header data. This function * will populate the PHP server environment the way one would normally expect * it to be via mod_php or FastCGI. * * @param string $request An associative array containing request data * @return bool */ public function set_environment($request) { if ($request['method'] == 'GET') { global $_GET; $_GET = $request['params']; } else { if ($request['method'] == 'PUT' || $request['method'] == 'POST') { global $_POST; $_POST = $request['params']; } } global $_SERVER; $_SERVER['REQUEST_METHOD'] = $request['method']; $_SERVER['REQUEST_URI'] = $request['uri']; $_SERVER['SERVER_PROTOCOL'] = $request['protocol']; $_SERVER['HTTP_HOST'] = $request['http_host'] . ':' . $request['server_port']; $_SERVER['SERVER_PORT'] = $request['server_port']; $_SERVER['REMOTE_ADDR'] = $request['remote_addr']; $_SERVER['REMOTE_PORT'] = $request['remote_port']; foreach ($request['headers'] as $key => $val) { $index = \veneer\util::header_to_index($key); $_SERVER[$index] = $val; } return true; }