/**
  * @throws RESTCommandResolverException
  * @param RESTRequest $request
  * @return RESTCommand
  */
 public function getCommand(RESTRequest $request)
 {
     $resource = implode("", array_map(function ($part) {
         return ucfirst($part);
     }, explode('_', $request->getResource())));
     $class = 'RESTCommand' . ucfirst($resource);
     if (!class_exists($class)) {
         throw new RESTCommandResolverException('Resource "' . $resource . '" does not exist');
     }
     return new $class();
 }
 /**
  * @throws RESTCommandResolverException
  * @param RESTRequest $request
  * @return RESTCommand
  */
 public function getCommand(RESTRequest $request)
 {
     //For php >= 5.3.0
     /*$resource = implode(array_map(function($part){
           return ucfirst($part);
       },explode('_', $request->getResource())));*/
     $resource = '';
     foreach (explode('_', $request->getResource()) as $part) {
         $resource .= ucfirst($part);
     }
     $class = 'RESTCommand' . ucfirst($resource);
     if (!class_exists($class)) {
         throw new RESTCommandResolverException('Resource "' . $class . '" does not exist');
     }
     return new $class();
 }
 public static function handleRequest()
 {
     $result = null;
     $response = new RESTResponse();
     try {
         $request = new RESTRequest();
         if ($request->getAction() != 'get' || !in_array($request->getResource(), array('vclub', 'karaoke'))) {
             self::checkAccess($request->getAccessToken());
         }
         $cmd_r = new RESTCommandResolver();
         $cmd = $cmd_r->getCommand($request);
         $result = $cmd->execute($request);
     } catch (Exception $e) {
         $response->setError($e->getMessage());
     }
     $response->setBody($result);
     $response->send();
 }