setCookie(SetCookie::fromString($cookie)); $client = new Client(['cookies' => $cookieJar]); } try { $response = $client->get($url)->getBody()->getContents(); } catch (RequestException $e) { if ($e->hasResponse()) { if ($e->getCode() === 404) { ColorCLI::doEcho(ColorCLI::notice('Data not available on server')); } elseif ($e->getCode() === 503) { ColorCLI::doEcho(ColorCLI::notice('Service unavailable')); } else { ColorCLI::doEcho(ColorCLI::notice('Unable to fetch data from server, http error reported: '.$e->getCode())); } } } catch (\RuntimeException $e) { ColorCLI::doEcho(ColorCLI::notice('Runtime error: '.$e->getCode())); } return $response; } } if (! function_exists('makeFieldLinks')) { /** * @param $data * @param $field * @param $type * @return string */ function makeFieldLinks($data, $field, $type) { $tmpArr = explode(', ', $data[$field]); $newArr = []; $i = 0; foreach ($tmpArr as $ta) { if (trim($ta) === '') { continue; } if ($type === 'xxx' && $field === 'genre') { $ta = (new XXX())->getGenres(true, $ta); $ta = $ta['title']; } if ($i > 7) { break; } $newArr[] = ''.$ta.''; $i++; } return implode(', ', $newArr); } }