public function validate($value, Constraint $constraint) { if (!$constraint instanceof ComponentEntity) { throw new \InvalidArgumentException('Given constraint must ne instance of ComponentEntity class'); } if ($value) { try { if (!in_array($value, $constraint->getComponentManager()->getComponents())) { throw new \Exception('Component not found'); } } catch (\Exception $e) { $this->context->addViolation($constraint->message, array('%string%' => $value)); return; } } }