| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
namespace Carbon\Traits; |
| 15 |
|
| 16 |
use Carbon\FactoryImmutable; |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
trait Macro |
| 24 |
{ |
| 25 |
use Mixin; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public static function macro(string $name, ?callable $macro): void |
| 47 |
{ |
| 48 |
FactoryImmutable::getDefaultInstance()->macro($name, $macro); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public static function resetMacros(): void |
| 55 |
{ |
| 56 |
FactoryImmutable::getDefaultInstance()->resetMacros(); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public static function genericMacro(callable $macro, int $priority = 0): void |
| 68 |
{ |
| 69 |
FactoryImmutable::getDefaultInstance()->genericMacro($macro, $priority); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public static function hasMacro(string $name): bool |
| 80 |
{ |
| 81 |
return FactoryImmutable::getInstance()->hasMacro($name); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public static function getMacro(string $name): ?callable |
| 88 |
{ |
| 89 |
return FactoryImmutable::getInstance()->getMacro($name); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public function hasLocalMacro(string $name): bool |
| 96 |
{ |
| 97 |
return ($this->localMacros && isset($this->localMacros[$name])) || $this->transmitFactory( |
| 98 |
static fn () => static::hasMacro($name), |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public function getLocalMacro(string $name): ?callable |
| 106 |
{ |
| 107 |
return ($this->localMacros ?? [])[$name] ?? $this->transmitFactory( |
| 108 |
static fn () => static::getMacro($name), |
| 109 |
); |
| 110 |
} |
| 111 |
} |