Other Helpers
Addresses Helper
The Addresses class provides helper methods for formatting address information.
Namespace: Medialight\Textstem\Helpers
formatAddress
Formats the address details into HTML representation.
public static function formatAddress($record): string
Parameters:
$record(stdClass): The object containing address details.
Returns:
- (string): The formatted HTML address.
Countries Helper
The Countries class provides helper methods for working with country data.
Namespace: Medialight\Textstem\Helpers
countryCode
Gets the country code for a given country name.
public static function countryCode($country): bool|int|string
Parameters:
$country(string): The country name to get the code for.
Returns:
- (bool|int|string): The country code if found, or false/0 if not found.
OpenAiHelper
The OpenAiHelper class provides helper methods for working with OpenAI prompts.
Namespace: Medialight\Textstem\Helpers
prepareForPrompt
Prepares text for a prompt by trimming and limiting its length.
public static function prepareForPrompt(?string $text = '', int $maxTokens = 2000): string
Parameters:
$text(string|null): The text to prepare. Default is an empty string.$maxTokens(int): The maximum number of tokens allowed. Default is 2000.
Returns:
- (string): The prepared text.
getContentFromHtml
Extracts content from HTML for use in a prompt.
public static function getContentFromHtml(?string $html = '', int $maxTokens = 2000): string
Parameters:
$html(string|null): The HTML to extract content from. Default is an empty string.$maxTokens(int): The maximum number of tokens allowed. Default is 2000.
Returns:
- (string): The extracted content.
Urls Helper
The Urls class is a Laravel facade backed by Medialight\Textstem\Services\UrlsService (accessor: urls). It provides URL manipulation utilities.
Namespace: Medialight\Textstem\Helpers
url_add_query_params
Adds or merges query parameters onto a URL, preserving any existing query string.
public static function url_add_query_params(mixed $url, ?array $params = null): string
Parameters:
$url(string|array): Target URL, or an associative array of params to apply to the current request URL.$params(array|null): Key/value pairs to add. When null,$urlis treated as the params array and the current request URL is used as the base.
Returns:
- (string): The resulting URL with merged query string.
Example:
Urls::url_add_query_params('https://example.com/page?foo=1', ['bar' => 2]);
// https://example.com/page?foo=1&bar=2
itemUrl
Generates a URL for a resource item, either as a path segment or query string.
public static function itemUrl(string $base, string|int $id, string $key = 'id', bool $nice = true): string
Parameters:
$base(string): The base URL.$id(string|int): The item identifier.$key(string): The parameter name. Default is'id'.$nice(bool): When true (default), produces a path-style URL (/base/key/123). When false, uses a query string (/base?key=123).
Returns:
- (string): The constructed URL.