作者:InformatiquePro
项目:Diaporama
public function checkValidDiaporama($value, ExecutionContextInterface $context)
{
$value = intval($value);
if (is_null(DiaporamaQuery::create()->findOneById($value))) {
$context->addViolation($this->trans('diaporama.delete.invalid_diaporama %diaporama_id', array('diaporama_id' => $value)));
}
}
作者:stephyle
项目:calendar-bundl
public function isValid(ExecutionContextInterface $context)
{
$is_valid = $this->start <= $this->end;
if (!$is_valid) {
$context->addViolationAt('end', 'bladetester_calendar.validation.event_dates', array(), null);
}
}
作者:marger
项目:theli
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$customer = CustomerQuery::getCustomerByEmail($value);
if ($customer) {
$context->addViolation(Translator::getInstance()->trans("This email already exists."));
}
}
作者:bobanmilan
项目:theli
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$customer = NewsletterQuery::create()->filterByUnsubscribed(false)->findOneByEmail($value);
if ($customer) {
$context->addViolation(Translator::getInstance()->trans("You are already registered!"));
}
}
作者:manuelbc
项目:theli
public function verifyCountry($value, ExecutionContextInterface $context)
{
$address = CountryQuery::create()->findPk($value);
if (null === $address) {
$context->addViolation(Translator::getInstance()->trans("Country ID not found"));
}
}
作者:zorn-
项目:theli
public function verifyCountryList($value, ExecutionContextInterface $context)
{
$jsonType = new JsonType();
if (!$jsonType->isValid($value)) {
$context->addViolation(Translator::getInstance()->trans("Country list is not valid JSON"));
}
$countryList = json_decode($value, true);
foreach ($countryList as $countryItem) {
if (is_array($countryItem)) {
$country = CountryQuery::create()->findPk($countryItem[0]);
if (null === $country) {
$context->addViolation(Translator::getInstance()->trans("Country ID %id not found", ['%id' => $countryItem[0]]));
}
if ($countryItem[1] == "0") {
continue;
}
$state = StateQuery::create()->findPk($countryItem[1]);
if (null === $state) {
$context->addViolation(Translator::getInstance()->trans("State ID %id not found", ['%id' => $countryItem[1]]));
}
} else {
$context->addViolation(Translator::getInstance()->trans("Wrong country definition"));
}
}
}
作者:badela
项目:theli
public function verifyExistingEmail($value, ExecutionContextInterface $context)
{
$customer = CustomerQuery::create()->findOneByEmail($value);
if (null === $customer) {
$context->addViolation(Translator::getInstance()->trans("This email does not exists"));
}
}
作者:marger
项目:theli
public function verifyExistingLogin($value, ExecutionContextInterface $context)
{
$administrator = AdminQuery::create()->findOneByLogin($value);
if ($administrator !== null) {
$context->addViolation("This login already exists");
}
}
作者:jacko97
项目:pim-community-de
function it_does_not_validate_a_non_existent_channel($channelManager, Channel $constraint, ExecutionContextInterface $context)
{
$channelManager->getChannelChoices()->willReturn(['mobile' => 'mobile']);
$context->addViolation(Argument::cetera())->shouldBeCalled();
$this->initialize($context);
$this->validate('Magento', $constraint);
}
作者:artur-dant
项目:heyrentm
public function validateSlug($blog, ExecutionContextInterface $context)
{
$unique = $this->getDoctrineRepo('AppBundle:Blog')->isSlugUnique($blog->getSlug(), $blog->getId());
if (!$unique) {
$context->buildViolation('The slug is not unique')->addViolation();
}
}
作者:raizet
项目:CraueFormFlowBundl
public function isDataValid(ExecutionContextInterface $context)
{
// valid only on first call
if (++self::$validationCalls > 1) {
$context->addViolation('Take this!');
}
}
作者:badela
项目:theli
/**
* Validate a date entered with the current edition Language date format.
*
* @param string $value
* @param ExecutionContextInterface $context
*/
public function checkDate($value, ExecutionContextInterface $context)
{
$format = self::PHP_DATE_FORMAT;
if (!empty($value) && false === \DateTime::createFromFormat($format, $value)) {
$context->addViolation(Translator::getInstance()->trans("Date '%date' is invalid, please enter a valid date using %fmt format", ['%fmt' => self::MOMENT_JS_DATE_FORMAT, '%date' => $value]));
}
}
作者:jantoto
项目:theli
public function verifyEmailField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if (isset($data["email_confirm"]) && $data["email"] != $data["email_confirm"]) {
$context->addViolation(Translator::getInstance()->trans("email confirmation is not the same as email field"));
}
}
作者:enuri
项目:INSEEGe
public function checkCityName($value, ExecutionContextInterface $context)
{
$isValid = InseeGeoMunicipalityQuery::create()->findOneById($value);
if (!isset($isValid)) {
$context->addViolation(Translator::getInstance()->trans('city.error', [], INSEEGeo::DOMAIN_NAME));
}
}
作者:alex6353
项目:theli
public function verifyTaxList($value, ExecutionContextInterface $context)
{
$jsonType = new JsonType();
if (!$jsonType->isValid($value)) {
$context->addViolation(Translator::getInstance()->trans("Tax list is not valid JSON"));
}
$taxList = json_decode($value, true);
/* check we have 2 level max */
foreach ($taxList as $taxLevel1) {
if (is_array($taxLevel1)) {
foreach ($taxLevel1 as $taxLevel2) {
if (is_array($taxLevel2)) {
$context->addViolation(Translator::getInstance()->trans("Bad tax list JSON"));
} else {
$taxModel = TaxQuery::create()->findPk($taxLevel2);
if (null === $taxModel) {
$context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
}
}
}
} else {
$taxModel = TaxQuery::create()->findPk($taxLevel1);
if (null === $taxModel) {
$context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
}
}
}
}
作者:alex6353
项目:theli
public function verifyPasswordField($value, ExecutionContextInterface $context)
{
$data = $context->getRoot()->getData();
if ($data["password"] != $data["password_confirm"]) {
$context->addViolation(Translator::getInstance()->trans("password confirmation is not the same as password field"));
}
}
作者:carlostop
项目:prueba_runato
/**
* Wrapper for {@link ExecutionContextInterface::buildViolation} that
* supports the 2.4 context API.
*
* @param ExecutionContextInterface $context The context to use
* @param string $message The violation message
* @param array $parameters The message parameters
*
* @return ConstraintViolationBuilderInterface The violation builder
*
* @deprecated This method will be removed in Symfony 3.0.
*/
protected function buildViolationInContext(ExecutionContextInterface $context, $message, array $parameters = array())
{
if ($context instanceof ExecutionContextInterface2Dot5) {
return $context->buildViolation($message, $parameters);
}
return new LegacyConstraintViolationBuilder($context, $message, $parameters);
}
作者:alex6353
项目:theli
public function verifyExistingCode($value, ExecutionContextInterface $context)
{
$coupon = CouponQuery::create()->findOneByCode($value);
if (null === $coupon) {
$context->addViolation(Translator::getInstance()->trans("This coupon does not exists"));
}
}
作者:MaximeMorill
项目:theli
public function checkDuplicateCode($value, ExecutionContextInterface $context)
{
$currency = CurrencyQuery::create()->findOneByCode($value);
if ($currency) {
$context->addViolation(Translator::getInstance()->trans('A currency with code "%name" already exists.', ['%name' => $value]));
}
}
作者:shakara
项目:powerline-serve
public function isSubjectValid(ExecutionContextInterface $context)
{
$text = preg_replace(array('/<a[^>]+href[^>]+>/', '/<\\/a>/'), '', $this->subjectParsed);
if (mb_strlen($text, 'utf-8') > 500) {
$context->addViolationAt('subject', 'The subject too long');
}
}