本文整理汇总了PHP中Symfony\Component\Validator\ExecutionContext::getPropertyPath方法的典型用法代码示例。如果您正苦于以下问题:PHP ExecutionContext::getPropertyPath方法的具体用法?PHP ExecutionContext::getPropertyPath怎么用?PHP ExecutionContext::getPropertyPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Validator\ExecutionContext
的用法示例。
在下文中一共展示了ExecutionContext::getPropertyPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isVoteValid
/**
* {@inheritdoc}
*/
public function isVoteValid(ExecutionContext $context)
{
if (!$this->checkValue($this->value)) {
$message = 'A vote cannot have a 0 value';
$propertyPath = $context->getPropertyPath() . '.value';
$context->addViolationAtPath($propertyPath, $message);
}
}
示例2: isVoteValid
/**
* {@inheritdoc}
*/
public function isVoteValid(ExecutionContext $context)
{
if (!$this->checkValue($this->value)) {
$propertyPath = $context->getPropertyPath() . '.value';
$context->setPropertyPath($propertyPath);
$context->addViolation('A vote cannot have a 0 value', array(), null);
}
}
示例3: validateValueAsYaml
public function validateValueAsYaml(ExecutionContext $context)
{
try {
Inline::load($this->value);
} catch (ParserException $e) {
$context->setPropertyPath($context->getPropertyPath() . '.value');
$context->addViolation('This value is not valid YAML syntax', array(), $this->value);
}
}
示例4: isEmailValid
public function isEmailValid(ExecutionContext $context)
{
// somehow you have an array of "fake email"
$fakeEmails = array('test@test.com');
// check if the name is actually a fake email
if (in_array($this->getEmail(), $fakeEmails)) {
$propertyPath = $context->getPropertyPath() . '.email';
$context->setPropertyPath($propertyPath);
$context->addViolation('Tu ne te moquerais pas un peu de moi avec cet email ?', array(), null);
}
}
示例5: validateFormChildren
public static function validateFormChildren(FormInterface $form, ExecutionContext $context)
{
if ($form->getAttribute('cascade_validation')) {
$propertyPath = $context->getPropertyPath();
$graphWalker = $context->getGraphWalker();
// Adjust the property path accordingly
if (!empty($propertyPath)) {
$propertyPath .= '.';
}
$propertyPath .= 'children';
$graphWalker->walkReference($form->getChildren(), Constraint::DEFAULT_GROUP, $propertyPath, true);
}
}
示例6: areImagesValid
public function areImagesValid(ExecutionContext $context)
{
$captured_ids = array_map(function ($image) {
return $image->getId();
}, $this->images->toArray());
$property_path = $context->getPropertyPath() . '.images';
if (!count($captured_ids)) {
$context->addViolationAt($property_path, 'Please select at least one image!', array(), null);
return;
}
$count = $this->query_builder->andWhere($this->query_builder->expr()->in('i.id', $captured_ids))->select('COUNT(i.id)')->getQuery()->getSingleScalarResult();
if (!$count) {
$context->addViolation('Please select images from the list!', array(), null);
}
}
示例7: validateFormData
/**
* Validates the data of a form
*
* This method is called automatically during the validation process.
*
* @param FormInterface $form The validated form
* @param ExecutionContext $context The current validation context
*/
public static function validateFormData(FormInterface $form, ExecutionContext $context)
{
if (is_object($form->getData()) || is_array($form->getData())) {
$propertyPath = $context->getPropertyPath();
$graphWalker = $context->getGraphWalker();
// The Execute constraint is called on class level, so we need to
// set the property manually
$context->setCurrentProperty('data');
// Adjust the property path accordingly
if (!empty($propertyPath)) {
$propertyPath .= '.';
}
$propertyPath .= 'data';
foreach (self::getFormValidationGroups($form) as $group) {
$graphWalker->walkReference($form->getData(), $group, $propertyPath, true);
}
}
}
示例8: isEntityValid
public function isEntityValid(ExecutionContext $context)
{
$propertyPath = $context->getPropertyPath() . '.fieldName';
if ($this->getFieldType() == 'entity') {
if ($this->getFragment() == null || $this->getBundleName() == null || $this->getEntityName() == null || $this->getRelationType() == null || $this->getPropertyName() == null) {
$context->setPropertyPath($propertyPath);
$context->addViolation('Incomplete relation value for ' . $this->getFieldName(), array(), null);
}
}
}
示例9: validateData
/**
* Validates the data of this form
*
* This method is called automatically during the validation process.
*
* @param ExecutionContext $context The current validation context
*/
public function validateData(ExecutionContext $context)
{
if (is_object($this->getData()) || is_array($this->getData())) {
$groups = $this->getValidationGroups();
$propertyPath = $context->getPropertyPath();
$graphWalker = $context->getGraphWalker();
if (null === $groups) {
$groups = array(null);
}
// The Execute constraint is called on class level, so we need to
// set the property manually
$context->setCurrentProperty('data');
// Adjust the property path accordingly
if (!empty($propertyPath)) {
$propertyPath .= '.';
}
$propertyPath .= 'data';
foreach ($groups as $group) {
$graphWalker->walkReference($this->getData(), $group, $propertyPath, true);
}
}
}
示例10: esFechaPeriodoPruebaValida
public function esFechaPeriodoPruebaValida(ExecutionContext $context)
{
$propertyPath = $context->getPropertyPath() . '.fechaInicioPrueba';
if ($this->getPeriodoPrueba() == 1) {
if ($this->getFechaInicioPrueba() > $this->getFechaTerminoPrueba()) {
$context->setPropertyPath($propertyPath);
$context->addViolation('compare dates test invalid', array(), null);
}
}
}
示例11: isValid
/**
* Custom validation constraint
* Not valid if no one recipient specified
*
* @param ExecutionContext $context
*/
public function isValid(ExecutionContext $context)
{
$notValid = $this->getGroups()->isEmpty() && $this->getUsers()->isEmpty() && $this->getEmail() == null && $this->getOwner() == null;
if ($notValid) {
$propertyPath = $context->getPropertyPath() . '.recipientList';
$context->addViolationAt($propertyPath, 'oro.notification.validators.recipient_list.empty.message');
}
}
示例12: isPackageUnique
public function isPackageUnique(ExecutionContext $context)
{
try {
if ($this->entityRepository->findOneByName($this->name)) {
$propertyPath = $context->getPropertyPath() . '.repository';
$context->setPropertyPath($propertyPath);
$context->addViolation('A package with the name ' . $this->name . ' already exists.', array(), null);
}
} catch (\Doctrine\ORM\NoResultException $e) {
}
}
示例13: esRutValido
public function esRutValido(ExecutionContext $context)
{
$propertyPath = $context->getPropertyPath() . '.rut';
$rut = $this->getRut();
/* validando rut */
$r = strtoupper(str_replace(array(".", "-"), "", $rut));
$sub_rut = substr($r, 0, strlen($r) - 1);
$sub_dv = substr($r, -1);
$x = 2;
$s = 0;
for ($i = strlen($sub_rut) - 1; $i >= 0; $i--) {
if ($x > 7) {
$x = 2;
}
$s += $sub_rut[$i] * $x;
$x++;
}
$dv = 11 - $s % 11;
if ($dv == 10) {
$dv = 'K';
}
if ($dv == 11) {
$dv = '0';
}
if ($dv != $sub_dv) {
$context->setPropertyPath($propertyPath);
$context->addViolation('rut invalid', array(), null);
}
}
示例14: testGetPropertyPathWithEmptyCurrentPropertyPath
public function testGetPropertyPathWithEmptyCurrentPropertyPath()
{
$this->context = new ExecutionContext($this->globalContext, $this->translator, self::TRANS_DOMAIN, $this->metadata, 'currentValue', 'Group', '');
$this->assertEquals('bam.baz', $this->context->getPropertyPath('bam.baz'));
}
示例15: isRegionValid
public function isRegionValid(ExecutionContext $context)
{
if ($this->getCountry() && $this->getCountry()->hasRegions() && !$this->state) {
$propertyPath = $context->getPropertyPath() . '.state';
$context->addViolationAt($propertyPath, 'State is required for country %country%', array('%country%' => $this->getCountry()->getName()));
}
}