Uris on steroids

v1.2.3 2021-06-14 08:01 UTC

This package is auto-updated.

Last update: 2024-04-14 14:08:29 UTC


README

Maintainability Bugs Reliability Rating Vulnerabilities

Yuri is a small utility for making sense out of URIs, without having to write the same utility methods again and again.

By default Yuri works for the current URL if an input URI is ommited:

<?php
use Kristos80\Yuri\Yuri;

require_once __DIR__ . '/vendor/autoload.php';

$yuri = new Yuri('https://www.dummy.com/path/index.html?q[]=1&q[]=2');

You can check, almost, all methods returned values, by using one of the asArray(), asClass() or asJsonString() methods:

//@see Yuri::asJsonString(bool $prettyPrint = FALSE)
echo($yuri->asJsonString(TRUE)); 
{
    "originalUri": "https:\/\/www.dummy.com\/path\/index.html?q[]=1&q[]=2",
    "normalizedUri": "https:\/\/www.dummy.com\/path\/index.html?q[0]=1&q[1]=2",
    "normalizedUriWithSlash": "https:\/\/www.dummy.com\/path\/index.html?q[0]=1&q[1]=2",
    "scheme": "https",
    "host": "www.dummy.com",
    "hostWithoutSubdomains": "dummy.com",
    "tld": "com",
    "path": "\/path\/index.html",
    "paths": [
        "path",
        "index.html"
    ],
    "query": {
        "q": [
            "1",
            "2"
        ]
    },
    "originalQueryString": "q[]=1&q[]=2",
    "queryString": "q[0]=1&q[1]=2",
    "port": null,
    "uid": "6ec78702bb2686046b5102547fbd3d79",
    "isHttps": true,
    "isFile": true,
    "isWww": true
}

And there are some extra utility methods for getting data about path and query, like:

//@see Yuri::getQueryVar(string $varNotation, $defaultValue = NULL)
//Notation syntax is, also, supported
echo $yuri->getQueryVar('q.0','defaultValueIfNotExists'); 
1
//@see Yuri::getPathByIndex(int $pathIndex = 0)
echo $yuri->getPathByIndex();
path

Methods

getOriginalUri(): string {}
getNormalizedUri(bool $useTrailingSlash = FALSE): string {}
isFile(): bool {}
isWww(): bool {}
getNormalizedUriWithSlash(): string {}
getScheme(): ?string {}
getHost(bool $removeSubDomains = FALSE): ?string {}
getTld(): string {}
getPaths(bool $useNullOnEmptyPaths = FALSE): ?array {}
getPath(bool $useSlashOnEmptyPath = FALSE): string {}
getQuery(): array {}
getOriginalQueryString(bool $useQuestionMark = FALSE): string {}
getQueryString(bool $useQuestionMark = FALSE): string {}
getPort(): ?int {}
getUid(): string {}
isHttps(): bool {}
getPathByIndex(int $pathIndex = 0): ?string {}
getQueryVar(string $varNotation, $defaultValue = NULL) {}
asArray(): array {}
asClass(): \stdClass {}
asJsonString(bool $prettyPrint = FALSE): string {}