public final function __construct(\HttpAdapter $adapter, \LogInterface &$log = NULL) { if (!$adapter->getRequestVariables()) { throw new \Exception("Unable to perform injection without any request variables set in the http adapter!"); } $this->_httpAdapter = $adapter; if (!is_null($log)) { $this->setLog($log); } }
public function __construct(\HttpAdapter $httpAdapter, \LogInterface $log = NULL) { if (is_null($httpAdapter->getUrl())) { throw new \Exception("URL Must be set in the adapter before passing it to the crawler"); } $host = $this->parseUrl($httpAdapter->getUrl()); $this->_host = $host; $this->_httpAdapter = $httpAdapter; if (!is_null($log)) { $this->setLog($log); } $this->log("Normalized URL: " . $host["scheme"] . "://" . $host["host"] . $host["path"] . $host["page"], "0", "light_green"); $this->_httpAdapter->setUrl($host["scheme"] . "://" . $host["host"] . $host["path"] . $host["page"]); }
/** * @param string $url * @return mixed */ public function get($url) { $filePath = $this->getFilePath(); if (file_exists($filePath)) { $lastMod = filemtime($filePath); // cache is valid if (date('mdY') == date('mdY', $lastMod)) { return file_get_contents($filePath); } } else { touch($filePath); } // cache outdated $content = parent::get($url); file_put_contents($filePath, $content); return $content; }
/** * {@inheritdoc} */ public function sendRequests(array $requests) { return $this->adapter->sendRequests($requests); }