| Server IP : 104.26.2.156 / Your IP : 216.73.216.185 Web Server : nginx/1.27.1 System : Linux us-1 5.15.0-131-generic #141-Ubuntu SMP Fri Jan 10 21:18:28 UTC 2025 x86_64 User : vinodai ( 3134) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /storage/v1396/wwwindicidolscom/public_html/wp-content/plugins/give/src/Log/ValueObjects/ |
Upload File : |
<?php
namespace Give\Log\ValueObjects;
use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
use ReflectionClass;
use ReflectionException;
/**
* Class ValueObject
* @package Give\Log\ValueObjects
*
* @since 2.10.0
*/
abstract class Enum implements EnumInterface
{
/**
* @var mixed
*/
protected $value;
/**
* ValueObject constructor.
*
* @param mixed $value
*/
final public function __construct($value)
{
if ($value instanceof static) {
$value = $value->getValue();
}
if ( ! self::isValid($value)) {
throw new InvalidArgumentException(
sprintf('Invalid %s enumeration value provided %s', static::class, $value)
);
}
$this->value = strtoupper($value);
}
/**
* Get an array of defined constants
*
* @return array
*/
public static function getAll()
{
static $constants = [];
if ( ! isset($constants[static::class])) {
try {
$reflection = new ReflectionClass(static::class);
$constants[static::class] = $reflection->getConstants();
} catch (ReflectionException $exception) {
return [];
}
}
return $constants[static::class];
}
/**
* @inheritDoc
*/
public function getValue()
{
$constants = self::getAll();
if (isset($constants[$this->value])) {
return $constants[$this->value];
}
return null;
}
/**
* Check if value is valid
*
* @param string $value
*
* @return bool
*/
public static function isValid($value)
{
return array_key_exists(
strtoupper($value),
self::getAll()
);
}
/**
* @inheritDoc
*/
public function equalsTo($value)
{
return $value instanceof self && $this->getValue() === $value->getValue();
}
/**
* @param string $name
* @param array $args
*
* @return static
*/
public static function __callStatic($name, $args)
{
if (self::isValid($name)) {
return new static($name);
}
throw new InvalidArgumentException("Invalid argument, does not match constant {$name}");
}
}