This document lists all the functions available in the Valksor Functions: Web package.
public function validateIPAddress(
string $ipAddress,
bool $deny = true,
): boolValidates an IP address and optionally denies private and reserved ranges.
Parameters:
$ipAddress: The IP address to validate$deny: Whether to deny private and reserved ranges (default: true)
Returns a boolean indicating whether the IP address is valid.
public function validateCIDR(
string $cidr,
): boolValidates a CIDR notation IP address.
Parameters:
$cidr: The CIDR notation IP address to validate
Returns a boolean indicating whether the CIDR notation is valid.
public function isCIDR(
string $cidr,
): boolChecks if a string is a valid CIDR notation.
Parameters:
$cidr: The string to check
Returns a boolean indicating whether the string is a valid CIDR notation.
public function cidrRange(
string $cidr,
): arrayGets the IP range from a CIDR notation.
Parameters:
$cidr: The CIDR notation
Returns an array with the start and end IP addresses of the range.
public function remoteIp(
Request $request,
bool $trust = false,
): stringGets the remote IP address from a request.
Parameters:
$request: The Symfony HttpFoundation Request object$trust: Whether to trust proxy headers (default: false)
Returns the remote IP address as a string.
public function remoteIpCF(
Request $request,
): stringGets the remote IP address from a request using Cloudflare headers.
Parameters:
$request: The Symfony HttpFoundation Request object
Returns the remote IP address as a string.
public function validateEmail(
string $email,
): boolValidates an email address.
Parameters:
$email: The email address to validate
Returns a boolean indicating whether the email address is valid.
public function urlEncode(
string $url,
): stringEncodes a URL by parsing it and rebuilding it with proper encoding.
Parameters:
$url: The URL to encode
Returns the encoded URL.
public function isAbsolute(
string $url,
): boolChecks if a URL is absolute (starts with http:// or https://).
Parameters:
$url: The URL to check
Returns a boolean indicating whether the URL is absolute.
public function isUrl(
string $url,
): boolChecks if a string is a valid URL.
Parameters:
$url: The string to check
Returns a boolean indicating whether the string is a valid URL.
public function schema(
bool $https = true,
): stringReturns the URL schema (http:// or https://).
Parameters:
$https: Whether to return https:// (true) or http:// (false)
Returns the URL schema as a string.
public function isHttps(
Request $request,
): boolChecks if a request is using HTTPS by examining various headers and indicators.
Parameters:
$request: The Symfony HttpFoundation Request object
Returns a boolean indicating whether the request is using HTTPS.
public function checkHttps(
Request $request,
): boolChecks if the HTTPS header is set in the request.
Parameters:
$request: The Symfony HttpFoundation Request object
Returns a boolean indicating whether the HTTPS header is set.
public function checkHttpXForwardedProto(
Request $request,
): boolChecks if the X-Forwarded-Proto header is set to HTTPS in the request.
Parameters:
$request: The Symfony HttpFoundation Request object
Returns a boolean indicating whether the X-Forwarded-Proto header is set to HTTPS.
public function checkHttpXForwardedSsl(
Request $request,
): boolChecks if the X-Forwarded-SSL header is set to on in the request.
Parameters:
$request: The Symfony HttpFoundation Request object
Returns a boolean indicating whether the X-Forwarded-SSL header is set to on.
public function checkServerPort(
Request $request,
): boolChecks if the server port is the HTTPS port (443).
Parameters:
$request: The Symfony HttpFoundation Request object
Returns a boolean indicating whether the server port is the HTTPS port.
public function buildHttpQueryString(
array $data,
): stringBuilds an HTTP query string from an array of data.
Parameters:
$data: The array of data to convert to a query string
Returns the HTTP query string.
public function buildHttpQueryArray(
array $data,
): arrayBuilds an array suitable for HTTP query string from a nested array.
Parameters:
$data: The nested array to convert
Returns an array suitable for HTTP query string.
public function arrayFromQueryString(
string $queryString,
): arrayConverts an HTTP query string to an array.
Parameters:
$queryString: The HTTP query string to convert
Returns an array of query parameters.
public function isIE(
Request $request,
): boolChecks if the request is from Internet Explorer.
Parameters:
$request: The Symfony HttpFoundation Request object
Returns a boolean indicating whether the request is from Internet Explorer.
public function requestIdentity(
Request $request,
): stringGenerates a unique identity for a request based on its properties.
Parameters:
$request: The Symfony HttpFoundation Request object
Returns a unique identity string for the request.
public function requestMethods(
bool $safe = false,
): arrayReturns an array of HTTP request methods.
Parameters:
$safe: Whether to return only safe methods (GET, HEAD)
Returns an array of HTTP request methods.
public function parseHeaders(
string $headers,
): arrayParses HTTP headers from a string.
Parameters:
$headers: The HTTP headers string
Returns an array of parsed headers.
public function rawHeaders(
): arrayGets the raw HTTP headers from the current request.
Returns an array of raw HTTP headers.
public function buildArrayFromObject(
object $object,
): arrayConverts an object to an array.
Parameters:
$object: The object to convert
Returns an array representation of the object.
public function result(
mixed $data,
int $status = 200,
array $headers = [],
): ResponseCreates a Response object with the given data, status, and headers.
Parameters:
$data: The data to include in the response$status: The HTTP status code (default: 200)$headers: Additional HTTP headers
Returns a Response object.
public function routeExists(
string $name,
RouterInterface $router,
): boolChecks if a route exists in the router.
Parameters:
$name: The route name$router: The Symfony RouterInterface
Returns a boolean indicating whether the route exists.
public function latestReleaseTag(
string $repository,
string $default = 'latest',
): stringGets the latest release tag from a GitHub repository.
Parameters:
$repository: The GitHub repository (e.g., "valksor/php-valksor")$default: The default value to return if no release is found
Returns the latest release tag or the default value.