/**
  * Validate params.
  * 
  * @author Alberto Miranda <*****@*****.**>
  * @param array $params
  */
 private function validateParams($params)
 {
     if (empty($params)) {
         ErrorHandler::handle(__CLASS__ . ": Empty params!");
     }
     if (!is_array($params)) {
         ErrorHandler::handle(__CLASS__ . ": Invalid params, not array: " . print_r($params, true));
     }
     $requiredKeys = array('name');
     foreach ($requiredKeys as $key) {
         if (!array_key_exists($key, $params)) {
             ErrorHandler::handle(__CLASS__ . ": Required param not found: '{$key}'. Invalid params: " . print_r($params, true));
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Actual Dispatcher method.
  * Calls service passing params.
  * 
  * @author Alberto Miranda <*****@*****.**>
  */
 public function dispatch()
 {
     $service = $this->getService();
     $serviceClass = "{$service}Service";
     $localPath = dirname(__FILE__) . '/..';
     $servicesPath = $this->getServicesPath();
     $serviceFile = "{$localPath}/{$servicesPath}/{$serviceClass}.class.php";
     if (!file_exists($serviceFile)) {
         ErrorHandler::handle(__CLASS__ . ": Oops! Service '{$service}' not found! Service file: {$serviceFile}");
     }
     //require, call and return
     require $serviceFile;
     if (!class_exists($serviceClass)) {
         ErrorHandler::handle(__CLASS__ . ": Service class '{$serviceClass}' not exists!");
     }
     $service = new $serviceClass($this->getParams());
     $method = $this->getMethod();
     if (!method_exists($service, $method)) {
         ErrorHandler::handle(__CLASS__ . ": Service method '{$method}' not exists!");
     }
     return $service->{$method}($this->getParams());
 }
Exemplo n.º 3
0
 private static function humanizeResponse($rawData, $format = self::FORMAT_JSON)
 {
     if (true === isset($rawData['sys-error'])) {
         return $rawData;
     }
     switch ($format) {
         case self::FORMAT_JSON:
             $out = JsonResponseParser::parse($rawData);
             break;
         default:
             $out = $rawData;
     }
     if (true === is_array($out) && true === isset($out['error'])) {
         return ErrorHandler::handle($out['error']);
     }
     return $out;
 }