This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| declare(strict_types=1); | |
| pcntl_async_signals(true); | |
| function printNow(): void { | |
| echo (new DateTime())->format('Y-m-d H:i:s'), "\n"; | |
| //echo (new DateTime())->getTimestamp(), "\n"; // no segfault | |
| //$dt = (new DateTime())->format('Y-m-d H:i:s'); echo $dt, "\n"; // no segfault |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * In this example, we'd use it like throw new FileNotFoundException($missingFileName) | |
| * or throw new FileNotFoundException(sprintf("File not found")) or | |
| * throw new FileNotFoundException(sprintf("File %s not found", $missingFileName)) | |
| * which quickly leads to non-uniform messages and hard-to-process/recover exceptions. | |
| * | |
| * Is it possible to perhaps send nice e-mail message? | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @method static WorldSide NORTH | |
| * @method static WorldSide SOUTH | |
| * @method static WorldSide EAST | |
| * @method static WorldSide WEST | |
| */ | |
| abstract class WorldSide extends \Zlikavac32\Enum\Enum | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @method static YesNo YES | |
| * @method static YesNo NO | |
| */ | |
| abstract class YesNo extends \Zlikavac32\Enum\Enum | |
| { | |
| protected static function enumerate(): array | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| final class YesNo extends \Eloquent\Enumeration\AbstractEnumeration { | |
| const NO = 0; | |
| const YES = 1; | |
| } | |
| var_dump(YesNo::YES()->key()); // YES |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class YesNo extends \SplEnum | |
| { | |
| const __default = self::YES; | |
| const NO = 0; | |
| const YES = 1; | |
| } | |
| $no = new YesNo(YesNo::NO); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| interface UserFactory { | |
| public function create( | |
| string $email, | |
| int $gender, | |
| int $status | |
| ): User; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class User { | |
| const GENDER_MALE = 0; | |
| const GENDER_FEMALE = 1; | |
| const STATUS_INACTIVE = 0; | |
| const STATUS_ACTIVE = 1; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| declare(strict_types=1); | |
| /** | |
| * Proof of concept for better enums in PHP. Supports type-hinting and per enum abstract method implementation | |
| */ | |
| abstract class Enum | |
| { | |
| private static $existingEnums = []; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //... | |
| public function testThatOnMondayItWorks(): void { | |
| try { | |
| timecop_travel(new DateTime('2017-08-28 00:00:00')); //Monday | |
| $output = $this->runCommand('some-command'); | |
NewerOlder