Example #1
0
 /**
  * Parse the given input and return either an array of attributes => values
  * or null if the input could not be parsed.
  *
  * @param Request $request the request object
  *
  * @return array|null
  */
 public function parse(Request $request)
 {
     $input = $request->getRawBody();
     if (empty($input)) {
         return null;
     }
     return $this->xmlToArray($input);
 }
Example #2
0
 /**
  * Parse the given input and return either an array of attributes => values
  * or null if the input could not be parsed.
  *
  * @param Request $request the request object
  *
  * @return array|null
  */
 public function parse(Request $request)
 {
     $input = $request->getRawBody();
     if (empty($input)) {
         return null;
     }
     ini_set('auto_detect_line_endings', true);
     $stream = fopen('php://memory', 'r+');
     fwrite($stream, $input);
     rewind($stream);
     $data = array();
     $names = null;
     $totalRows = 0;
     while (($row = fgetcsv($stream, 4096, $this->delimiter, $this->enclosure)) !== false) {
         if ($names === null) {
             $names = $row;
         } else {
             $item = array();
             foreach ($row as $key => $value) {
                 if (!isset($names[$key])) {
                     break;
                 }
                 $item[$names[$key]] = $value;
             }
             $data[] = $item;
             $totalRows++;
         }
     }
     fclose($stream);
     if ($totalRows === 0) {
         return null;
     }
     if ($totalRows === 1) {
         $data = $data[0];
     }
     return $data;
 }
Example #3
0
 /**
  * Parse the given input and return either an array of attributes => values
  * or null if the input could not be parsed.
  *
  * @param Request $request the request object
  *
  * @return array|null
  */
 public function parse(Request $request)
 {
     $data = json_decode($request->getRawBody(), true);
     return $data ? $data : null;
 }