* $url = Civi::url('frontend://civicrm/ajax/api4/[entity]/[action]')
* ->addVars(['entity' => 'Foo', 'action' => 'bar']);
*
- * NOTE: CiviCRM is integrated into many environments, and they handle URL-construction different ways.
- * For example, in Joomla+WordPress, there are separate sub-applications for the public-facing
- * frontend UI (`/`) and the staff-facing backend UI (`/wp-admin/` or `/administrator/`) -- each follows
- * a different URL-formula. But in Drupal, all use the same formula. To
- *
* @param string $logicalUri
* Logical URI. The scheme of the URI may be one of:
* - 'frontend://' (Front-end page-route for constituents)
* - 'backend://' (Back-end page-route for staff)
* - 'service://` (Web-service page-route for automated integrations; aka webhooks and IPNs)
* - 'current://' (Whichever UI is currently active)
- * - 'assetBuilder://' (Dynamically-generated asset-file)
+ * - 'assetBuilder://' (Dynamically-generated asset-file; see \Civi\Core\AssetBuilder)
* - 'ext://' (Static asset-file provided by an extension)
* An empty scheme (`//hello.txt`) is equivalent to `current://hello.txt`.
* @param string|null $flags
* List of flags. Some combination of the following:
- * - 'a': absolute
- * - 'r': relative
- * - 'h': html
- * - 'p': plain text
- * - 's': ssl
+ * - 'a': absolute (aka `setPreferFormat('absolute')`)
+ * - 'r': relative (aka `setPreferFormat('relative')`)
+ * - 'h': html (aka `setHtmlEscape(TRUE)`)
+ * - 'p': plain text (aka `setHtmlEscape(FALSE)`)
+ * - 's': ssl (aka `setSsl(TRUE)`)
* FIXME: Should we have a flag for appending 'resCacheCode'?
* @return \Civi\Core\Url
* URL object which may be modified or rendered as text.
* As input, this class takes a *logical URI*, which may include a range of configurable sub-parts (path, query, fragment, etc).
*
* As output, it provides a *concrete URL* that can be used by a web-browser to make requests.
+ *
+ * The typical way to construct a URL object is through `Civi::url()`, which features more
+ * documentation and examples.
+ *
+ * @see \Civi::url()
*/
final class Url {
}
/**
+ * Specify whether to prefer absolute or relative formatting.
+ *
* @param string|null $preferFormat
+ * One of:
+ * - 'relative': Prefer relative format, if available
+ * - 'absolute': Prefer absolute format
+ * - NULL: Decide format based on current environment/request. (Ordinary web UI requests prefer 'relative'.)
*/
public function setPreferFormat(?string $preferFormat): Url {
$this->preferFormat = $preferFormat;
}
/**
+ * Specify whether to enable HTML escaping of the final output.
+ *
* @param bool $htmlEscape
+ * @return $this
*/
public function setHtmlEscape(bool $htmlEscape): Url {
$this->htmlEscape = $htmlEscape;
}
/**
+ * Specify whether the hyperlink should use SSL.
+ *
* @param bool|null $ssl
+ * TRUE: Force SSL on. (Convert "http:" to "https:")
+ * FALSE: Force SSL off. (Convert "https:" to "http:")
+ * NULL: Inherit current SSL-ness
*/
public function setSsl(?bool $ssl): Url {
$this->ssl = $ssl;
}
/**
+ * Specify a list of variables. After composing all parts of the URL, variables will be replaced
+ * with their URL-encoded values.
+ *
+ * Example:
+ * Civi::url('frontend://civicrm/greeter?cid=[contact]&msg=[message]')
+ * ->setVars(['contact' => 123, 'message' => 'Hello to you & you & you!');
+ *
* @param string[]|null $vars
+ * @return $this
*/
public function setVars(?array $vars): Url {
$this->vars = $vars;
}
/**
- * @param string[] $vars
+ * Add more variables. After composing all parts of the URL, variables will be replaced
+ * with their URL-encoded values.
*
+ * Example:
+ * Civi::url('frontend://civicrm/greeter?cid=[contact]&msg=[message]')
+ * ->addVars(['contact' => 123, 'message' => 'Hello to you & you & you!');
+ *
+ * @param string[] $vars
* @return $this
*/
public function addVars(array $vars): Url {
}
/**
+ * Apply a series of flags using short-hand notation.
+ *
* @param string $flags
- * A series of flag-letters. Any of the following:
- * - [a]bsolute
- * - [r]elative
- * - [h]tml
- * - [s]sl
+ * List of flag-letters, such as (a)bsolute or (r)elative
+ * For a full list, see Civi::url().
+ * @see Civi::url()
* @return $this
*/
public function useFlags(string $flags): Url {