I am using the base64_decode()
and base64_encode()
in my code but PHPCS
says
The use of function base64_decode() is discouraged
so what's the equivalence of this core PHP function in Magento2?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI am using the base64_decode()
and base64_encode()
in my code but PHPCS
says
The use of function base64_decode() is discouraged
so what's the equivalence of this core PHP function in Magento2?
Magento does not have equivalence function of base64_decode() and base64_encode()
method.
Using phpcs:ignore
you can use these two methods.Like Below
// phpcs:ignore Magento2.Functions.DiscouragedFunction
base64_decode($content);
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
Both the method have different Interface.
Magento\Framework\Url\EncoderInterface.php used for encode URL.
Magento\Framework\Url\DecoderInterface.php used for decode URL.
public function __construct(
\Magento\Framework\Url\EncoderInterface $urlEncoder,
\Magento\Framework\Url\DecoderInterface $urlDecoder
) {
$this->urlEncoder = $urlEncoder;
$this->urlDecoder = $urlDecoder;
}
public function execute()
{
//base64_encode()
$this->urlEncoder->encode($Url);
//base64_decode()
$this->urlDecoder->decode($UrlEncoded);
}