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
8 months ago
DeprecatedProperties.php
4 years ago
Difference.php
2 years ago
IntervalRounding.php
2 years ago
IntervalStep.php
4 years ago
Localization.php
8 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
8 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
Cast.php
19 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Carbon\Traits; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Carbon\Exceptions\InvalidCastException; |
| 5 | use DateTimeInterface; |
| 6 | trait Cast |
| 7 | { |
| 8 | public function cast(string $className) |
| 9 | { |
| 10 | if (!\method_exists($className, 'instance')) { |
| 11 | if (\is_a($className, DateTimeInterface::class, \true)) { |
| 12 | return new $className($this->rawFormat('Y-m-d H:i:s.u'), $this->getTimezone()); |
| 13 | } |
| 14 | throw new InvalidCastException("{$className} has not the instance() method needed to cast the date."); |
| 15 | } |
| 16 | return $className::instance($this); |
| 17 | } |
| 18 | } |
| 19 |