{"id":22764604,"url":"https://github.com/kuria/url","last_synced_at":"2025-03-30T10:14:13.851Z","repository":{"id":57009932,"uuid":"96825574","full_name":"kuria/url","owner":"kuria","description":"Parsing, modifying and building URLs","archived":false,"fork":false,"pushed_at":"2023-04-22T14:38:39.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-12T22:05:39.990Z","etag":null,"topics":["php","querystring","url","url-builder","url-parser","url-parsing"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kuria.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2017-07-10T22:07:48.000Z","updated_at":"2023-09-19T17:45:42.000Z","dependencies_parsed_at":"2025-02-07T00:45:17.186Z","dependency_job_id":null,"html_url":"https://github.com/kuria/url","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuria%2Furl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuria%2Furl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuria%2Furl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kuria%2Furl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kuria","download_url":"https://codeload.github.com/kuria/url/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246301995,"owners_count":20755514,"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":["php","querystring","url","url-builder","url-parser","url-parsing"],"created_at":"2024-12-11T12:09:28.513Z","updated_at":"2025-03-30T10:14:13.826Z","avatar_url":"https://github.com/kuria.png","language":"PHP","readme":"Url\n###\n\nParsing, modifying and building URLs.\n\n.. image:: https://travis-ci.com/kuria/url.svg?branch=master\n   :target: https://travis-ci.com/kuria/url\n\n.. contents::\n   :depth: 3\n\n\nFeatures\n********\n\n- parsing URLs\n- building relative and absolute URLs, including protocol-relative URLs\n- getting, checking and setting individual URL components:\n\n  - scheme\n  - host\n  - port\n  - path\n  - query parameters\n  - fragment\n\n\nRequirements\n************\n\n- PHP 7.1+\n\n\nUsage\n*****\n\nCreating a new URL\n==================\n\nCreate a new instance of ``Url`` and use constructor arguments or setters\nto define the components:\n\n.. code:: php\n\n   \u003c?php\n\n   use Kuria\\Url\\Url;\n\n   $url = new Url();\n\n   $url-\u003esetScheme('http');\n   $url-\u003esetHost('example.com');\n   $url-\u003esetPath('/test');\n   // many more setters are available..\n\n   echo $url;\n\nOutput:\n\n::\n\n  http://example.com/test\n\n\nParsing an URL\n==============\n\n.. code:: php\n\n   \u003c?php\n\n   use Kuria\\Url\\Url;\n\n   $url = Url::parse('http://example.com:8080/test?foo=bar\u0026lorem=ipsum#fragment');\n\n.. TIP::\n\n   If you wish to determine the current request URL, you may use the `kuria/request-info \u003chttps://github.com/kuria/request-info/\u003e`_\n   component, which integrates with ``kuria/url``.\n\n.. NOTE::\n\n   Parsing URLs that contain username and a password is supported, but these components are ignored.\n\n   Such URLs are deprecated according to RFC 3986.\n\n\nGetting URL components\n======================\n\n.. code:: php\n\n   var_dump(\n       $url-\u003egetScheme(),\n       $url-\u003egetHost(),\n       $url-\u003egetFullHost(),\n       $url-\u003egetPort(),\n       $url-\u003egetPath(),\n       $url-\u003egetQuery(),\n       $url-\u003egetFragment()\n   );\n\n   // checking whether a certain component is defined\n   var_dump(\n       $url-\u003ehasScheme(),\n       $url-\u003ehasHost(),\n       $url-\u003ehasPort(),\n       $url-\u003ehasPath(),\n       $url-\u003ehasQuery(),\n       $url-\u003ehasFragment()\n   );\n\n\nOutput:\n\n::\n\n  string(4) \"http\"\n  string(11) \"example.com\"\n  string(16) \"example.com:8080\"\n  int(8080)\n  string(5) \"/test\"\n  array(2) {\n    [\"foo\"]=\u003e\n    string(3) \"bar\"\n    [\"lorem\"]=\u003e\n    string(5) \"ipsum\"\n  }\n  string(8) \"fragment\"\n  bool(true)\n  bool(true)\n  bool(true)\n  bool(true)\n  bool(true)\n  bool(true)\n\n\nGetting query parameters\n========================\n\n.. code:: php\n\n   \u003c?php\n\n   use Kuria\\Url\\Url;\n\n   $url = Url::parse('/test?foo=bar\u0026lorem%5B0%5D=ipsum\u0026lorem%5B1%5D=dolor');\n\n   var_dump(\n       $url-\u003ehas('foo'),\n       $url-\u003ehas('nonexistent'),\n       $url-\u003eget('foo'),\n       $url-\u003eget('lorem'),\n       $url-\u003eget('nonexistent')\n   );\n\nOutput:\n\n::\n\n  bool(true)\n  bool(false)\n  string(3) \"bar\"\n  array(2) {\n    [0]=\u003e\n    string(5) \"ipsum\"\n    [1]=\u003e\n    string(5) \"dolor\"\n  }\n  NULL\n\n\nManipulating query parameters\n=============================\n\nSetting a single parameter\n--------------------------\n\n.. code:: php\n\n   \u003c?php\n\n   $url-\u003eset('parameter', 'value');\n\n\nRemoving a single parameter\n---------------------------\n\n.. code:: php\n\n   \u003c?php\n\n   $url-\u003eremove('foo');\n\n\nSetting multiple parameters\n---------------------------\n\n.. code:: php\n\n   \u003c?php\n\n   $url-\u003eadd(['foo' =\u003e 'bar', 'lorem' =\u003e 'ipsum']);\n\n\nReplacing all parameters\n------------------------\n\n.. code:: php\n\n   \u003c?php\n\n   $url-\u003esetQuery(['foo' =\u003e 'bar']);\n\n\nRemoving all parameters\n-----------------------\n\n.. code:: php\n\n   \u003c?php\n\n   $url-\u003eremoveAll();\n\n\nBuilding URLs\n=============\n\nUsing ``build()`` or ``__toString()``\n-------------------------------------\n\nThese methods will return an absolute or relative URL.\n\n- if no host is specified, a relative URL will be returned\n- if the host is specified, an absolute URL will be returned\n  (unless the `preferred format option \u003cSpecifying a preferred format_\u003e`_ is set to relative)\n\n.. code:: php\n\n   \u003c?php\n\n   use Kuria\\Url\\Url;\n\n   $url = new Url();\n\n   $url-\u003esetPath('/test');\n\n   var_dump($url-\u003ebuild());\n\n   $url-\u003esetScheme('http');\n   $url-\u003esetHost('example.com');\n\n   var_dump($url-\u003ebuild());\n\nOutput:\n\n::\n\n  string(5) \"/test\"\n  string(23) \"http://example.com/test\"\n\n\nSpecifying a preferred format\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nBy default, ``build()`` and ``__toString()`` return an absolute URL if the host is specified.\n\nThis behavior can be changed by passing the ``$preferredFormat`` parameter to the constructor,\n``Url::parse()`` or the ``setPreferredFormat()`` method.\n\n- ``Url::RELATIVE`` - prefer generating a relative URL even if the host is specified\n- ``Url::ABSOLUTE`` - prefer generating an absolute URL if a host is specified\n\n.. code:: php\n\n   \u003c?php\n\n   use Kuria\\Url\\Url;\n\n   $url = Url::parse('http://example.com/foo');\n\n   // print URL using the default preferred format (absolute)\n   echo $url, \"\\n\";\n\n   // set the preferred format to relative\n   $url-\u003esetPreferredFormat(Url::RELATIVE);\n\n   echo $url, \"\\n\";\n\nOutput:\n\n::\n\n  http://example.com/foo\n  /foo\n\n\nUsing ``buildAbsolute()``\n-------------------------\n\nThis method will always return an absolute URL.\n\nIf the host is not defined, ``Kuria\\Url\\Exception\\IncompleteUrlException``\nwill be thrown.\n\n.. code:: php\n\n   \u003c?php\n\n   use Kuria\\Url\\Url;\n\n   $url = new Url();\n\n   $url-\u003esetScheme('http');\n   $url-\u003esetHost('example.com');\n   $url-\u003esetPath('/test');\n\n   var_dump($url-\u003ebuildAbsolute());\n\nOutput:\n\n::\n\n  string(23) \"http://example.com/test\"\n\n.. NOTE::\n\n   Building an absolute URL with undefined scheme will yield a protocol-relative URL.\n\n   Example: *//localhost/test*\n\n\nUsing ``buildRelative()``\n-------------------------\n\nThis method will always return a relative URL regardless of whether the host\nis defined or not.\n\n.. code:: php\n\n   \u003c?php\n\n   use Kuria\\Url\\Url;\n\n   $url = new Url();\n\n   $url-\u003esetScheme('http');\n   $url-\u003esetHost('example.com');\n   $url-\u003esetPath('/test');\n\n   var_dump($url-\u003ebuildRelative());\n\nOutput:\n\n::\n\n  string(5) \"/test\"\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuria%2Furl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkuria%2Furl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkuria%2Furl/lists"}