/** * @see \Components\Http_Scriptlet::dispatch() dispatch */ public static function dispatch(Http_Scriptlet_Context $context_, Uri $uri_) { $response = $context_->getResponse(); $content = null; try { // FIXME Temporary fix - create a explicit route for ui/scriptlet/embedded. if (Environment::isEmbedded()) { $scriptlet = new Ui_Scriptlet_Embedded(); $scriptlet->request = $context_->getRequest(); $scriptlet->response = $context_->getResponse(); $method = $scriptlet->request->getMethod(); if (false === method_exists($scriptlet, strtolower($method))) { throw new Http_Exception('ui/scriptlet', null, Http_Exception::NOT_FOUND); } $content = $scriptlet->{$method}(); } else { $content = parent::dispatch($context_, $uri_); } } catch (\Exception $e) { Runtime::addException($e); if ($e instanceof Http_Exception) { $e->sendHeader(); } } echo $content; }
public static function serve($pattern_ = null, $resource_ = null) { if (false === self::$m_initialized) { self::initialize(); } if (null === $resource_) { $resource_ = get_called_class(); } parent::serve($pattern_, $resource_); self::$m_resources[$resource_] = $resource_; }
private function dispatchImpl(Uri $uri_, $method_ = null) { $this->m_contextUri = Uri::valueOf($this->m_contextRoot); $this->m_request = new Http_Scriptlet_Request(clone $uri_); if (null !== $method_) { $this->m_request->setMethod($method_); } $mimeType = $this->m_request->getMimetype(); header('Content-Type: ' . $mimeType->name() . ';charset=' . $mimeType->charset()->name(), true, 200); $this->m_response = new Http_Scriptlet_Response($mimeType); if ('/' !== $this->m_contextRoot) { $contextRoot = rtrim($this->m_contextRoot, '/'); $contextRoot = ltrim($contextRoot, '/'); $contextRootSegments = explode('/', $contextRoot); while (count($contextRootSegments)) { if (array_shift($contextRootSegments) !== $uri_->shiftPathParam()) { throw new Http_Exception('http/scriptlet/context', null, Http_Exception::NOT_FOUND); } } } if (!($component = $uri_->shiftPathParam())) { throw new Http_Exception('http/scriptlet/context', null, Http_Exception::NOT_FOUND); } $this->m_contextUri->pushPathParam($component); if ($this->m_contextUri->hasFileExtension()) { Config::get($this->m_contextUri->getFilename(true)); } else { Config::get($component); } Http_Scriptlet::dispatch($this, $uri_); }