protected function buildUrl($url) { if (is_array($url)) { return new Url($url); } elseif ($url instanceof Url) { return $url; } elseif (is_string($url)) { $rule = new UrlRule('url-validation'); if ($rule->apply($url)) { return new Url(['value' => $rule->getSanitizedValue()]); } } throw new ConfigError('Given URL must be convertible to an instance of: ' . Url::CLASS); }
protected function execute($values, EntityInterface $entity = null) { if (!is_array($values)) { $this->throwError('non_array_value', [], IncidentInterface::CRITICAL); return false; } $sanitized = []; $url_rule = new UrlRule('url', $this->getOptions()); foreach ($values as $val) { $is_valid = $url_rule->apply($val); if (!$is_valid) { foreach ($url_rule->getIncidents() as $incident) { $this->throwError($incident->getName(), $incident->getParameters(), $incident->getSeverity()); } return false; } else { $val = $url_rule->getSanitizedValue(); } $sanitized[] = $val; } $this->setSanitizedValue($sanitized); return true; }