/** * Returns CSV payload data * * @param null $key * @param null $default * * @return array|mixed|null * @throws \DreamFactory\Core\Exceptions\BadRequestException */ protected function csv($key = null, $default = null) { if (!empty($this->contentAsArray)) { if (null === $key) { return $this->contentAsArray; } else { return ArrayUtils::get($this->contentAsArray, $key, $default); } } $content = $this->getContent(); $data = DataFormatter::csvToArray($content); if (!empty($content) && empty($data)) { throw new BadRequestException('Invalid CSV payload supplied.'); } $payload = ResourcesWrapper::wrapResources($data); // Store the content so that formatting is only done once. $this->contentAsArray = empty($payload) ? [] : $payload; $this->content = $content; if (null === $key) { if (empty($payload)) { return []; } else { return $payload; } } else { if (empty($payload)) { return $default; } else { return ArrayUtils::get($payload, $key, $default); } } }