/**
  * @param string $object
  * @throws TypeNotValidException
  */
 public function setObject($object)
 {
     if (!is_string($object)) {
         $description = ExceptionMessage::TYPE_NOT_VALID("CronExpressionValidator was not given an string\n            value at the setObject function");
         throw new TypeNotValidException($description, 500);
     }
     $this->expression = $object;
 }
Example #2
0
 /**
  * @param Finder $finder
  * @return SplFileInfo
  * @throws NotFoundException
  * @throws SnapshotException
  */
 protected function getFirstMatch(Finder $finder)
 {
     try {
         foreach ($finder as $file) {
             /** @var SplFileInfo $file */
             return $file;
         }
     } catch (InvalidArgumentException $e) {
         throw new SnapshotException(ExceptionMessage::QUERY_IS_NOT_FETCHING);
     }
     throw new NotFoundException(ExceptionMessage::INSTANCE_NOT_FOUND("The requested snapshot was not located"), 404);
 }
Example #3
0
 /**
  * @param QueryRequest $qr
  * @return array
  * @throws TypeNotValidException
  * @throws ValidationFailedException
  */
 public function getResults(QueryRequest $qr)
 {
     // if the query request is cached then call the cached version!
     $configurations = ["time" => $qr->getConfig()->getExecutionLimit(), "rows" => $qr->getConfig()->getQueryLimit(), "chartType" => $qr->getConfig()->getTypeOfChart(), "offset" => $qr->getConfig()->getOffset(), "connection" => $qr->getConfig()->getDatabaseConnection(), "cronExpression" => $qr->getCronExpression()];
     if ($this->hasDependency(LiveStrategy::DEPENDENCY_NAME)) {
         try {
             $dependencies = $this->getDependencies();
             /** @var QueryValidatorService $queryValidator */
             $queryValidator = $dependencies[LiveStrategy::DEPENDENCY_NAME];
             $query = $qr->getQuery()->getQuery();
             $queryValidator->isValidQuery($query, $configurations["connection"]);
             $results = $queryValidator->validateQueryExecution($query, $configurations);
             return $results;
         } catch (OffLimitsException $e) {
             $exception = new ValidationFailedException("Query validation has failed. {$e->getMessage()}", $e->getCode(), $e);
             throw $exception;
         }
     }
     throw new TypeNotValidException(ExceptionMessage::DEPENDENCY_NOT_AVAILABLE(", QueryValidator was absent"), 500);
 }
Example #4
0
 /**
  * @param null $directoryId
  * @return \Doctrine\ORM\Query
  * @throws TypeNotValidException
  */
 protected function getQueryByDirectory($directoryId = null)
 {
     if (!is_null($directoryId)) {
         if (is_numeric($directoryId)) {
             //query for it
             $queryBuilder = $this->createQueryBuilder('q');
             $queryBuilder->join("q.directory", "d")->where("d.id = :dirId")->setParameter('dirId', $directoryId);
             return $queryBuilder->getQuery();
         }
         throw new TypeNotValidException(ExceptionMessage::TYPE_NOT_VALID("folder id should be numeric"), 500);
     }
     return $this->createQueryBuilder('d')->where('d.directory is null')->getQuery();
 }
Example #5
0
 /**
  * @param $mode
  * @return bool
  * @throws TypeNotValidException
  */
 public static function validateMode($mode)
 {
     $exists = array_key_exists($mode, StrategyFactory::getModes());
     if (!$exists) {
         $description = ExceptionMessage::TYPE_NOT_VALID("the mode given ({$mode}) was not valid");
         throw new TypeNotValidException($description, 500);
     }
     return true;
 }
 /**
  * @param Directory $directory
  * @param bool|true $autoFlush
  * @throws OverlappingException
  */
 public function safeSave(Directory $directory, $autoFlush = true)
 {
     //get the directories that have the same parent, check if they have the same name
     // or query for the dirs that have the same name with the same parent!
     // if nothing then save it
     $parentToCheck = $directory->getParent();
     $parentID = $parentToCheck ? $parentToCheck->getId() : null;
     $siblings = $this->getArchivesUnder($parentID);
     foreach ($siblings as $sibling) {
         /** @var Directory $sibling */
         if ($sibling->getName() === $directory->getName() && $directory !== $sibling) {
             throw new OverlappingException(ExceptionMessage::NAME_OVERLAPPING("name: {$directory->getName()} vs {$sibling->getName()}"), 500);
         }
     }
     $this->save($directory, $autoFlush);
 }