PHP Classes

File: src/Managers/EncodingManager.php

Recommend this page to a friend!
  Packages of Amirreza Ebrahimi   HeroQR Powerful PHP QR Code Library to generate PNG, SVG, PDF, Logos Ready to Use with Laravel   src/Managers/EncodingManager.php   Download  
File: src/Managers/EncodingManager.php
Role: Class source
Content type: text/plain
Description: Class source
Class: HeroQR Powerful PHP QR Code Library to generate PNG, SVG, PDF, Logos Ready to Use with Laravel
Generate QR code images in several formats
Author: By
Last change: feat: add SVG customization support for shapes, markers, and cursors (previously only PNG)
Date: 15 days ago
Size: 1,450 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
HeroQR\Managers;

use
Endroid\QrCode\Encoding\{EncodingInterface,Encoding};
use
HeroQR\Contracts\Managers\EncodingManagerInterface;

/**
 * Manages the character encoding for QR codes
 * Ensures proper encoding for different data types and provides methods
 * to set or retrieve the current encoding
 */
class EncodingManager implements EncodingManagerInterface
{
    private
EncodingInterface $encoding;

   
/**
     * EncodingManager constructor
     * Initializes the encoding with a default value of 'UTF-8'
     */
   
public function __construct()
    {
       
$this->encoding = new Encoding('UTF-8');
    }

   
/**
     * Get the current encoding
     *
     * @return EncodingInterface The current encoding object
     */
   
public function getEncoding(): EncodingInterface
   
{
        return
$this->encoding;
    }

   
/**
     * Set a new encoding for QR code generation
     *
     * @param string $encoding The desired encoding (e.g., 'UTF-8', 'UTF-16', 'ASCII', 'ISO-8859-1', etc.)
     * @throws \InvalidArgumentException If the encoding string is empty
     * @throws \Exception If the encoding is invalid or unsupported by the library
     */
   
public function setEncoding(string $encoding): void
   
{
        if (empty(
$encoding)) {
            throw new \
InvalidArgumentException('Encoding Cannot Be Empty');
        }

       
$this->encoding = new Encoding($encoding);
    }
}