コード例 #1
0
ファイル: Rate.php プロジェクト: apioo/fusio-impl
 public function getRateForRequest($routeId, Model\App $app)
 {
     $sql = '    SELECT rate.rateLimit,
                        rate.timespan
                   FROM fusio_rate_allocation rateAllocation
             INNER JOIN fusio_rate rate
                     ON rateAllocation.rateId = rate.id 
                  WHERE rate.status = :status
                    AND (rateAllocation.routeId IS NULL OR rateAllocation.routeId = :routeId)
                    AND (rateAllocation.appId IS NULL OR rateAllocation.appId = :appId)
                    AND (rateAllocation.authenticated IS NULL OR rateAllocation.authenticated = :authenticated)';
     $params = ['status' => self::STATUS_ACTIVE, 'routeId' => $routeId, 'appId' => $app->getId(), 'authenticated' => $app->isAnonymous() ? 0 : 1];
     $parameters = $app->getParameters();
     if (!empty($parameters)) {
         $sql .= ' AND (rateAllocation.parameters IS NULL OR ';
         $sql .= $this->connection->getDatabasePlatform()->getLocateExpression(':parameters', 'rateAllocation.parameters');
         $sql .= ' > 0)';
         $params['parameters'] = http_build_query($parameters, '', '&');
     }
     $sql .= ' ORDER BY rate.priority DESC';
     return $this->connection->fetchAssoc($sql, $params);
 }
コード例 #2
0
ファイル: Rate.php プロジェクト: apioo/fusio-impl
 /**
  * @param string $ip
  * @param string $timespan
  * @param \Fusio\Engine\Model\App $app
  * @return integer
  */
 protected function getRequestCount($ip, $timespan, Model\App $app)
 {
     if (empty($timespan)) {
         return 0;
     }
     $now = new \DateTime();
     $past = new \DateTime();
     $past->sub(new \DateInterval($timespan));
     $condition = new Condition();
     if ($app->isAnonymous()) {
         $condition->equals('ip', $ip);
     } else {
         $condition->equals('appId', $app->getId());
     }
     $condition->between('date', $past->format('Y-m-d H:i:s'), $now->format('Y-m-d H:i:s'));
     return $this->logTable->getCount($condition);
 }