for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace vipnytt\RobotsTxtParser\Modules;
use GuzzleHttp;
use vipnytt\RobotsTxtParser\RobotsTxtInterface;
/**
* Class Download
*
* @package vipnytt\RobotsTxtParser\Modules
*/
class Download implements RobotsTxtInterface
{
use UrlTools;
private $response;
* Download constructor.
* @param string $url
public function __construct($url)
$client = new GuzzleHttp\Client(
[
'base_uri' => $this->urlBase($url),
'max' => self::MAX_REDIRECTS,
]
);
$this->response = $client->request('GET', '/robots.txt');
}
* Status code
* @return int
public function getStatusCode()
return $this->response->getStatusCode();
* Encoding
* @return string
public function getEncoding()
$header = $this->response->getHeader('content-type')[0];
$split = array_map('trim', mb_split(';', $header));
foreach ($split as $string) {
if (($pos = mb_stripos($string, 'charset=')) !== false) {
return mb_split('=', $string, 2)[1];
return $this->detectEncoding();
* Manually detect encoding
protected function detectEncoding()
if (($encoding = mb_detect_encoding($this->getBody())) !== false) {
return $encoding;
return self::ENCODING;
* URL content
public function getBody()
return $this->response->getBody()->getContents();