本文整理汇总了PHP中Symfony\Component\Validator\Constraint::getMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Constraint::getMessage方法的具体用法?PHP Constraint::getMessage怎么用?PHP Constraint::getMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\Constraint
的用法示例。
在下文中一共展示了Constraint::getMessage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
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();
}
}
示例2: validate
/**
* 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();
}
}
}
示例3: validate
/**
* 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: isValid
/**
* @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: validate
/**
* @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());
}
}
示例6: addViolation
/**
* 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));
}