コード例 #1
0
 /**
  * This method return a singleton instance of __ErrorHandler
  *
  * @return error _manager A singleton reference to the __ErrorHandler
  */
 public static function &getInstance()
 {
     if (self::$_instance == null) {
         // Use "Lazy initialization"
         self::$_instance = new __ErrorHandler();
     }
     return self::$_instance;
 }
コード例 #2
0
 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);
                         }
                     }
                 }
             }
         }
     }
 }