Boundaries.php
4 years ago
Cast.php
4 years ago
Comparison.php
2 years ago
Converter.php
2 years ago
Creator.php
2 years ago
Date.php
9 months ago
DeprecatedProperties.php
4 years ago
Difference.php
2 years ago
IntervalRounding.php
2 years ago
IntervalStep.php
4 years ago
Localization.php
9 months ago
Macro.php
4 years ago
MagicParameter.php
2 years ago
Mixin.php
2 years ago
Modifiers.php
4 years ago
Mutability.php
4 years ago
ObjectInitialisation.php
4 years ago
Options.php
2 years ago
Rounding.php
2 years ago
Serialization.php
2 years ago
Test.php
9 months ago
Timestamp.php
1 year ago
ToStringFormat.php
3 years ago
Units.php
2 years ago
Week.php
4 years ago
index.php
3 years ago
Macro.php
43 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Carbon\Traits; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | trait Macro |
| 5 | { |
| 6 | use Mixin; |
| 7 | protected static $globalMacros = []; |
| 8 | protected static $globalGenericMacros = []; |
| 9 | public static function macro($name, $macro) |
| 10 | { |
| 11 | static::$globalMacros[$name] = $macro; |
| 12 | } |
| 13 | public static function resetMacros() |
| 14 | { |
| 15 | static::$globalMacros = []; |
| 16 | static::$globalGenericMacros = []; |
| 17 | } |
| 18 | public static function genericMacro($macro, $priority = 0) |
| 19 | { |
| 20 | if (!isset(static::$globalGenericMacros[$priority])) { |
| 21 | static::$globalGenericMacros[$priority] = []; |
| 22 | \krsort(static::$globalGenericMacros, \SORT_NUMERIC); |
| 23 | } |
| 24 | static::$globalGenericMacros[$priority][] = $macro; |
| 25 | } |
| 26 | public static function hasMacro($name) |
| 27 | { |
| 28 | return isset(static::$globalMacros[$name]); |
| 29 | } |
| 30 | public static function getMacro($name) |
| 31 | { |
| 32 | return static::$globalMacros[$name] ?? null; |
| 33 | } |
| 34 | public function hasLocalMacro($name) |
| 35 | { |
| 36 | return $this->localMacros && isset($this->localMacros[$name]) || static::hasMacro($name); |
| 37 | } |
| 38 | public function getLocalMacro($name) |
| 39 | { |
| 40 | return ($this->localMacros ?? [])[$name] ?? static::getMacro($name); |
| 41 | } |
| 42 | } |
| 43 |