예제 #1
0
 /**
  * Add multiple headers
  *
  * @param array<string,string> $headers
  */
 public function addMultiple(array $headers) : HeaderCollection
 {
     foreach ($headers as $key => $value) {
         $key = $this->getKey($key, true);
         \sndsgd\Arr::addValue($this->headers, $key, $value);
     }
     return $this;
 }
예제 #2
0
파일: BodyDecoder.php 프로젝트: sndsgd/http
 /**
  * Process the $_POST superglobal to spoof the results of a decoder
  *
  * @return array
  */
 protected function parsePost()
 {
     $ret = $_POST ?: [];
     if (isset($_FILES)) {
         foreach ($_FILES as $name => $info) {
             if (is_array($info["name"])) {
                 $len = count($info["name"]);
                 for ($i = 0; $i < $len; $i++) {
                     $file = $this->createUploadedFile(["name" => $info["name"][$i] ?? "", "type" => $info["type"][$i] ?? "", "tmp_name" => $info["tmp_name"][$i] ?? "", "error" => $info["error"][$i] ?? 0, "size" => $info["size"][$i] ?? 0]);
                     \sndsgd\Arr::addValue($ret, $name, $file);
                 }
             } else {
                 $file = $this->createUploadedFile($info);
                 \sndsgd\Arr::addValue($ret, $name, $file);
             }
         }
     }
     return $ret;
 }
예제 #3
0
 /**
  * Add more data to the query
  * 
  * @param string|array $data
  * @return \sndsgd\Url
  */
 public function addQueryData($data)
 {
     if (is_string($data)) {
         $data = self::decodeQueryString($data);
     } else {
         if (is_object($data)) {
             $data = (array) $data;
         } else {
             if (!is_array($data)) {
                 throw new InvalidArgumentException("invalid value provided for 'query'; " . "expecting a string, array, or object");
             }
         }
     }
     foreach ($data as $k => $v) {
         Arr::addValue($this->query, $k, $v);
     }
     return $this;
 }
예제 #4
0
파일: Collection.php 프로젝트: sndsgd/http
 /**
  * Add a value that has a nested key
  *
  * @param string $key
  * @param mixed $value
  * @param integer $pos The position of the first open bracket
  */
 protected function addNestedValue(string $key, $value, int $pos)
 {
     # convert the levels into an array of strings
     $levels = strpos($key, "][") !== false ? explode("][", substr($key, $pos + 1, -1)) : [substr($key, $pos + 1, -1)];
     array_unshift($levels, substr($key, 0, $pos));
     # ensure the nesting doesn't exceed `max_nesting_levels`
     $levelLen = count($levels);
     if ($levelLen > $this->maxNestingLevels) {
         throw new DecodeException("max_input_nesting_level exceeded");
     }
     $lastKey = array_pop($levels);
     $values =& $this->values;
     foreach ($levels as $level) {
         if ($level === "") {
             $level = count($values);
         }
         if (!array_key_exists($level, $values)) {
             $values[$level] = [];
         }
         $values =& $values[$level];
     }
     if ($lastKey === "") {
         $lastKey = count($values);
     }
     \sndsgd\Arr::addValue($values, $lastKey, $value);
 }