PHP Classes

File: src/Contracts/Customs/AbstractCustomPaths.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/Contracts/Customs/AbstractCustomPaths.php   Download  
File: src/Contracts/Customs/AbstractCustomPaths.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: Update of src/Contracts/Customs/AbstractCustomPaths.php
Date: 6 months ago
Size: 1,838 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

namespace
HeroQR\Contracts\Customs;

/**
 * Abstract class for managing custom marker paths.
 *
 * This class provides the base functionality for handling marker paths,
 * including methods for retrieving paths, validating keys, and checking for valid markers.
 * Subclasses will implement the logic for storing and handling custom marker paths.
 *
 * @package HeroQR\Contracts\Customs
 */
abstract class AbstractCustomPaths
{
   
/**
     * Returns all paths as an associative array
     *
     * @return array
     */
   
abstract public static function getAllPaths(): array;

   
/**
     * Checks if the given key is a valid marker key
     *
     * @param string $key
     * @return bool
     */
   
public static function isValidKey(string $key): bool
   
{
        return
array_key_exists($key, static::getAllPaths());
    }

   
/**
     * Retrieves the path for a specific marker key
     *
     * @param string $key
     * @return string
     * @throws \InvalidArgumentException
     */
   
public static function getPath(string $key): string
   
{
       
$paths = static::getAllPaths();

        if (!isset(
$paths[$key])) {
            throw new \
InvalidArgumentException("Invalid marker key : {$key}");
        }

        return
$paths[$key];
    }

   
/**
     * Retrieves the value of a constant based on its key
     *
     * @param string $key
     * @return string|null
     * @throws \InvalidArgumentException
     */
   
public static function getValueByKey(string $key): ?string
   
{
       
$paths = static::getAllPaths();

        if (!isset(
$paths[$key])) {
            throw new \
InvalidArgumentException(
               
"Invalid key '{$key}' provided. Valid keys are : " . implode(', ', array_keys($paths)) . "."
           
);
        }

        return
$paths[$key];
    }
}