コード例 #1
0
 /**
  * @dataProvider generateDataForTest
  * @param string $robotsTxtContent
  */
 public function testStatusCode($robotsTxtContent)
 {
     $parser = new RobotsTxtParser\TxtClient('http://example.com', 300, $robotsTxtContent);
     $this->assertTrue($parser->userAgent('*')->isAllowed("/"));
     $parser = new RobotsTxtParser\TxtClient('http://example.com', 400, $robotsTxtContent);
     $this->assertTrue($parser->userAgent('*')->isAllowed("/"));
     $parser = new RobotsTxtParser\TxtClient('http://example.com', 500, $robotsTxtContent);
     $this->assertTrue($parser->userAgent('*')->isDisallowed("/"));
 }
コード例 #2
0
ファイル: Import.php プロジェクト: vipnytt/robotstxtparser
 /**
  * Import constructor.
  *
  * @param array $export
  * @param string $baseUri
  */
 public function __construct(array $export, $baseUri = 'https://example.com')
 {
     $this->array = $this->arrayMergeRecursiveEx(self::TEMPLATE_ROOT, $export);
     foreach (array_keys($this->array[self::DIRECTIVE_USER_AGENT]) as $userAgent) {
         $this->array[self::DIRECTIVE_USER_AGENT][$userAgent] = $this->arrayMergeRecursiveEx(self::TEMPLATE_SUB, $this->array[self::DIRECTIVE_USER_AGENT][$userAgent]);
     }
     parent::__construct($baseUri, null, implode(PHP_EOL, array_merge($this->buildHost($this->array[self::DIRECTIVE_HOST]), $this->buildCleanParam($this->array[self::DIRECTIVE_CLEAN_PARAM]), $this->buildGenericArray($this->array[self::DIRECTIVE_SITEMAP], self::DIRECTIVE_SITEMAP), $this->buildUserAgent($this->array[self::DIRECTIVE_USER_AGENT]))));
 }
コード例 #3
0
ファイル: UriClient.php プロジェクト: vipnytt/robotstxtparser
 /**
  * RequestClient constructor.
  *
  * @param string $baseUri
  * @param array $curlOptions
  * @param int|null $byteLimit
  */
 public function __construct($baseUri, array $curlOptions = [], $byteLimit = self::BYTE_LIMIT)
 {
     $uriParser = new UriParser($baseUri);
     $this->base = $uriParser->base();
     if ($this->request($curlOptions) === false) {
         $this->time = time();
         $this->effective = $this->base;
         $this->rawStatusCode = null;
         $this->rawContents = '';
         $this->rawEncoding = self::ENCODING;
         $this->rawMaxAge = 0;
     }
     parent::__construct($this->base, $this->rawStatusCode, $this->rawContents, $this->rawEncoding, $this->effective, $byteLimit);
 }