Example #1
0
 /**
  * @param string $query
  * @param int $limit
  * @param int $offset
  * @return string
  * @throws ValidationFailedException
  */
 public function addLimit($query, $limit = 0, $offset = 0)
 {
     $limits = $this->limitService->getLimits();
     if ($this->hasLimit($query)) {
         $limit = $this->getLimitFromQuery($query);
         if ($limit <= 0 || $limits["row"] < $limit) {
             throw new ValidationFailedException("The written limit is off limits", 500);
         }
     } else {
         if ($limit <= 0 || $limits["row"] < $limit) {
             $limit = $limits["row"];
         }
         $offset = $this->getOffset($offset);
         $query = "({$query}) LIMIT {$limit} OFFSET {$offset};";
     }
     return $query;
 }
 /**
  * @param int $timeLimit
  * @param string $connectionName
  * @return bool|int|number
  */
 public function getMaxTime($timeLimit = 0, $connectionName = 'default')
 {
     $this->validateConnection($connectionName);
     $this->dynamicRepo->setUp($connectionName);
     $time = $this->dynamicRepo->isMaxExecutionSet();
     $configLimits = $this->limits->getLimits();
     if (is_numeric($time) && $time !== 0) {
         if ($timeLimit > 0 && $time > $timeLimit) {
             return $timeLimit;
         }
         return $time;
     }
     $limit = $timeLimit > 0 && $timeLimit <= $configLimits["time"] ? $timeLimit : $configLimits["time"];
     if (is_string($time)) {
         // limit is in seconds!
         $this->dynamicRepo->setMaxExecutionTime($configLimits["time"], $time);
     }
     return $limit;
 }