https://github.com/maximgrynykha/urling
๐ฏ URL parser & constructor in PHP
https://github.com/maximgrynykha/urling
create-uri create-url php uri uri-builder uri-constructor uri-extend uri-manipulation uri-parser uris url url-builder url-constructor url-extend url-manipulation url-parser urling urls
Last synced: 5 months ago
JSON representation
๐ฏ URL parser & constructor in PHP
- Host: GitHub
- URL: https://github.com/maximgrynykha/urling
- Owner: maximgrynykha
- License: mit
- Created: 2021-03-07T10:42:36.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-02T03:08:21.000Z (over 4 years ago)
- Last Synced: 2024-12-05T22:34:47.600Z (over 1 year ago)
- Topics: create-uri, create-url, php, uri, uri-builder, uri-constructor, uri-extend, uri-manipulation, uri-parser, uris, url, url-builder, url-constructor, url-extend, url-manipulation, url-parser, urling, urls
- Language: PHP
- Homepage: https://github.com/ismaxim/urling
- Size: 854 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://github.com/ismaxim/urling#%EF%B8%8F-installation)

# __Urling__
> ๐โะะพะบัะผะตะฝัะฐัะธั ะฝะฐ ััััะบะพะผ โโ|โะะพะบัะผะตะฝัะฐััั ะฝะฐ ัะบัะฐัะฝััะบัะน โ
## โ๏ธ Installation
To install this library - run the command below in your terminal:
```shell
composer require ismaxim/urling
```
## ๐ง Usage
### ๐ Concept
#### Three major ideas
๐ 1. Two modes to work with URL: parser mode & constructor mode.
๐ 2. Accessing to concrete part of URL with using aliases (see [ACCESSING TABLE](#accessing-table), column [Aliases](#aliases)).
๐ 3. Base editors for processing complete URL and each part separately (see section [Basic usage](https://github.com/ismaxim/urling#-basic-usage)).
***
### ๐ Start
```php
# Url parser mode
use Urling\Urling;
$urling = new Urling("https://github.com/ismaxim/urling#start");
$url_part_values = [
"protocol_value" => $urling->url->protocol->get(),
"domain_value" => $urling->url->domain->get(),
"routes_value" => $urling->url->routes->get(),
"anchor_value" => $urling->url->anchor->get(),
];
print_r($url_part_values);
/*
RESULT:
[
"protocol_value" => "https",
"domain_value" => "github.com",
"routes_value" => "ismaxim/urling",
"anchor_value" => "start",
]
*/
```
```php
# Url constructor mode
use Urling\Urling;
$urling = new Urling();
$urling->url->construct([
"protocol" => "https",
"domain" => "github.com",
"routes" => "ismaxim/urling",
"anchor" => "start",
]);
// Either you can set the value for each distinct part
// in the url by accessing it directly, for example:
$urling->url->protocol->add("https");
$urling->url->domain->add("github.com");
$urling->url->routes->add("ismaxim/urling");
$urling->url->anchor->add("start");
print_r($urling->url->get());
/*
RESULT:
"https://github.com/ismaxim/urling#start"
*/
```
#### ๐ Accessing
***
You can access to concrete URL part to parse it by using its basename (see [ACCESSING TABLE](#accessing-table), column [Url Part](#url-part)) or ask for its alias (see [ACCESSING TABLE](#accessing-table), column [Aliases](#aliases)) like:
```php
$urling->url->scheme->... | $urling->url->protocol->... (other parts of url in a similar way).
```
__ACCESSING TABLE__
| Url Part | Aliases | Parser |
| ----------------------------- | --------------------------- | --------------------------------------- |
| scheme | protocol | [SchemeParser](https://bit.ly/3vOpzbs) |
| user | username | [UserParser](https://bit.ly/2NLCWYQ) |
| pass | password | [PassParser](https://bit.ly/3lPdkXG) |
| host | hostname, domain | [HostParser](https://bit.ly/394KA8c) |
| port | | [PortParser](https://bit.ly/39aiMz0) |
| path | routes | [PathParser](https://bit.ly/3lEZS8H) |
| query | params, attributes | [QueryParser](https://bit.ly/3d0VaOu) |
| fragment | anchor | [FragmetParser](https://bit.ly/3tKfI4C) |
#### ๐ถ Basic usage
***
__Basic Editors__ - [Base editor of URL](https://bit.ly/3vXg0qA) and [Base editor of part of URL](https://bit.ly/3tNXSgZ) cover almost all tasks: *__add, get, update or remove__* URL or values anywhere in it. __Base Editors__ are "CRUDable" wrappers over the __parse_url()__ function from native PHP, and according to this fact, they return and modify values in a similar way. The only significant difference is the syntax of calls when parsing a URL or its parts.
```php
// Working with URL
$urling->url->add();
$urling->url->get();
$urling->url->update();
$urling->url->delete();
// Working with one of the URL parts
$urling->url->scheme->add();
$urling->url->scheme->get();
$urling->url->scheme->update();
$urling->url->scheme->delete();
// For example, let's imagine that the URL is: https://github.com/ismaxim/urling#basic-usage
// Then example workflow to parse this URL in part of "scheme" or "protocol" (see ACCESSING TABLE, column "Aliases") will seem to this:
$urling->url->scheme->get(); # returns "https" (state of URL: https://github.com/ismaxim/urling#basic-usage)
$urling->url->scheme->delete(); # returns null (state of URL: github.com/ismaxim/urling#basic-usage)
$urling->url->scheme->add("ftp"); # returns "ftp" (state of URL: ftp://github.com/ismaxim/urling#basic-usage)
$urling->url->scheme->update("smtp"); # returns "smtp" (state of URL: smtp://github.com/ismaxim/urling#basic-usage)
// Work with other parts of URL can be done in a similar way.
```
#### ๐ง Advanced usage
***
If you need to do something like *__add, get, update or delete__* the value of any part of the URL, but it's outside the scope of the base functionality, you can use one of the Base editors functions *__add, get, update or delete__* as a prefix with the name of a specific method as postfix appropriate for your task like:
> (add, get, update, delete) + "SomeFunctionName" for the concrete task.
Note: *Almost all functions will use that code convention permanently.*
Examples:
- getValueByName();
- getNameValuePairs();
- etc. ...
```php
$urling->url->params->getValueByName();
$urling->url->params->getNameValuePairs();
```
## ๐งช Testing
_Actually, all tests already automatically passed within CI build._
To test this library - run the command below in your terminal.
```shell
composer test
```
## ๐ค Contributing
If you have a problem that cannot be solved using this library, please write your solution and if you want to help other developers who also use this library (or if you want to keep your solution working after a new version is released, which will go to package manager dependencies) - create a pull-request. We will be happy to add your excellent code to the library!
๐ Report any bugs or issues you find on the [GitHub issues](https://github.com/ismaxim/urling/issues).
### โจ Creating custom functional
You can extend the functionality of the library with your own code, making edits to solve your problems in the parser classes. There are two types of parser classes the first and the main is [URL parser](https://github.com/ismaxim/urling/blob/master/src/Urling/Core/Url.php), but there are others as well, - [URL parts parsers](https://github.com/ismaxim/urling/tree/master/src/Urling/PartParsers). For each part is separate own parser.
Using the library or examining docs you can notice the same or similar to this record:
```php
$urling->url->params->get()
```
This entry might interpret the next way: "Hey, Urling, ask to the part 'params' on the current URL and return it value(this part)".
Basically extending functionality, you will work with a part of the URL almost all times and will processing or get the value for a specific part. To understand how to access to parser for needed part you can look at [ACCESSING TABLE](#accessing-table). You only need to match the [*__url part__*](#url-part) and [*__aliases__*](#aliases) sections with the [*__parser__*](#parser) section, and then go to the desired parser file and write the best code in the world!
## ๐ Credits
- [Maintainer โ](https://github.com/ismaxim)
- [Contributors โ](https://github.com/ismaxim/urling/contributors)
## ๐ License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.