/**
  * Costruisce una nuova istanza e recupera la lista dei tweet, eventualmente limita
  * al numero passato come parametro.
  * @param int $limit Numero massimo di tweet da considerare
  * @throws InvalidConfigException
  */
 public function __construct($limit = null)
 {
     parent::__construct();
     if (!Yii::$app->twitter->screenName || !Yii::$app->twitter->hashtag) {
         throw new InvalidConfigException('Componente Twitter: parametri di configurazione mancanti.');
     }
     $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
     $getfield = '?count=3200&screen_name=' . Yii::$app->twitter->screenName;
     $requestMethod = 'GET';
     $tweets = json_decode($this->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest());
     if (!isset($tweets->errors)) {
         if (isset($limit) && (int) $limit > 0) {
             $limit = (int) $limit;
         } else {
             $limit = 3200;
         }
         # Scorro tutti i tweets e controllo se sono già presenti nel database.
         foreach ($tweets as $tw) {
             foreach ($tw->entities->hashtags as $ht) {
                 if ($ht->text === Yii::$app->twitter->hashtag) {
                     $tweet = TwitterTweet::CreateFromObj($tw);
                     if ($tweet === true) {
                         break 2;
                     }
                     # trovato tweet già presente nel db: inutile continuare!
                 }
             }
         }
     }
     # Restituisco la lista dei tweets (tutti o gli ultimi se impostato il $limit)
     $query = TwitterTweet::find()->orderBy(['created' => SORT_DESC]);
     if ($limit) {
         $query->limit($limit);
     }
     $this->_tweets = $query->all();
     $this->_tweets_index = 0;
 }