Exemplo n.º 1
0
 /**
  * @inheritDoc
  */
 public function delete($id)
 {
     try {
         return apc_delete($this->prefix . $id);
     } catch (\Exception $e) {
         ErrorHandler::log($e);
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function removeVersions($name, array $versions)
 {
     $basePath = dirname($this->path . $name) . '/';
     foreach ($versions as $v) {
         try {
             unlink($basePath . $v);
         } catch (\Exception $e) {
             ErrorHandler::log($e);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Handles request and echos response to client
  * @param array $path
  * @param null|RequestController $controller
  */
 public function dispatch($path, $controller = null)
 {
     try {
         $db = DB::instance($this->config('application.db'));
         $cache = Cache::instance($this->config('application.cache'));
         if ($controller === null) {
             $controller = new RequestController($this, $db, $cache);
         } else {
             $controller->setDatabase($db);
             $controller->setCache($cache);
         }
         // override output content-type in runtime using file extension
         if ($this->config('application.allow_output_extensions') !== false) {
             $path_last_index = count($path) - 1;
             if ($ext = pathinfo($path[$path_last_index], PATHINFO_EXTENSION)) {
                 $this->config('application.output', $ext);
                 $path[$path_last_index] = pathinfo($path[$path_last_index], PATHINFO_FILENAME);
             }
         }
         $controller->handle($path);
     } catch (DuplicationException $e) {
         $response = new OperationResponse(409, array('error' => 'An action causing data duplication was found: ' . $e->getMessage()));
         $controller = new RequestController($this, null, null);
         $controller->handleResponse($response);
     } catch (\InvalidArgumentException $e) {
         $response = new OperationResponse(400, array('error' => $e->getMessage()));
         $controller = new RequestController($this, null, null);
         $controller->handleResponse($response);
     } catch (\Exception $e) {
         ErrorHandler::log($e);
         $mess = array('message' => $e->getMessage());
         if ($this->config('mode') == 'development') {
             $mess['trace'] = $e->getTraceAsString();
         }
         $response = new OperationResponse(500, $mess);
         $controller = new RequestController($this, null, null);
         $controller->handleResponse($response);
     }
 }