| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of the Carbon package. |
| 7 | * |
| 8 | * (c) Brian Nesbitt <[email protected]> |
| 9 | * |
| 10 | * For the full copyright and license information, please view the LICENSE |
| 11 | * file that was distributed with this source code. |
| 12 | */ |
| 13 | |
| 14 | namespace Carbon\Traits; |
| 15 | |
| 16 | use Carbon\FactoryImmutable; |
| 17 | |
| 18 | /** |
| 19 | * Options related to a static variable. |
| 20 | */ |
| 21 | trait StaticOptions |
| 22 | { |
| 23 | /////////////////////////////////////////////////////////////////// |
| 24 | ///////////// Behavior customization for sub-classes ////////////// |
| 25 | /////////////////////////////////////////////////////////////////// |
| 26 | |
| 27 | /** |
| 28 | * Function to call instead of format. |
| 29 | * |
| 30 | * @var string|callable|null |
| 31 | */ |
| 32 | protected static $formatFunction; |
| 33 | |
| 34 | /** |
| 35 | * Function to call instead of createFromFormat. |
| 36 | * |
| 37 | * @var string|callable|null |
| 38 | */ |
| 39 | protected static $createFromFormatFunction; |
| 40 | |
| 41 | /** |
| 42 | * Function to call instead of parse. |
| 43 | * |
| 44 | * @var string|callable|null |
| 45 | */ |
| 46 | protected static $parseFunction; |
| 47 | |
| 48 | /////////////////////////////////////////////////////////////////// |
| 49 | ///////////// Use default factory for static options ////////////// |
| 50 | /////////////////////////////////////////////////////////////////// |
| 51 | |
| 52 | /** |
| 53 | * @deprecated To avoid conflict between different third-party libraries, static setters should not be used. |
| 54 | * You should rather use the ->settings() method. |
| 55 | * @see settings |
| 56 | * |
| 57 | * Enable the strict mode (or disable with passing false). |
| 58 | * |
| 59 | * @param bool $strictModeEnabled |
| 60 | */ |
| 61 | public static function useStrictMode(bool $strictModeEnabled = true): void |
| 62 | { |
| 63 | FactoryImmutable::getDefaultInstance()->useStrictMode($strictModeEnabled); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Returns true if the strict mode is globally in use, false else. |
| 68 | * (It can be overridden in specific instances.) |
| 69 | * |
| 70 | * @return bool |
| 71 | */ |
| 72 | public static function isStrictModeEnabled(): bool |
| 73 | { |
| 74 | return FactoryImmutable::getInstance()->isStrictModeEnabled(); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @deprecated To avoid conflict between different third-party libraries, static setters should not be used. |
| 79 | * You should rather use the ->settings() method. |
| 80 | * Or you can use method variants: addMonthsWithOverflow/addMonthsNoOverflow, same variants |
| 81 | * are available for quarters, years, decade, centuries, millennia (singular and plural forms). |
| 82 | * @see settings |
| 83 | * |
| 84 | * Indicates if months should be calculated with overflow. |
| 85 | * |
| 86 | * @param bool $monthsOverflow |
| 87 | * |
| 88 | * @return void |
| 89 | */ |
| 90 | public static function useMonthsOverflow(bool $monthsOverflow = true): void |
| 91 | { |
| 92 | FactoryImmutable::getDefaultInstance()->useMonthsOverflow($monthsOverflow); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @deprecated To avoid conflict between different third-party libraries, static setters should not be used. |
| 97 | * You should rather use the ->settings() method. |
| 98 | * Or you can use method variants: addMonthsWithOverflow/addMonthsNoOverflow, same variants |
| 99 | * are available for quarters, years, decade, centuries, millennia (singular and plural forms). |
| 100 | * @see settings |
| 101 | * |
| 102 | * Reset the month overflow behavior. |
| 103 | * |
| 104 | * @return void |
| 105 | */ |
| 106 | public static function resetMonthsOverflow(): void |
| 107 | { |
| 108 | FactoryImmutable::getDefaultInstance()->resetMonthsOverflow(); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Get the month overflow global behavior (can be overridden in specific instances). |
| 113 | * |
| 114 | * @return bool |
| 115 | */ |
| 116 | public static function shouldOverflowMonths(): bool |
| 117 | { |
| 118 | return FactoryImmutable::getInstance()->shouldOverflowMonths(); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @deprecated To avoid conflict between different third-party libraries, static setters should not be used. |
| 123 | * You should rather use the ->settings() method. |
| 124 | * Or you can use method variants: addYearsWithOverflow/addYearsNoOverflow, same variants |
| 125 | * are available for quarters, years, decade, centuries, millennia (singular and plural forms). |
| 126 | * @see settings |
| 127 | * |
| 128 | * Indicates if years should be calculated with overflow. |
| 129 | * |
| 130 | * @param bool $yearsOverflow |
| 131 | * |
| 132 | * @return void |
| 133 | */ |
| 134 | public static function useYearsOverflow(bool $yearsOverflow = true): void |
| 135 | { |
| 136 | FactoryImmutable::getDefaultInstance()->useYearsOverflow($yearsOverflow); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * @deprecated To avoid conflict between different third-party libraries, static setters should not be used. |
| 141 | * You should rather use the ->settings() method. |
| 142 | * Or you can use method variants: addYearsWithOverflow/addYearsNoOverflow, same variants |
| 143 | * are available for quarters, years, decade, centuries, millennia (singular and plural forms). |
| 144 | * @see settings |
| 145 | * |
| 146 | * Reset the month overflow behavior. |
| 147 | * |
| 148 | * @return void |
| 149 | */ |
| 150 | public static function resetYearsOverflow(): void |
| 151 | { |
| 152 | FactoryImmutable::getDefaultInstance()->resetYearsOverflow(); |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * Get the month overflow global behavior (can be overridden in specific instances). |
| 157 | * |
| 158 | * @return bool |
| 159 | */ |
| 160 | public static function shouldOverflowYears(): bool |
| 161 | { |
| 162 | return FactoryImmutable::getInstance()->shouldOverflowYears(); |
| 163 | } |
| 164 | } |