public function rateLimit($applicationId, $userId)
	{
		// load limit data, creating initial record if doesnt exist
		if (!$data = $this->storage->getRateLimitData($applicationId, $userId))
		{
			$data = $this->createRateLimitData($applicationId, $userId);
		}

		// check if we can reset short expiration
		if (time() > with(new Date($data->expires_short))->toUnix())
		{
			$newShortDate = $this->getNewExpiresDateString('short');
			$this->storage->resetShort($data->id, 0, $newShortDate);
		}

		// check if we can reset long expiration
		if (time() > with(new Date($data->expires_long))->toUnix())
		{
			$newLongDate = $this->getNewExpiresDateString('long');
			$this->storage->resetLong($data->id, 0, $newLongDate);
		}

		// increment data then refetch
		$this->storage->incrementRateLimitData($data->id);

		// refetch record after incrementing
		$data = $this->storage->getRateLimitData($applicationId, $userId);

		// check to see if were over short or long limits
		$data->exceeded_short = false;
		$data->exceeded_long  = false;
		if ($data->count_short >= $data->limit_short)
		{
			$data->exceeded_short = true;
		}
		if ($data->count_long >= $data->limit_long)
		{
			$data->exceeded_long = true;
		}

		// return data
		return $data;
	}
public function rateLimit($applicationId, $userId)
	{
		// load limit data, creating initial record if doesnt exist
		if (!$data = $this->storage->getRateLimitData($applicationId, $userId))
		{
			$data = $this->createRateLimitData($applicationId, $userId);
		}

		// check if we can reset short expiration
		if (time() > with(new Date($data->expires_short))->toUnix())
		{
			$newShortDate = $this->getNewExpiresDateString('short');
			$this->storage->resetShort($data->id, 0, $newShortDate);
		}

		// check if we can reset long expiration
		if (time() > with(new Date($data->expires_long))->toUnix())
		{
			$newLongDate = $this->getNewExpiresDateString('long');
			$this->storage->resetLong($data->id, 0, $newLongDate);
		}

		// increment data then refetch
		$this->storage->incrementRateLimitData($data->id);

		// refetch record after incrementing
		$data = $this->storage->getRateLimitData($applicationId, $userId);

		// check to see if were over short or long limits
		$data->exceeded_short = false;
		$data->exceeded_long  = false;
		if ($data->count_short >= $data->limit_short)
		{
			$data->exceeded_short = true;
		}
		if ($data->count_long >= $data->limit_long)
		{
			$data->exceeded_long = true;
		}

		// return data
		return $data;
	}
public function rateLimit ( $ applicationId , $ userId ) { // load limit data, creating initial record if doesnt exist if ( ! $ data = $ this -> storage -> getRateLimitData ( $ applicationId , $ userId ) ) { $ data = $ this -> createRateLimitData ( $ applicationId , $ userId ) ; } // check if we can reset short expiration if ( time ( ) > with ( new Date ( $ data -> expires_short ) ) -> toUnix ( ) ) { $ newShortDate = $ this -> getNewExpiresDateString ( 'short' ) ; $ this -> storage -> resetShort ( $ data -> id , 0 , $ newShortDate ) ; } // check if we can reset long expiration if ( time ( ) > with ( new Date ( $ data -> expires_long ) ) -> toUnix ( ) ) { $ newLongDate = $ this -> getNewExpiresDateString ( 'long' ) ; $ this -> storage -> resetLong ( $ data -> id , 0 , $ newLongDate ) ; } // increment data then refetch $ this -> storage -> incrementRateLimitData ( $ data -> id ) ; // refetch record after incrementing $ data = $ this -> storage -> getRateLimitData ( $ applicationId , $ userId ) ; // check to see if were over short or long limits $ data -> exceeded_short = false ; $ data -> exceeded_long = false ; if ( $ data -> count_short >= $ data -> limit_short ) { $ data -> exceeded_short = true ; } if ( $ data -> count_long >= $ data -> limit_long ) { $ data -> exceeded_long = true ; } // return data return $ data ; }
Rate limit for application & user

@param   int    $applicationId  Application identifier
@param   int    $userId         User identifier
@return  array  Array of rate limit data
Rate limit for application & user