Exemplo n.º 1
0
 /**
  * Validate SerpScraper constructor arguments.
  * @param  array  $keywords
  * @param  string $outDir
  * @param  string $fetcherCacheDir
  * @param  string $serializerCacheDir
  * @param  int    $cacheTTL
  * @param  int    $requestDelay
  */
 public static function checkArgs($keywords, $outDir, $fetcherCacheDir, $serializerCacheDir, $cacheTTL, $requestDelay)
 {
     if (!\Franzip\SerpScraper\Helpers\KeywordValidator::validKeywords($keywords)) {
         throw new \Franzip\SerpScraper\Exceptions\InvalidArgumentException('Invalid SerializableSerpPage $keywords: please supply a sequential non-empty array of strings.');
     }
     if (!self::validateDirName($outDir)) {
         throw new \Franzip\SerpScraper\Exceptions\InvalidArgumentException('Invalid SerializableSerpPage $outDir: please supply a non empty string.');
     }
     if (!self::validateDirName($fetcherCacheDir)) {
         throw new \Franzip\SerpScraper\Exceptions\InvalidArgumentException('Invalid SerializableSerpPage $fetcherCacheDir: please supply a non empty string.');
     }
     if (!self::validateDirName($serializerCacheDir)) {
         throw new \Franzip\SerpScraper\Exceptions\InvalidArgumentException('Invalid SerializableSerpPage $serializerCacheDir: please supply a non empty string.');
     }
     if (!\Franzip\SerpScraper\Helpers\FileSystemHelper::preventCacheCollision($outDir, $fetcherCacheDir, $serializerCacheDir)) {
         throw new \Franzip\SerpScraper\Exceptions\InvalidArgumentException('Invalid SerializableSerpPage $outDir, $fetcherCacheDir, $serializerCacheDir: cannot share the same folder for different caches. Please supply different folders path for different caches.');
     }
     if (!self::validateExpirationTime($cacheTTL)) {
         throw new \Franzip\SerpScraper\Exceptions\InvalidArgumentException('Invalid SerializableSerpPage $cacheTTL: please supply a positive integer.');
     }
     if (!self::validateExpirationTime($requestDelay)) {
         throw new \Franzip\SerpScraper\Exceptions\InvalidArgumentException('Invalid SerializableSerpPage $requestDelay: please supply a positive integer.');
     }
 }
Exemplo n.º 2
0
 /**
  * Set the path to the folder used to store the fetcher cache.
  * @param   string
  * @return  bool
  */
 public function setFetcherCacheDir($dir)
 {
     if (SerpScraperHelper::validateDirName($dir) && FileSystemHelper::preventCacheCollision($this->outDir, $dir, $this->serializerCacheDir)) {
         $this->fetcherCacheDir = $dir;
         FileSystemHelper::setUpDir($dir);
         return true;
     }
     return false;
 }