Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 2b2342b

Browse files
Added new page for URL library (#8384)
* Added new page for URL library * Added new page to TOC * Fixed PHP code doc blocks * Added symlink to 2.4 Co-authored-by: Jeff Matthews <[email protected]>
1 parent 8459d7c commit 2b2342b

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

src/_data/toc/php-developer-guide.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ pages:
265265
- label: Array Manager
266266
url: /extension-dev-guide/framework/array-manager.html
267267

268+
- label: URL Library
269+
url: /extension-dev-guide/framework/url-library.html
270+
268271
- label: Security
269272
children:
270273

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
group: php-developer-guide
3+
title: URL Library
4+
contributor_name: Adarsh Manickam
5+
contributor_link: https://github.com/drpayyne
6+
---
7+
8+
## Overview
9+
10+
This URL library provides numerous utilities to work with URLs. Some of the most useful URL utilities are described below.
11+
12+
## URL Utilities
13+
14+
### Encoder
15+
16+
The [`Magento\Framework\Url\EncoderInterface`]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Url/EncoderInterface.php){:target="_blank"} provides a method to `encode` the URL provided to it into a base64 format and also escapes the special charaters described in the table below.
17+
18+
|Special Character|Encoded Value|
19+
|--- |--- |
20+
| `+` | `-` |
21+
| `/` | `_` |
22+
| `=` | `,` |
23+
24+
### Decoder
25+
26+
The [`Magento\Framework\Url\DecoderInterface`]({{ site.mage2bloburl }}/{{ page.guide_version }}/lib/internal/Magento/Framework/Url/DecoderInterface.php){:target="_blank"} provides a method to `decode` the base64 encoded URL provided to it and also decodes the special characters described in the table below.
27+
28+
|Special Character|Decoded Value|
29+
|--- |--- |
30+
| `-` | `+` |
31+
| `_` | `/` |
32+
| `,` | `=` |
33+
34+
## Usage
35+
36+
Declare `SerializerInterface` as a [constructor dependency]({{ page.baseurl }}/extension-dev-guide/depend-inj.html) to get an instance of a serializer class.
37+
38+
```php
39+
use Magento\Framework\Url\DecoderInterface;
40+
use Magento\Framework\Url\EncoderInterface;
41+
42+
/**
43+
* @var EncoderInterface
44+
*/
45+
private $encoder;
46+
47+
/**
48+
* @var DecoderInterface
49+
*/
50+
private $decoder;
51+
52+
/**
53+
* QuickCartTaxInput constructor.
54+
*
55+
* @param EncoderInterface $encoder
56+
* @param DecoderInterface $decoder
57+
*/
58+
public function __construct(
59+
EncoderInterface $encoder,
60+
DecoderInterface $decoder
61+
) {
62+
$this->encoder = $encoder;
63+
$this->decoder = $decoder;
64+
}
65+
66+
/**
67+
* Encodes URL to base64 format and escapes special characters.
68+
*
69+
* @param string $url
70+
*
71+
* @return string
72+
*/
73+
public function encodeURL($url): string
74+
{
75+
return $this->encoder->encode($url);
76+
}
77+
78+
/**
79+
* Decodes URL from base64 format and special characters.
80+
*
81+
* @param string $encodedUrl
82+
*
83+
* @return string
84+
*/
85+
public function decodeURL($encodedUrl): string
86+
{
87+
return $this->decoder->decode($encodedUrl);
88+
}
89+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../v2.3/extension-dev-guide/framework/url-library.md

0 commit comments

Comments
 (0)