/** * Load a locale file into the translator * * @param string $file * @param string $domain */ public function loadLocaleFile($file, $domain) { $filename = $this->findLocaleFile($file); if ($filename !== null) { $locale = $this->getLocaleFromFilename($filename); $translator = $this->service->getTranslator(); $translator->addResource('json', $filename, $locale, $domain); } }
public function validate($model) { $builder = new ValidatorBuilder(); $builder->setTranslator($this->service->getTranslator()); $validator = $builder->getValidator(); $validations = $this->getValidations(); $this->violations = new ConstraintViolationList(); foreach ($validations as $column => $validation) { $method = 'get' . NameUtils::toStudlyCase($column); if (method_exists($model, $method)) { $value = $model->{$method}(); $constraints = []; foreach ($validation as $options) { $name = $options['constraint']; unset($options['constraint']); $constraints[] = $this->getConstraint($name, $options); } $violations = $validator->validate($value, $constraints); $this->violations->addAll($violations); } } return (bool) (!(count($this->violations) > 0)); }