From f3c53364e71db0fde43b885496dceb027ed21b20 Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Mon, 14 Dec 2020 17:45:20 +0530 Subject: [PATCH 1/4] Added new page for URL library --- .../framework/url-library.md | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/guides/v2.3/extension-dev-guide/framework/url-library.md diff --git a/src/guides/v2.3/extension-dev-guide/framework/url-library.md b/src/guides/v2.3/extension-dev-guide/framework/url-library.md new file mode 100644 index 00000000000..b890c00c8e2 --- /dev/null +++ b/src/guides/v2.3/extension-dev-guide/framework/url-library.md @@ -0,0 +1,77 @@ +--- +group: php-developer-guide +title: URL Library +contributor_name: Adarsh Manickam +contributor_link: https://github.com/drpayyne +--- + +## Overview + +This URL library provides numerous utilities to work with URLs. Some of the most useful URL utilities are described below. + +## URL Utilities + +### Encoder + +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. + +|Special Character|Encoded Value| +|--- |--- | +| `+` | `-` | +| `/` | `_` | +| `=` | `,` | + +### Decoder + +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. + +|Special Character|Encoded Value| +|--- |--- | +| `-` | `+` | +| `_` | `/` | +| `,` | `=` | + +## Usage + +Declare `SerializerInterface` as a [constructor dependency]({{ page.baseurl }}/extension-dev-guide/depend-inj.html) to get an instance of a serializer class. + +```php +use Magento\Framework\Url\DecoderInterface; +use Magento\Framework\Url\EncoderInterface; + +/** + * @var EncoderInterface + */ +private $encoder; + +/** + * @var DecoderInterface + */ +private $decoder; + + +public function __construct( + EncoderInterface $encoder, + DecoderInterface $decoder +) { + $this->encoder = $encoder; + $this->decoder = $decoder; +} + +/** + * Encodes URL to base64 format and escapes special characters + */ +public function encodeURL($url) +{ + return $this->encoder->encode($url); +} + +/** + * Decodes URL from base64 format and special characters + */ +public function decodeURL($encodedUrl) +{ + return $this->decoder->decode($encodedUrl); +} +... +``` From d51dd6cf18b20008bee57772579bc20577b28cc8 Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Mon, 14 Dec 2020 17:47:00 +0530 Subject: [PATCH 2/4] Added new page to TOC --- src/_data/toc/php-developer-guide.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/_data/toc/php-developer-guide.yml b/src/_data/toc/php-developer-guide.yml index 578e2636859..d14ff9431a6 100644 --- a/src/_data/toc/php-developer-guide.yml +++ b/src/_data/toc/php-developer-guide.yml @@ -265,6 +265,9 @@ pages: - label: Array Manager url: /extension-dev-guide/framework/array-manager.html + - label: URL Library + url: /extension-dev-guide/framework/url-library.html + - label: Security children: From e20e5b762d4e386e593b5b4d5206f4071ca90269 Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Mon, 14 Dec 2020 19:32:52 +0530 Subject: [PATCH 3/4] Fixed PHP code doc blocks --- .../framework/url-library.md | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/guides/v2.3/extension-dev-guide/framework/url-library.md b/src/guides/v2.3/extension-dev-guide/framework/url-library.md index b890c00c8e2..5717e0059e7 100644 --- a/src/guides/v2.3/extension-dev-guide/framework/url-library.md +++ b/src/guides/v2.3/extension-dev-guide/framework/url-library.md @@ -25,7 +25,7 @@ The [`Magento\Framework\Url\EncoderInterface`]({{ site.mage2bloburl }}/{{ page.g 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. -|Special Character|Encoded Value| +|Special Character|Decoded Value| |--- |--- | | `-` | `+` | | `_` | `/` | @@ -49,7 +49,12 @@ private $encoder; */ private $decoder; - +/** + * QuickCartTaxInput constructor. + * + * @param EncoderInterface $encoder + * @param DecoderInterface $decoder + */ public function __construct( EncoderInterface $encoder, DecoderInterface $decoder @@ -59,19 +64,26 @@ public function __construct( } /** - * Encodes URL to base64 format and escapes special characters + * Encodes URL to base64 format and escapes special characters. + * + * @param string $url + * + * @return string */ -public function encodeURL($url) +public function encodeURL($url): string { return $this->encoder->encode($url); } /** - * Decodes URL from base64 format and special characters + * Decodes URL from base64 format and special characters. + * + * @param string $encodedUrl + * + * @return string */ -public function decodeURL($encodedUrl) +public function decodeURL($encodedUrl): string { return $this->decoder->decode($encodedUrl); } -... ``` From d5e77eaebaff05a786ff94f53ad36a3307c4935b Mon Sep 17 00:00:00 2001 From: Adarsh Manickam Date: Mon, 14 Dec 2020 21:29:15 +0530 Subject: [PATCH 4/4] Added symlink to 2.4 --- src/guides/v2.4/extension-dev-guide/framework/url-library.md | 1 + 1 file changed, 1 insertion(+) create mode 120000 src/guides/v2.4/extension-dev-guide/framework/url-library.md diff --git a/src/guides/v2.4/extension-dev-guide/framework/url-library.md b/src/guides/v2.4/extension-dev-guide/framework/url-library.md new file mode 120000 index 00000000000..990051bf1ea --- /dev/null +++ b/src/guides/v2.4/extension-dev-guide/framework/url-library.md @@ -0,0 +1 @@ +../../../v2.3/extension-dev-guide/framework/url-library.md \ No newline at end of file