src/Mcfedr/TwitterPushBundle/Service/TweetPusher.php
/**
     * Send a tweet to everyone
     *
     * @param array $tweet
     * @throws MaxPushesPerHourException
     * @throws \Mcfedr\AwsPushBundle\Exception\PlatformNotConfiguredException
     */
Send a tweet to everyone
@param array $tweet
@throws MaxPushesPerHourException
@throws \Mcfedr\AwsPushBundle\Exception\PlatformNotConfiguredException
Send a tweet to everyone @param array $tweet @throws MaxPushesPerHourException @throws \ Mcfedr \ AwsPushBundle \ Exception \ PlatformNotConfiguredException
public function pushTweet($tweet)
    {
        if ($this->maxPushesPerHour > 0 && $this->cache) {
            $hourAgo = new \DateTime('- 1 hour');
            $tweetTimes = $this->cache->fetch(static::CACHE_KEY) ?: [];
            foreach ($tweetTimes as $k => $time) {
                if ($time < $hourAgo) {
                    unset($tweetTimes[$k]);
                }
            }
            if (($count = count($tweetTimes)) >= $this->maxPushesPerHour) {
                throw new MaxPushesPerHourException("Cannot send push, $count have already been sent. The limit is {$this->maxPushesPerHour}");
            }
            $tweetTimes[] = new \DateTime();
            $this->cache->save(static::CACHE_KEY, $tweetTimes, 3600);
        }
        $m = $this->getMessageForTweet($tweet);
        if ($this->topicArn) {
            $this->messages->send($m, $this->topicArn);
        } else {
            $this->messages->broadcast($m);
        }
    }
public function pushTweet ( $ tweet ) { if ( $ this -> maxPushesPerHour > 0 && $ this -> cache ) { $ hourAgo = new \ DateTime ( '- 1 hour' ) ; $ tweetTimes = $ this -> cache -> fetch ( static :: CACHE_KEY ) ? : [ ] ; foreach ( $ tweetTimes as $ k => $ time ) { if ( $ time < $ hourAgo ) { unset ( $ tweetTimes [ $ k ] ) ; } } if ( ( $ count = count ( $ tweetTimes ) ) >= $ this -> maxPushesPerHour ) { throw new MaxPushesPerHourException ( " Cannot send push,  $ count  have already been sent. The limit is  { $ this -> maxPushesPerHour } " ) ; } $ tweetTimes [ ] = new \ DateTime ( ) ; $ this -> cache -> save ( static :: CACHE_KEY , $ tweetTimes , 3600 ) ; } $ m = $ this -> getMessageForTweet ( $ tweet ) ; if ( $ this -> topicArn ) { $ this -> messages -> send ( $ m , $ this -> topicArn ) ; } else { $ this -> messages -> broadcast ( $ m ) ; } }
Send a tweet to everyone
 @param array $tweet
 @throws MaxPushesPerHourException
 @throws \Mcfedr\AwsPushBundle\Exception\PlatformNotConfiguredException
Send a tweet to everyone @param array $tweet @throws MaxPushesPerHourException @throws \ Mcfedr \ AwsPushBundle \ Exception \ PlatformNotConfiguredException
/** @var \DateTime[] $tweetTimes */