Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-popa88 committed Dec 18, 2018
1 parent 25a98b7 commit 14f081c
Showing 1 changed file with 107 additions and 3 deletions.
110 changes: 107 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,113 @@
### Installation

```
composer require keppler/url
composer require keppler/url
```

### License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
Quickstart
----------

Parser and Builder
----------

This package is split into 2 independent pieces. These pieces are also split into several other pieces.

The Scheme.php will be referred to as Parser in the documentation.

Parser
------

The Parser is the entry point for parsing a url. It's immutable, meaning you cannot change it once it is created.

The scheme is split into schemes such as ftp, http, https, mailto, etc.
Each scheme is used to parse a single url type, as you might have guessed.

require 'vendor/autoload.php';

$url = 'ftp://user:password@host:123/path';

$scheme = Scheme::ftp($url);

print_r($scheme->all());

...

Array
(
[scheme] => ftp
[user] => user
[password] => password
[host] => host
[port] => 123
[path] => Array
(
[0] => path
)

)

At the time of this writing the parser supports 4 schemes: FTP, HTTPS, HTTP, and MAILTO

Builder
-------

The Builder.php class is the entry point for modifying a url or simply creating one from scratch.
If you choose to build from an existing url you must pass it a Parser instance with the appropriate scheme.

At the time of this writing the Builder supports 4 schemes: FTP, HTTPS, HTTP, and MAILTO

````
require 'vendor/autoload.php';
$url = 'ftp://user:password@host:123/path';
$ftpScheme = Scheme::ftp($url);
$builder = Builder::ftp($ftpScheme);
$builder->setHost('example.com')
->setPassword('hunter2')
->setPort(5);
print_r($builder->raw());
...
ftp://user:hunter2@example.com:5/path/
print_r($builder->encoded());
...
ftp://user:hunter2@example.com:5/path/to+encode/ // notice the extra +
````

Both the Parser and the Builder can be used independently.

Each supported scheme can also be used independently without the Builder or the Parser. Examples bellow.

Independent usage
-----------------

Assuming you don't want to use the Parser/Builder classes directly you can choose not to.

Each scheme supported can be used independently of the Parser/Builder.


$ftpUrl = 'ftp://user:password@host:123/path';

$ftpImmutable = new FtpImmutable($ftpUrl);

echo $ftpImmutable->raw();

```
$ftpBuilder = new FtpBuilder();
$ftpBuilder->setHost('host')
->setPassword('hunter2')
->setPort(987)
->setUser('hunter');
$ftpBuilder->getPathBag()
->set(0, 'path')
->set(1, 'new path');
echo $ftpBuilder->raw(); // ftp://hunter:hunter2@host:987/path/new path/
echo $ftpBuilder->encoded(); // ftp://hunter:hunter2@host:987/path/new+path/

0 comments on commit 14f081c

Please sign in to comment.