Ejemplo n.º 1
0
 /**
  * Populates the parameter values
  *
  * @param array $call
  * @param       $data
  *
  * @return ApiMethodInfo
  *
  * @access private
  */
 protected static function populate(array $call, $data)
 {
     $call['parameters'] = $call['defaults'];
     $p =& $call['parameters'];
     $dataName = CommentParser::$embeddedDataName;
     foreach ($data as $key => $value) {
         if (isset($call['arguments'][$key])) {
             $p[$call['arguments'][$key]] = $value;
         }
     }
     if (Defaults::$smartParameterParsing) {
         if (($m = Util::nestedValue($call, 'metadata', 'param', 0)) && !array_key_exists($m['name'], $data) && array_key_exists(Defaults::$fullRequestDataName, $data) && !is_null($d = $data[Defaults::$fullRequestDataName]) && isset($m['type']) && static::typeMatch($m['type'], $d)) {
             $p[0] = $d;
         } else {
             $bodyParamCount = 0;
             $lastBodyParamIndex = -1;
             $lastM = null;
             foreach ($call['metadata']['param'] as $k => $m) {
                 if ($m[$dataName]['from'] == 'body') {
                     $bodyParamCount++;
                     $lastBodyParamIndex = $k;
                     $lastM = $m;
                 }
             }
             if ($bodyParamCount == 1 && !array_key_exists($lastM['name'], $data) && array_key_exists(Defaults::$fullRequestDataName, $data) && !is_null($d = $data[Defaults::$fullRequestDataName])) {
                 $p[$lastBodyParamIndex] = $d;
             }
         }
     }
     $r = ApiMethodInfo::__set_state($call);
     $modifier = "_modify_{$r->methodName}_api";
     if (method_exists($r->className, $modifier)) {
         $stage = end(Scope::get('Restler')->getEvents());
         if (empty($stage)) {
             $stage = 'setup';
         }
         $r = Scope::get($r->className)->{$modifier}($r, $stage) ?: $r;
     }
     return $r;
 }
Ejemplo n.º 2
0
 /**
  * Populates the parameter values
  *
  * @param array $call
  * @param       $data
  *
  * @return ApiMethodInfo
  *
  * @access private
  */
 protected static function populate(array $call, $data)
 {
     $call['parameters'] = $call['defaults'];
     $p =& $call['parameters'];
     foreach ($data as $key => $value) {
         if (isset($call['arguments'][$key])) {
             $p[$call['arguments'][$key]] = $value;
         }
     }
     if (count($p) == 1 && ($m = Util::nestedValue($call, 'metadata', 'param', 0)) && !array_key_exists($m['name'], $data) && array_key_exists(Defaults::$fullRequestDataName, $data) && !is_null($d = $data[Defaults::$fullRequestDataName]) && static::typeMatch($m['type'], $d)) {
         $p[0] = $d;
     } else {
         $bodyParamCount = 0;
         $lastBodyParamIndex = -1;
         $lastM = null;
         foreach ($call['metadata']['param'] as $k => $m) {
             if ($m['from'] == 'body') {
                 $bodyParamCount++;
                 $lastBodyParamIndex = $k;
                 $lastM = $m;
             }
         }
         if ($bodyParamCount == 1 && !array_key_exists($lastM['name'], $data) && array_key_exists(Defaults::$fullRequestDataName, $data) && !is_null($d = $data[Defaults::$fullRequestDataName]) && static::typeMatch($lastM['type'], $d)) {
             $p[$lastBodyParamIndex] = $d;
         }
     }
     return ApiMethodInfo::__set_state($call);
 }