static function recognise(URL $url) { $url = $url->getPath(); if ($url->firstPathElement() == 'api') { $url->removeFirstPathElement(); $module = $url->firstPathElement(); $url->removeFirstPathElement(); $method = $url->firstPathElement(); $url->removeFirstPathElement(); $type = static::DEFAULT_TYPE; if (count($parts = explode('.', $method)) > 1) { if (count($parts) != 2) { throw new \Exception('Invalid API Method'); } $method = $parts[0]; $type = $parts[1]; } //Query Data $query = $url->getQuery(); if (!isset($_SERVER['HTTP_CONTENT_TYPE']) || $_SERVER['HTTP_CONTENT_TYPE'] != 'application/octet-stream') { if ($query) { $query = array_merge($query, $_POST); } else { $query = $_POST; } } return Handler::Objectify('API', array('module' => $module, 'method' => $method, 'type' => $type, 'query' => $query)); } }
function execute($method) { parent::Execute($method); //Flush Output $this->headers->Output(); ob_end_flush(); //Remove from stack PH::Pop(); }
function execute($method = 'GET') { ob_start(); parent::Execute($method); $data = ob_get_contents(); ob_end_clean(); //Pop off the stack PH::Pop(); return $data; }
function execute($method) { if ($method == 'GET') { $this->cache->preExecute(); } //No assumptions $method = strtoupper($method); //Add to Page\Handler Stack PH::Push($this); //Setup output buffering ob_start(); $real_method = $method; $depth = 0; while ($this->page->can($method) || $this->can_fake($method)) { $depth++; if ($this->can_fake($method)) { $method = 'GET'; } $return = $this->page->execute_request($method); if ($return) { ob_clean(); $this->page = $return; } else { if (!$this->page->can($real_method)) { if ($real_method == 'HEAD') { //$contents = ob_get_contents(); //Headers only, no body ob_clean(); } } break; } //Infinite loop? if ($depth > static::MAX_REQUEST_DEPTH) { PH::Pop(); ob_end_flush(); $this->headers->Clear(); throw new PageHandlerException('Max request depth of ' . static::MAX_REQUEST_DEPTH . ' exceeded.'); } } ob_end_flush(); //Nothing was handled if (!$depth) { PH::Pop(); $this->headers->Clear(); throw new PageHandlerException('Invalid or unknown method ' . $method); } //Pass to the cache handler if ($method == 'GET') { $this->cache->postExecute($this->headers); } }
protected function sendHeaders($file) { if (!is_array($file)) { $file = array($file); } $headers = \Radical\Web\Page\Handler::current()->headers; $headers->Add('Content-Type', static::MIME_TYPE); $headers->Add('Cache-Control', 'public'); $headers->setCache(60 * 60 * 24); $headers->Add('Pragma', 'cache'); //$headers['Vary'] = 'Accept-Encoding'; $times = array_map('filemtime', $file); if (!$times) { return; } $filemtime = max($times); //die(var_dump($file)); $headers->setLastModified($filemtime); }
function exception(ErrorException $error) { if (ob_get_level()) { ob_end_clean(); } try { \Radical\Web\Page\Handler::init(); \Radical\Web\Page\Handler::$stack->push(new PageRequest(null)); //@todo Remove ugly hack $page = new Error($error); while ($page) { $page = $page->GET(); } \Radical\Web\Page\Handler::current(true)->headers->output(); } catch (\Exception $ex) { die('Error: ' . $ex->getMessage()); } exit; }
/** * Handle GET request * * @throws \Exception */ function GET() { $adapter = $this->adapter(); if ($adapter == null) { throw new \Exception('Template file couldnt be found'); } if ($adapter instanceof Templates\Adapter\ITemplateAdapter) { $top = Page\Handler::Top(); if ($top && $top->headers) { $top->headers->Add('Content-Type', 'text/html;charset=utf-8'); } else { //Warning } //$VAR,$HANDLER,$TEMPLATE_FILE $adapter->Output($this->_scope()); } else { throw new \Exception('Invalid Template Adapter'); } }
/** * Handle GET request * * @throws \Exception */ function GET() { \Radical\Web\Page\Handler::top()->headers['Content-Type'] = 'image/gif'; echo base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'); }
/** * Handle GET request * * @throws \Exception */ function GET() { \Radical\Web\Page\Handler::top()->headers->status(500); return new Template('error', array('error' => $this->error), 'framework'); }
/** * Handle GET request * * @throws \Exception */ function GET() { $key = static::EXTENSION . '_' . $this->name . '_' . $this->version; $files = $this->getFiles(); $this->sendHeaders($files); $cache = PooledCache::Get(get_called_class(), 'Memory'); $ret = $cache->get($key); if (!$ret || !\Radical\Core\Server::isProduction()) { $data = array(); foreach ($files as $f) { if (is_file($f)) { //Ignore folders $fn = basename($f); $data[$fn] = Individual::get_file($f); } } $ret = ''; foreach ($data as $f => $d) { if (!\Radical\Core\Server::isProduction()) { $ret .= "\r\n/* Including: " . $f . " */\r\n"; } $ret .= $d; } if (\Radical\Core\Server::isProduction()) { $ret = $this->optimize($ret); $cache->set($key, $ret); } } echo $ret; $headers = \Radical\Web\Page\Handler::top()->headers; $headers->setContentLength(strlen($ret)); $headers['Vary'] = 'Accept-Encoding'; }