-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConstant.php
More file actions
42 lines (36 loc) · 816 Bytes
/
Constant.php
File metadata and controls
42 lines (36 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
namespace Crmplease\Coder;
use function constant;
use function explode;
use function ltrim;
use function strpos;
use function strtolower;
/**
* @author Mougrim <rinat@mougrim.ru>
*/
class Constant
{
private $constant;
public function __construct(string $constant)
{
$this->constant = $constant;
}
public function getConstant(): string
{
return $this->constant;
}
/**
* @return mixed
*/
public function getValue()
{
if (strpos($this->constant, '::') !== false) {
[$class, $constant] = explode('::', $this->constant);
if (strtolower($constant) === 'class') {
return ltrim($class, '\\');
}
}
return constant($this->constant);
}
}