Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This file is part of the Carbon package. |
| 5 | * |
| 6 | * (c) Brian Nesbitt <brian@nesbot.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace Carbon\Traits; |
| 12 | |
| 13 | use Carbon\Carbon; |
| 14 | use Carbon\CarbonImmutable; |
| 15 | |
| 16 | /** |
| 17 | * Trait Mutability. |
| 18 | * |
| 19 | * Utils to know if the current object is mutable or immutable and convert it. |
| 20 | */ |
| 21 | trait Mutability |
| 22 | { |
| 23 | use Cast; |
| 24 | |
| 25 | /** |
| 26 | * Returns true if the current class/instance is mutable. |
| 27 | * |
| 28 | * @return bool |
| 29 | */ |
| 30 | public static function isMutable() |
| 31 | { |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Returns true if the current class/instance is immutable. |
| 37 | * |
| 38 | * @return bool |
| 39 | */ |
| 40 | public static function isImmutable() |
| 41 | { |
| 42 | return !static::isMutable(); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Return a mutable copy of the instance. |
| 47 | * |
| 48 | * @return Carbon |
| 49 | */ |
| 50 | public function toMutable() |
| 51 | { |
| 52 | /** @var Carbon $date */ |
| 53 | $date = $this->cast(Carbon::class); |
| 54 | |
| 55 | return $date; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Return a immutable copy of the instance. |
| 60 | * |
| 61 | * @return CarbonImmutable |
| 62 | */ |
| 63 | public function toImmutable() |
| 64 | { |
| 65 | /** @var CarbonImmutable $date */ |
| 66 | $date = $this->cast(CarbonImmutable::class); |
| 67 | |
| 68 | return $date; |
| 69 | } |
| 70 | } |