public function validate($commitEntity, Constraint $constraint)
 {
     $statusHash = $commitEntity->getStatusHash();
     $this->projectEnvironment = $this->projectEnvironmentStorage->getProjectEnviromment($commitEntity->getProject());
     $this->gitStatusCommand->overRideGitEnvironment($this->projectEnvironment);
     $currentStatusHash = $this->gitStatusCommand->getStatusHash();
     if ($currentStatusHash !== $statusHash) {
         $this->context->buildViolation($constraint->getMessage())->setParameter('{{statushash}}', $statusHash)->setParameter('{{currentstatushash}}', $currentStatusHash)->atPath('files')->addViolation();
     }
 }
 /**
  * Validates Project Enviroment.
  *
  * @param VersionControl\GitControlBundle\Entity\ProjectEnvironment $projectEnvironment
  * @param Constraint                                                $constraint
  */
 public function validate($projectEnvironment, Constraint $constraint)
 {
     $gitPath = rtrim(trim($projectEnvironment->getPath()), '/');
     if ($projectEnvironment->getSsh() === true) {
         $this->sftpProcess->setGitEnviroment($projectEnvironment);
         try {
             if ($this->sftpProcess->fileExists($gitPath . '/.git') === true) {
                 $this->context->buildViolation($constraint->getMessage())->atPath('path')->addViolation();
             }
         } catch (SshLoginException $sshLoginException) {
             $this->context->buildViolation($sshLoginException->getMessage())->atPath('path')->addViolation();
         } catch (Exception $ex) {
             $this->context->buildViolation($ex->getMessage())->atPath('path')->addViolation();
         }
     } else {
         if (file_exists($gitPath . '/.git') === true) {
             $this->context->buildViolation($constraint->getMessage())->atPath('path')->addViolation();
         }
     }
 }
 /**
  * Validates Project Enviroment.
  *
  * @param VersionControl\GitControlBundle\Entity\ProjectEnvironment $projectEnvironment
  * @param Constraint                                                $constraint
  */
 public function validate($projectEnvironment, Constraint $constraint)
 {
     $gitPath = rtrim(trim($projectEnvironment->getPath()), '/');
     if ($projectEnvironment->getSsh() === true) {
         $this->sftpProcess->setGitEnviroment($projectEnvironment);
         try {
             if ($this->sftpProcess->isDir($gitPath) === false) {
                 $this->context->buildViolation('This directory (%gitPath%) does not exist. Please check that you have entered the correct path in %projectEnviromentTitle%')->setParameter('%gitPath%', $gitPath)->setParameter('%projectEnviromentTitle%', $projectEnvironment->getTitle())->atPath('path')->addViolation();
             }
         } catch (SshLoginException $sshLoginException) {
             $this->context->buildViolation($sshLoginException->getMessage())->atPath('title')->addViolation();
         } catch (\Exception $ex) {
             $this->context->buildViolation($constraint->getMessage())->atPath('title')->addViolation();
         }
     }
 }
예제 #4
0
 /**
  * @param object $object
  * @param \Symfony\Component\Validator\Constraint $constraint
  * @return Boolean
  */
 public function isValid($object, Constraint $constraint)
 {
     if (!is_array($constraint->fields) && !is_string($constraint->fields)) {
         throw new UnexpectedTypeException($constraint->fields, 'array');
     }
     $fields = (array) $constraint->fields;
     if (0 === count($fields)) {
         throw new ConstraintDefinitionException("At least one field must be specified.");
     }
     $class = get_class($object);
     $peerClass = $class . 'Peer';
     $queryClass = $class . 'Query';
     $classFields = $peerClass::getFieldNames(\BasePeer::TYPE_FIELDNAME);
     foreach ($fields as $fieldName) {
         if (false === array_search($fieldName, $classFields)) {
             throw new ConstraintDefinitionException('The field "' . $fieldName . '" doesn\'t exist in the "' . $class . '" class.');
         }
     }
     $bddUsersQuery = $queryClass::create();
     foreach ($fields as $fieldName) {
         $bddUsersQuery->filterBy($peerClass::translateFieldName($fieldName, \BasePeer::TYPE_FIELDNAME, \BasePeer::TYPE_PHPNAME), $object->getByName($fieldName, \BasePeer::TYPE_FIELDNAME));
     }
     $bddUsers = $bddUsersQuery->find();
     $countUser = count($bddUsers);
     if ($countUser > 1 || $countUser === 1 && $object !== $bddUsers[0]) {
         $constraintMessage = $constraint->getMessage();
         $constraintMessage .= ' with';
         foreach ($fields as $fieldName) {
             $constraintMessage .= sprintf(' %s "%s" and', $peerClass::translateFieldName($fieldName, \BasePeer::TYPE_FIELDNAME, \BasePeer::TYPE_PHPNAME), $object->getByName($fieldName, \BasePeer::TYPE_FIELDNAME));
         }
         $constraintMessage = substr($constraintMessage, 0, -4) . '.';
         $this->setMessage($constraintMessage);
         return false;
     }
     return true;
 }
예제 #5
0
 /**
  * @param mixed $value
  * @param Constraint $constraint
  * @throws \Exception
  */
 public function validate($value, Constraint $constraint)
 {
     if (!preg_match('#https?://www\\.youtube\\.com/watch\\?v=([^&]*)#', $value, $matches)) {
         $this->context->addViolation($constraint->getMessage());
     }
 }
 /**
  * Add a violation.
  *
  * @param mixed      $value      The value that should be validated.
  * @param Constraint $constraint The constraint for the validation.
  */
 private function addViolation($value, Constraint $constraint)
 {
     $this->context->addViolation($constraint->getMessage(), array('{{ type }}' => $constraint->getType(), '{{ value }}' => $value));
 }