{"id":18550272,"url":"https://github.com/xp-forge/uri","last_synced_at":"2025-09-10T00:16:47.634Z","repository":{"id":57084829,"uuid":"86093179","full_name":"xp-forge/uri","owner":"xp-forge","description":"URI handling","archived":false,"fork":false,"pushed_at":"2025-01-19T10:21:54.000Z","size":146,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T12:39:41.435Z","etag":null,"topics":["fluent-interface","php","rfc-3986","uri"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xp-forge.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-03-24T17:19:41.000Z","updated_at":"2025-01-19T10:21:33.000Z","dependencies_parsed_at":"2024-02-04T11:58:31.711Z","dependency_job_id":"5e6615c6-b1f0-4cc1-814f-d5db55cd4219","html_url":"https://github.com/xp-forge/uri","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Furi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Furi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Furi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xp-forge%2Furi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xp-forge","download_url":"https://codeload.github.com/xp-forge/uri/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248123464,"owners_count":21051478,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fluent-interface","php","rfc-3986","uri"],"created_at":"2024-11-06T21:04:03.564Z","updated_at":"2025-04-09T22:31:13.506Z","avatar_url":"https://github.com/xp-forge.png","language":"PHP","readme":"URI handling\n============\n\n[![Build status on GitHub](https://github.com/xp-forge/uri/workflows/Tests/badge.svg)](https://github.com/xp-forge/uri/actions)\n[![XP Framework Module](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)\n[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)\n[![Requires PHP 7.4+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_4plus.svg)](http://php.net/)\n[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)\n[![Latest Stable Version](https://poser.pugx.org/xp-forge/uri/version.svg)](https://packagist.org/packages/xp-forge/uri)\n\nA Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource.\n\n```\n  foo://example.com:8042/over/there?name=ferret#nose\n  \\_/   \\______________/\\_________/ \\_________/ \\__/\n   |           |            |            |        |\nscheme     authority       path        query   fragment\n   |   _____________________|__\n  / \\ /                        \\\n  urn:example:animal:ferret:nose\n```\n\nSee https://tools.ietf.org/html/rfc3986\n\n## Examples\n\n### Parsing from a string\n\nThe most common case will include constructing URIs from a given input string.\n\n```php\nuse util\\URI;\n\n$uri= new URI('https://user:password@localhost:8443/index?sort=name#top');\n$uri-\u003eisOpaque();     // false - it's a hierarchical URI\n$uri-\u003escheme();       // \"https\"\n$uri-\u003eauthority();    // util.Authority(\"localhost\", 8443, \"user\", util.Secret(\"password\"))\n$uri-\u003ehost();         // \"localhost\"\n$uri-\u003eport();         // 8443\n$uri-\u003euser();         // \"user\"\n$uri-\u003epassword();     // util.Secret(\"password\")\n$uri-\u003epath();         // \"index\"\n$uri-\u003equery();        // \"sort=name\"\n$uri-\u003eparams();       // util.uri.Parameters(\"sort=name\")\n$uri-\u003eparam('sort');  // \"name\"\n$uri-\u003efragment();     // \"top\"\n$uri-\u003eresource();     // \"/index?sort=name#top\"\n```\n\n### Creating or modifying\n\nURI instances are immutable. However, a fluent interface is offered via `with()` and `using()`. Both return fresh instances.\n\n```php\nuse util\\URI;\n\n$uri= URI::with()-\u003escheme('mailto')-\u003epath('timm@example.com')-\u003eparam('Subject', 'Hello')-\u003ecreate();\n$uri-\u003eisOpaque();   // true - it's an opaque URI\n$uri-\u003escheme();     // \"mailto\"\n$uri-\u003eauthority();  // null\n(string)$uri;       // \"mailto:timm@example.com?Subject=Hello\"\n\n$copy= $uri-\u003eusing()-\u003epath('cc@example.com')-\u003ecreate();\n(string)$copy;      // \"mailto:cc@example.com?Subject=Hello\"\n```\n\n### Resolving URIs\n\nGiven `http://localhost/home/` as the base URI, you can resolve links in its context using the `resolve()` method:\n\n```php\nuse util\\URI;\n\n$uri= new URI('http://localhost/home/');\n$uri-\u003eresolve('/index.html');       // util.URI\u003chttp://localhost/index.html\u003e\n$uri-\u003eresolve('index.html');        // util.URI\u003chttp://localhost/home/index.html\u003e\n$uri-\u003eresolve('?sort=name');        // util.URI\u003chttp://localhost/home/?sort=name\u003e\n$uri-\u003eresolve('#top');              // util.URI\u003chttp://localhost/home/#top\u003e\n$uri-\u003eresolve('//example.com');     // util.URI\u003chttp://example.com\u003e\n$uri-\u003eresolve('https://localhost'); // util.URI\u003chttps://localhost\u003e\n```\n\n### Filesystem\n\nURIs can point to filesystem paths. Converting between the two is not trivial - you need to handle Windows UNC paths correctly. The URI class' `file()` and `asPath()` methods take care of this.\n\n```php\nuse util\\URI;\n\n$uri= URI::file('/etc/php.ini');\n(string)$uri;       // \"file:///etc/php.ini\"\n\n$uri= new URI('file://c:/Windows');\n$uri-\u003epath();       // \"C:/Windows\"\n$uri-\u003easPath();     // io.Path(\"C:\\Windows\")\n\n$uri= new URI('file://share/file.txt');\n$uri-\u003eauthority();  // util.Authority(\"share\")\n$uri-\u003epath();       // \"/file.txt\"\n$uri-\u003easPath();     // io.Path(\"\\\\share\\file.txt\")\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-forge%2Furi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxp-forge%2Furi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxp-forge%2Furi/lists"}