/** * Updates the browscap ini file to the latest version * * @throws Gass\Exception\RuntimeException */ private function updateIniFile() { $browsCapLocation = $this->getOption('browscap'); $directory = dirname($browsCapLocation); if (!@file_exists($directory) && !mkdir($directory, 0777, true) || !@is_writable($directory)) { throw new Exception\RuntimeException('The directory "' . $directory . '" is not writable, ' . 'please ensure this file can be written to and try again.'); } $currentHttpUserAgent = Http\Http::getInstance()->getUserAgent(); if ($currentHttpUserAgent === null || '' == trim($currentHttpUserAgent)) { throw new Exception\RuntimeException(__CLASS__ . ' cannot be initialised before a user-agent has been set in the Gass\\Http adapter.' . ' The remote server rejects requests without a user-agent.'); } $browscapSource = Http\Http::getInstance()->request(self::BROWSCAP_URL)->getResponse(); $browscapContents = trim($browscapSource); if (empty($browscapContents)) { throw new Exception\RuntimeException('browscap ini file retrieved from external source seems to be empty. ' . 'Please either set botInfo to null or ensure the full_php_browscap.ini file can be retrieved.'); } if (false === @file_put_contents($browsCapLocation, $browscapContents)) { throw new Exception\RuntimeException('Could not write to "' . $browsCapLocation . '", please check the permissions and try again.'); } }
/** * Retrieves the bots csv from the default source * * @return string * @throws Gass\Exception\RuntimeException */ private function getFromWeb() { $csvSource = Http\Http::getInstance()->request(self::CSV_URL)->getResponse(); $botsCsv = trim($csvSource); if (empty($botsCsv)) { throw new Exception\RuntimeException('Bots CSV retrieved from external source seems to be empty. ' . 'Please either set botInfo to null or ensure the bots csv file can be retrieved.'); } return $botsCsv; }