Exemplo n.º 1
0
 /**
  * Call the method and return the results
  * @param type $version
  * @param Request $request
  * @throws Exception
  */
 public function call($version, $request = null)
 {
     if (!isset($this->versions['all']) && !isset($this->versions[$version])) {
         throw new \RuntimeException('Invalid method call');
     }
     if (!isset($this->versions[$version])) {
         $version = 'all';
     }
     if (!empty($this->verifiers)) {
         foreach ($this->verifiers as $verifier) {
             if (!Api::verify($verifier, $request)) {
                 throw new \InvalidArgumentException('Invalid API Call');
             }
         }
     }
     $call = $this->versions[$version]['callback'];
     if (!is_callable($call)) {
         $func = $this->versions[$version]['method'];
         $controllerClassname = $call;
         $controller = new $controllerClassname();
         return call_user_func_array(array($controller, $func), array($request));
     } else {
         return call_user_func_array($call, array($request));
     }
 }
Exemplo n.º 2
0
 /**
  * Require a parameter, and validate with callback
  */
 public static function validate($param_name, $validate = false, $arguments = array())
 {
     array_unshift($arguments, $param_name);
     if (is_array($validate)) {
         foreach ($validate as $validate_callback) {
             if (false === ($value = call_user_func_array($validate_callback, $arguments))) {
                 throw new ApiException(Api::lastError());
             }
         }
         return $value;
     }
     if ($validate !== false && false === ($value = call_user_func_array($validate, $arguments))) {
         throw new ApiException(Api::lastError());
     }
     return $value;
 }