/** * @param $edge * @param string $method * @param array $params * @return Request */ public function request($edge, $method = 'get', $params = []) { if (!in_array(strtolower($method), ['get', 'post', 'put', 'delete'])) { throw new \InvalidArgumentException(sprintf('Unknown method %s', $method)); } $request = new Request($edge, $method, $params); $request->setOptions($this->options)->setOption(CURLOPT_USERAGENT, $this->user_agent); return $request; }
/** * @inheritdoc */ public function request(Request $request, $callback) { $crawler = $this; $request->setOptions(\array_merge($this->getOptions(), $request->getOptions())); $this->tasksIndex++; $this->tasks[$this->tasksIndex] = new Task($this->tasksIndex, $request, new Response($request->url), function (Task $task) use($crawler, $callback) { if ($callback && \is_callable($callback)) { \call_user_func_array($callback, [$task->getRequest(), $task->getResponse()]); } $crawler->remove($task); }); return $this->tasks[$this->tasksIndex]; }
/** * Create new Request and add it to the request queue * * @param string $url * @param string $method * @param array|string $postData * @param array $headers * @param array $options * @return RollingCurl */ public function request($url, $method = "GET", $postData = null, $headers = null, $options = null) { $newRequest = new Request($url, $method); if ($postData) { $newRequest->setPostData($postData); } if ($headers) { $newRequest->setHeaders($headers); } if ($options) { $newRequest->setOptions($options); } return $this->add($newRequest); }
function clearCloudFlareCache(array $modifiedFiles, $email, $key, $identifier) { $req = new Request("https://api.cloudflare.com/client/v4/zones/{$identifier}/purge_cache"); foreach (array_chunk($modifiedFiles, 30) as $mods) { $req->setOptions(['customRequest' => 'DELETE', 'verbose' => true, 'httpHeader' => ["X-Auth-Email: {$email}", "X-Auth-Key: {$key}", 'Content-Type: application/json'], 'postFields' => json_encode(['files' => $mods])]); $req->send(); } }