client = $client; $this->login = $login; $this->password = $password; } /** * @return Client */ public function getClient() { return $this->client; } public function isConnected() { if (!$this->is_connected) { $crawler = $this->client->request('GET', self::HOME_URL); $this->is_connected = $crawler->filter('.loggedOut')->count() == 0; } return $this->is_connected; } public function connect() { if (!$this->isConnected()) { $crawler = $this->client->request('GET', self::LOGIN_URL); $form = $crawler->selectButton('Se connecter')->form(); $crawler = $this->client->submit($form, ['st_username' => $this->login, 'st_passwd' => $this->password]); $this->is_connected = $crawler->filter('.account_userinfo')->count() > 0; } return $this->is_connected; } public function getDeals() { if ($this->isConnected()) { $crawler = $this->client->request('GET', self::ACCOUNT_URL); $deals = $crawler->filter('#dashboard .list .element')->each( function ($node) { return $node->filter('.detail .title')->each( function ($n) { return $n->filter('a')->first()->attr('href'); } ); } ); return new Deals($this, $deals); } return new Deals($this, []); } }