public function setResponse(__IResponse &$response) { $response->prepareToSleep(); $this->_response =& $response; $this->_view_codes = array(); $view_codes = $response->getViewCodes(); foreach ($view_codes as $view_code) { $this->_view_codes[$view_code] = true; } }
public function write(__IResponse &$response) { switch ($this->_position) { case self::POSITION_TOP: $response->dockContentOnTop($this->getContent(), $this->getId()); break; case self::POSITION_BOTTOM: $response->dockContentAtBottom($this->getContent(), $this->getId()); break; case self::POSITION_EMBEDDED: $response->placeContentAfterElement($this->getContent(), $this->getElementToPlaceContentAfter(), $this->getId()); break; default: $response->addContent($this->getContent(), $this->getId()); break; } }
/** * This method process an AJAX request * */ public function processRequest(__IRequest &$request, __IResponse &$response) { try { $return_value = $this->_resolveAndCallRemoteService($request); if ($return_value !== null) { if (function_exists('json_encode')) { $return_value = json_encode($return_value); } else { $services_json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); $return_value = $services_json->encode($return_value); } } $response->addContent($return_value); } catch (Exception $e) { $response->addHeader("HTTP/1.0 500 Internal Server Error"); $response->addContent(json_encode($e->getMessage())); } }
protected function _setResponseToCache(__IRequest &$request, __IResponse &$response) { $uri = $request->getUri(); if ($uri != null) { $route = $uri->getRoute(); if ($route != null) { if ($route->getCache()) { //only cache anonymous view: if ($response->isCacheable()) { $response_snapshot = new __ResponseSnapshot($response); $cache = __ApplicationContext::getInstance()->getCache(); $cache->setData('responseSnapshot::' . $request->getUniqueCode(), $response_snapshot, $route->getCacheTtl()); } } else { if ($route->getSuperCache()) { //only cache anonymous view: if ($response->isCacheable()) { $target_url_components = parse_url($uri->getAbsoluteUrl()); $path = $target_url_components['path']; $dir = dirname($path); $file = basename($path); $response_content = $response->getContent() . "\n<!-- supercached -->"; $cache_ttl = $route->getCacheTtl(); $server_dir = $_SERVER['DOCUMENT_ROOT'] . $dir; if (is_dir($server_dir) && is_writable($server_dir)) { $file_handler = fopen($server_dir . DIRECTORY_SEPARATOR . $file, "w+"); fputs($file_handler, $response_content); fclose($file_handler); } else { $exception = __ExceptionFactory::getInstance()->createException('Directory not found to supercache: ' . $server_dir); __ErrorHandler::getInstance()->logException($exception); } } } } } } }
public function write(__IResponse &$response) { $response->dockContentAtBottom($this->getContent()); }
public function write(__IResponse &$response) { $response->dockContentOnTop($this->getContent(), $this->getId()); }