getUrl(); } // If the URL is malformed this constraint cannot check further. catch (\InvalidArgumentException $e) { return; } if ($url->isRouted()) { $allowed = TRUE; try { $url->toString(); } // The following exceptions are all possible during URL generation, and // should be considered as disallowed URLs. catch (RouteNotFoundException $e) { $allowed = FALSE; } catch (InvalidParameterException $e) { $allowed = FALSE; } catch (MissingMandatoryParametersException $e) { $allowed = FALSE; } if (!$allowed) { $this->context->addViolation($constraint->message, ['@uri' => $value->uri]); } } } } }