/** * @param Authenticator $authenticator * @return string */ public function fetch(Authenticator $authenticator = null) { if ($authenticator) { $request = new Request(static::$url, null, Request::GET, $authenticator->getSession()); $authenticator->validateAuthentication($request); } else { $request = new Request(static::$url, null, Request::GET); } return $request->getContent(); }
/** * @param Request $request * @throws Exception */ public function validateAuthentication(Request $request) { if ($request->getEffectiveUrlWithoutQueryString() === self::INDEX_URL) { if (strpos($request->getContent(), 'Nesprávné jméno nebo heslo!') !== false) { throw new Exception('Invalid credentials.', Exception::INVALID_CREDENTIALS); } elseif (strpos($request->getContent(), 'Probíhá údržba systému!') !== false) { throw new Exception('Information system maintenance. Please try again later.', Exception::MAINTENANCE); } elseif ($this->authenticationType === self::AUTH_TYPE_SESSION and strpos($request->getContent(), '<div class="loginpageinfo">') !== false) { throw new Exception('Invalid session. Hint: 24 minutes after last request session expires.', Exception::INVALID_SESSION); } } $this->authenticationSucceeded = true; }
/** * @param int $id * @return string */ public function fetch($id) { $request = new Request(self::BASE_URL . $id, null, Request::GET); return $request->getContent(); }
public function fetch($link) { $request = new Request(self::BASE_URL . '/' . $link, null, Request::GET); return $request->getContent(); }