作者:Maksol
项目:platfor
/**
* Checks if current workflow item allows transition
*
* @param WorkflowData $value
* @param TransitionIsAllowed $constraint
*/
public function validate($value, Constraint $constraint)
{
/** @var WorkflowItem $workflowItem */
$workflowItem = $constraint->getWorkflowItem();
$transitionName = $constraint->getTransitionName();
$workflow = $this->registry->getWorkflow($workflowItem->getWorkflowName());
$errors = new ArrayCollection();
$result = false;
try {
$result = $workflow->isTransitionAllowed($workflowItem, $transitionName, $errors, true);
} catch (InvalidTransitionException $e) {
switch ($e->getCode()) {
case InvalidTransitionException::UNKNOWN_TRANSITION:
$errors->add(array('message' => $constraint->unknownTransitionMessage, 'parameters' => array('{{ transition }}' => $transitionName)));
break;
case InvalidTransitionException::NOT_START_TRANSITION:
$errors->add(array('message' => $constraint->notStartTransitionMessage, 'parameters' => array('{{ transition }}' => $transitionName)));
break;
case InvalidTransitionException::STEP_HAS_NO_ALLOWED_TRANSITION:
$errors->add(array('message' => $constraint->stepHasNotAllowedTransitionMessage, 'parameters' => array('{{ transition }}' => $transitionName, '{{ step }}' => $workflowItem->getCurrentStep()->getName())));
break;
}
}
if (!$result) {
if ($errors->count()) {
foreach ($errors as $error) {
$this->context->addViolation($error['message'], $error['parameters']);
}
} else {
$this->context->addViolation($constraint->someConditionsNotMetMessage);
}
}
}
作者:kebool
项目:orchestrator-bundl
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof TokenEntity) {
throw new \InvalidArgumentException('Given constraint must ne instance of TokenEntity class');
}
if ($value) {
$configValidation = false;
try {
/** @var StorageApi $storageApi */
$storageApi = $constraint->getStorageApi();
$token = $storageApi->getToken($value);
if (!$token) {
throw new \Exception('Token does not exists');
}
$userToken = new Token($storageApi);
$configValidation = true;
$components = new Components(new StorageApi(array('token' => $token['token'], 'url' => $storageApi->getApiUrl(), 'userAgent' => $storageApi->getUserAgent())));
$components->listComponents(new ListConfigurationsOptions());
} catch (\Exception $e) {
if ($e instanceof \Keboola\StorageApi\ClientException && $e->getCode() === 403) {
//@FIXME jak zmenit api exception code
if ($configValidation) {
$this->context->addViolation($constraint->configMessage, array('%string%' => $value), null, null, 'TOKEN_PERMISSION');
} else {
$this->context->addViolation($constraint->permissionsMessage, array(), null, null, 'TOKEN_PERMISSION');
}
} else {
$this->context->addViolation($constraint->message, array('%string%' => $value));
}
return;
}
//@FIXME doplnit validaci na master token!!!
}
}
作者:myschoolmanagemen
项目:assert-constrain
/**
* {@inheritdoc}
*
* @throws UnexpectedTypeException When the constraint isn't a subclass of {@see AbstractAssertionConstraint}
* @throws ConstraintDefinitionException When the assertion doesn't exist on the assertion class
*/
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof AbstractAssertionConstraint) {
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\AbstractAssertionConstraint');
}
$methodName = $constraint->getAssertionMethodName();
$callable = [static::$assertClass, $methodName];
$override = null;
if (is_callable($callable) === false) {
throw new ConstraintDefinitionException('Must be a valid callable on the assertion class');
}
$parameters = array($value);
foreach ($constraint->getAssertionParameterNames() as $name) {
$parameters[] = $constraint->{$name};
}
try {
call_user_func_array($callable, $parameters);
} catch (\Exception $e) {
if ($e instanceof static::$assertExceptionClass) {
$this->context->buildViolation($e->getMessage())->setParameter('{{ value }}', $this->formatValue($value))->setCode($e->getCode())->setCause($e)->addViolation();
} else {
throw $e;
}
}
}
作者:raphael-thibierg
项目:ProgWebServerProjec
/**
* Returns the validator for the supplied constraint.
*
* @param Constraint $constraint A constraint
*
* @return ConstraintValidatorInterface A validator for the supplied constraint
*
* @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface
*/
public function getInstance(Constraint $constraint)
{
$name = $constraint->validatedBy();
if (!isset($this->validators[$name])) {
switch (get_class($constraint)) {
case self::BASE_NAMESPACE . '\\All':
$name = self::BASE_NAMESPACE . '\\LegacyAllValidator';
break;
case self::BASE_NAMESPACE . '\\Choice':
$name = self::BASE_NAMESPACE . '\\LegacyChoiceValidator';
break;
case self::BASE_NAMESPACE . '\\Collection':
$name = self::BASE_NAMESPACE . '\\LegacyCollectionValidator';
break;
case self::BASE_NAMESPACE . '\\Count':
$name = self::BASE_NAMESPACE . '\\LegacyCountValidator';
break;
case self::BASE_NAMESPACE . '\\Length':
$name = self::BASE_NAMESPACE . '\\LegacyLengthValidator';
break;
case self::FORM_BASE_NAMESPACE . '\\Form':
$name = self::FORM_BASE_NAMESPACE . '\\LegacyFormValidator';
break;
}
$this->validators[$name] = new $name();
} elseif (is_string($this->validators[$name])) {
$this->validators[$name] = $this->container->get($this->validators[$name]);
}
if (!$this->validators[$name] instanceof ConstraintValidatorInterface) {
throw new UnexpectedTypeException($this->validators[$name], 'Symfony\\Component\\Validator\\ConstraintValidatorInterface');
}
return $this->validators[$name];
}
作者:apitud
项目:apitud
/**
* Checks if the passed value is valid.
*
* @param mixed $value The value that should be validated
* @param Constraint $constraint The constraint for the validation
* @return bool
*/
public function validate($value, Constraint $constraint)
{
/** @var EntityExists $constraint */
if ($constraint->validate($value)) {
$this->context->addViolation($constraint->message, ['{{ type }}' => $constraint->entityClass, '{{ value }}' => $value]);
}
}
作者:kebool
项目:orchestrator-bundl
public function validate($value, Constraint $constraint)
{
if (!$constraint instanceof OrchestrationTableEntity) {
throw new \InvalidArgumentException('Given constraint must ne instance of OrchestrationTableEntity class');
}
if ($value) {
// table exists
try {
/** @var StorageApi $storageApi */
$storageApi = $constraint->getStorageApi();
if (!$storageApi->tableExists($value)) {
throw new \Exception('Configuration table does not exists');
}
} catch (\Exception $e) {
$this->context->addViolation($constraint->message, array('%string%' => $value));
return;
}
// table structure
try {
/** @var StorageApi $storageApi */
$storageApi = $constraint->getStorageApi();
$table = $storageApi->getTable($value);
$token = new Token($storageApi);
$requiredColumns = self::getRequiredColumns();
$missingColumns = array_diff($requiredColumns, $table['columns']);
if (!empty($missingColumns)) {
throw new \Exception('Invalid configuration table structure');
}
} catch (\Exception $e) {
$this->context->addViolation($constraint->structureMessage, array('%string%' => implode(', ', $requiredColumns)));
return;
}
}
}
作者:senthil-r-wiredelt
项目:meilleure-visit
/**
* {@inheritDoc}
*/
public function getInstance(Constraint $constraint)
{
$className = $constraint->validatedBy();
if (!isset($this->validators[$className]) || $className === 'Symfony\\Component\\Validator\\Constraints\\CollectionValidator') {
$this->validators[$className] = new $className();
}
return $this->validators[$className];
}
作者:eigento
项目:tommiblo
/**
* {@inheritdoc}
*/
public function getInstance(Constraint $constraint)
{
$class_name = $constraint->validatedBy();
if (!isset($this->validators[$class_name])) {
$this->validators[$class_name] = $this->classResolver->getInstanceFromDefinition($class_name);
}
return $this->validators[$class_name];
}
作者:rolas12
项目:weather-homewor
/**
* {@inheritdoc}
*/
public function getInstance(Constraint $constraint)
{
$className = $constraint->validatedBy();
if (!isset($this->validators[$className])) {
$this->validators[$className] = 'validator.expression' === $className ? new ExpressionValidator($this->propertyAccessor) : new $className();
}
return $this->validators[$className];
}
作者:rageba
项目:chamilo-lm
/**
* @param Constraint $constraint
* @return \Symfony\Component\Validator\ConstraintValidatorInterface
*/
public function getInstance(Constraint $constraint)
{
$class_name = $constraint->validatedBy();
if (!isset($this->validators[$class_name])) {
$this->validators[$class_name] = new $class_name();
}
return $this->validators[$class_name];
}
作者:Ener-Getic
项目:symfon
/**
* {@inheritdoc}
*/
public function addConstraint(Constraint $constraint)
{
if (!in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets())) {
throw new ConstraintDefinitionException(sprintf('The constraint %s cannot be put on properties or getters', get_class($constraint)));
}
parent::addConstraint($constraint);
return $this;
}
作者:speedwor
项目:provide
/**
* {@inheritdoc}
*/
public function getInstance(Constraint $constraint)
{
$name = $constraint->validatedBy();
if (isset($this->serviceNames[$name])) {
return $this->container[$this->serviceNames[$name]];
}
return parent::getInstance($constraint);
}
作者:ashutosh-srija
项目:findit_akene
function it_doesnt_support_multi_targets_constraint($guesser, $factory, ClassMetadata $metadata, ProductValueInterface $value, AttributeInterface $attribute, Constraint $multiTargets, Constraint $validNumber)
{
$factory->createMetadata(Argument::any())->willReturn($metadata);
$value->getAttribute()->willReturn($attribute);
$attribute->getBackendType()->willReturn('varchar');
$guesser->guessConstraints($attribute)->willReturn([$multiTargets]);
$multiTargets->getTargets()->willReturn([Constraint::PROPERTY_CONSTRAINT, Constraint::CLASS_CONSTRAINT]);
$this->shouldThrow(new \LogicException('No support provided for constraint on many targets'))->duringGetMetadataFor($value);
}
作者:hafedhbo
项目:hetic-p201
/**
* Returns the validator for the supplied constraint.
*
* @param Constraint $constraint A constraint
* @return ConstraintValidator A validator for the supplied constraint
*/
public function getInstance(Constraint $constraint)
{
$name = $constraint->validatedBy();
if (isset($this->validators[$name])) {
return $this->validators[$name];
}
$this->validators[$name] = $this->createValidator($name);
return $this->validators[$name];
}
作者:sarahwille
项目:OD
/**
* {@inheritdoc}
*/
public function validate($entity, Constraint $constraint)
{
if (!isset($entity)) {
return;
}
if (!in_array($entity->bundle(), $constraint->getBundleOption())) {
$this->context->addViolation($constraint->message, array('%bundle' => implode(', ', $constraint->getBundleOption())));
}
}
作者:bodetre
项目:synapse-bas
/**
* {@inheritDoc}
*/
public function validate($value, Constraint $constraint)
{
$callback = $constraint->getFilterCallback();
$entity = $constraint->getMapper()->findBy($callback($value));
if ($entity instanceof AbstractEntity) {
return;
}
$this->context->addViolation($constraint->message, ['{{ field }}' => $constraint->field, '{{ value }}' => $value], $value);
}
作者:kdyb
项目:validato
/**
* {@inheritDoc}
*/
public function getInstance(Constraint $constraint)
{
$name = $constraint->validatedBy();
if (!isset($this->validators[$name])) {
$this->validators[$name] = new $name();
} elseif (is_string($this->validators[$name])) {
$this->validators[$name] = $this->serviceLocator->getService($this->validators[$name]);
}
return $this->validators[$name];
}
作者:sshversioncontro
项目:git-web-clien
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();
}
}
作者:mparais
项目:doctrineodmserviceprovide
/**
* Returns the validator for the supplied constraint.
*
* @param Constraint $constraint A constraint
*
* @return Symfony\Component\Validator\ConstraintValidator A validator for the supplied constraint
*/
public function getInstance(Constraint $constraint)
{
$className = $constraint->validatedBy();
if (!isset($this->validators[$className])) {
$this->validators[$className] = new $className();
} elseif (is_string($this->validators[$className])) {
$this->validators[$className] = $this->container[$this->validators[$className]];
}
return $this->validators[$className];
}
作者:vpetrovyc
项目:pim-community-de
/**
* @param ClassMetadata $metadata
* @param Constraint $constraint
* @param AttributeInterface $attribute
*/
protected function addConstraint(ClassMetadata $metadata, Constraint $constraint, AttributeInterface $attribute)
{
$target = $constraint->getTargets();
if (is_array($target)) {
throw new \LogicException('No support provided for constraint on many targets');
} elseif (Constraint::PROPERTY_CONSTRAINT === $target) {
$metadata->addPropertyConstraint($attribute->getBackendType(), $constraint);
} elseif (Constraint::CLASS_CONSTRAINT === $target) {
$metadata->addConstraint($constraint);
}
}