Download the PHP package riimu/kit-urlparser without Composer

On this page you can find all versions of the php package riimu/kit-urlparser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package kit-urlparser

RFC 3986 URL Parser

UrlParser is PHP library that provides a RFC 3986 compliant URL parser and a PSR-7 compatible URI component. The purpose of this library is to provide a parser that accurately implements the RFC specification unlike the built in function parse_url(), which differs from the specification in some subtle ways.

This library has two main purposes. The first to provide information from the parsed URLs. To achieve this, the library implements the standard URI handling interface from the PSR-7 and also provides additional methods that make it easier to retrieve commonly used information from the URLs. The second purpose is to also permit the modification of said URLs using the interface from the PSR-7 standard in addition to few extra methods that make some tasks more straightforward.

While this library is mainly intended for parsing URLs, the parsing is simply based on the generic URI syntax. Thus, it is possible to use this library to validate and parse any other types of URIs against the generic syntax. The library does not perform any scheme specific validation for the URLs.

In addition to the default RFC 3986 compliant mode, the library also offers options that allow parsing of URLs that contain UTF-8 characters in different components of the URL while converting them to the appropriate percent encoded and IDN ascii formats.

The API documentation is available at: http://kit.riimu.net/api/urlparser/

CI Scrutinizer codecov Packagist

Requirements

Installation

Installation with Composer

The easiest way to install this library is to use Composer to handle your dependencies. In order to install this library via Composer, simply follow these two steps:

  1. Acquire the composer.phar by running the Composer Command-line installation in your project root.

  2. Once you have run the installation script, you should have the composer.phar file in you project root and you can run the following command:

After installing this library via Composer, you can load the library by including the vendor/autoload.php file that was generated by Composer during the installation.

Adding the library as a dependency

If you are already familiar with how to use Composer, you may alternatively add the library as a dependency by adding the following composer.json file to your project and running the composer install command:

Manual installation

If you do not wish to use Composer to load the library, you may also download the library manually by downloading the latest release and extracting the src folder to your project. You may then include the provided src/autoload.php file to load the library classes.

Please note that using Composer will also automatically download the other required PHP libraries. If you install this library manually, you will also need to make those other required libraries available.

Usage

Using this library is relatively straightforward. The library provides a URL parsing class UriParser and an immutable value object class Uri that represents the URL. To parse an URL, you could simply provide the URL as a string to the parse() method in UriParser which returns an instance of Uri that has been generated from the parsed URL.

For example:

Alternatively, you can just skip using the UriParser completely and simply provide the URL as a constructor parameter to the Uri:

The main difference between using the parse() method and the constructor is that the parse() method will return a null if the provided URL is not a valid url, while the constructor will throw an InvalidArgumentException.

To retrieve different types of information from the URL, the Uri class provides various different methods to help you. Here is a simple example as an overview of the different available methods:

The Uri component also provides various methods for modifying the URL, which allows you to construct new URLs from separate components or modify existing ones. Note that the Uri component is an immutable value object, which means that each of the modifying methods return a new Uri instance instead of modifying the existing one. Here is a simple example of constructing an URL from it's components:

As can be seen from the previous example, the Uri component also provides a __toString() method that provides the URL as a string.

Retrieving Information

Here is the list of methods that the Uri component provides for retrieving information from the URL:

Modifying the URL

The Uri component provides various methods that can be used to modify URLs and construct new ones. Note that since the Uri class is an immutable value object, each method returns a new instance of Uri rather than modifying the existing one.

UTF-8 and International Domains Names

By default, this library provides a parser that is RFC 3986 compliant. The RFC specification does not permit the use of UTF-8 characters in the domain name or any other parts of the URL. The correct representation for these in the URL is to use the an IDN standard for domain names and percent encoding the UTF-8 characters in other parts.

However, to help you deal with UTF-8 encoded characters, many of the methods in the Uri component will automatically percent encode any characters that cannot be inserted in the URL on their own, including UTF-8 characters. Due to complexities involved, however, the withHost() method does not allow UTF-8 encoded characters.

By default, the parser also does not parse any URLs that include UTF-8 encoded characters because that would be against the RFC specification. However, the parser does provide two additional parsing modes that allows these characters whenever possible.

If you wish to parse URLs that may contain UTF-8 characters in the user information (i.e. the username or password), path, query or fragment components of the URL, you can simply use the UTF-8 parsing mode. For example:

UTF-8 characters in the domain name, however, are a bit more complex issue. The parser, however, does provide a rudimentary support for parsing these domain names using the IDNA mode. For example:

Note that using this parsing mode requires the PHP extension intl to be enabled. The appropriate parsing mode can also be provided to the constructor of the Uri component using the second constructor parameter.

While support for parsing these UTF-8 characters is available, this library does not provide any methods for the reverse operations since the purpose of this library is to deal with RFC 3986 compliant URIs.

URL Normalization

Due to the fact that the RFC 3986 specification defines some URLs as equivalent despite having some slight differences, this library does some minimal normalization to the provided values. You may encounter these instances when, for example, parsing URLs provided by users. The most notable normalizations you may encounter are as follows:

Credits

This library is Copyright (c) 2013-2022 Riikka Kalliomäki.

See LICENSE for license and copying information.


All versions of kit-urlparser with dependencies

PHP Build Version
Package Version
Requires php Version >=5.6.0
psr/http-message Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package riimu/kit-urlparser contains the following files

Loading the files please wait ....