本文整理匯總了PHP中Symfony\Component\Validator\Constraint::getChannel方法的典型用法代碼示例。如果您正苦於以下問題:PHP Constraint::getChannel方法的具體用法?PHP Constraint::getChannel怎麽用?PHP Constraint::getChannel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Validator\Constraint
的用法示例。
在下文中一共展示了Constraint::getChannel方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: validatePrices
/**
* Validate that prices contain the currencies required by the channel
*
* @param ProductValueInterface $value
* @param Constraint $constraint
*
* @return null
*/
protected function validatePrices(ProductValueInterface $value, Constraint $constraint)
{
$channel = $constraint->getChannel();
$expectedCurrencies = array_map(function ($currency) {
return $currency->getCode();
}, $channel->getCurrencies()->toArray());
foreach ($expectedCurrencies as $currency) {
foreach ($value->getData() as $price) {
if ($price->getCurrency() === $currency) {
if ($price->getData() === null) {
$this->context->addViolation($constraint->messageComplete);
}
}
}
}
}