Files
michaelschiemer/src/Framework/View/ValueObjects/DataAttributeHelper.php
2025-11-24 21:28:25 +01:00

32 lines
846 B
PHP

<?php
declare(strict_types=1);
namespace App\Framework\View\ValueObjects;
/**
* Helper functions for working with data attributes
*
* Provides convenience methods for converting data attribute enums to strings
* and working with both string and enum attribute names.
*/
final readonly class DataAttributeHelper
{
/**
* Convert attribute name to string
*
* Accepts both string and DataAttributeInterface for convenience.
* This allows methods to accept either format without requiring ->value() calls.
*
* @param string|DataAttributeInterface $attribute
* @return string
*/
public static function toString(string|DataAttributeInterface $attribute): string
{
return $attribute instanceof DataAttributeInterface
? $attribute->value()
: $attribute;
}
}