public function getInstance(Constraint $constraint) { $className = $constraint->validatedBy(); if (!isset($this->validators[$className])) { $this->validators[$className] = new $className(); } return $this->validators[$className]; }
/** * Returns a contraint validator from the container service, setting it if it * doesn't exist yet * * Throws an exception if validator service is not instance of * ConstraintValidatorInterface. * * @param Constraint $constraint * @return ConstraintValidatorInterface * @throws \LogicException */ public function getInstance(Constraint $constraint) { $className = $constraint->validatedBy(); $id = $this->getServiceIdFromClass($className); if (!$this->container->hasService($id)) { $this->container->setService($id, new $className()); } $validator = $this->container->getService($id); if (!$validator instanceof ConstraintValidatorInterface) { throw new \LogicException('Service "' . $id . '" is not instance of ConstraintValidatorInterface'); } return $validator; }