/** * Fetches all events in a date range * * @param \DateTime $startDate * @param \DateTime $endDate * * @return Event array */ public function fetchEvents(\DateTime $startDate, \DateTime $endDate) { $events = array(); $client = $this->client->getClient(); $uri = self::IS_URL . '/eplug/agenda/agenda.asp'; $body = array('NumDat' => null, 'TypVis' => 'Vis-Tab.xsl'); for ($date = new \DateTime($startDate->format('Y-m')); $date < $endDate; $date->modify("+1 month")) { $body['NumDat'] = $date->format('Ym'); $request = $client->post($uri, null, $body); foreach ($this->client->getCookieJar()->allRawValues($uri) as $name => $value) { $request->addCookie($name, $value); } $requests[] = $request; } $responses = $client->send($requests); foreach ($responses as $response) { $crawler = new Crawler(null, $uri); $crawler->addContent($response->getBody(true), $response->getHeader('Content-Type')); $events = array_merge(self::extractEvents($crawler), $events); } // Filter out events that are not in the date range $events = array_filter($events, function ($event) use($startDate, $endDate) { return $event->startDate > $startDate && $event->startDate < $endDate; }); return $events; }