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 | |
function getEmojiFlag(string $countryCode): string | |
{ | |
$regionalOffset = 0x1F1A5; | |
return mb_chr($regionalOffset + mb_ord($countryCode[0], 'UTF-8'), 'UTF-8') | |
. mb_chr($regionalOffset + mb_ord($countryCode[1], 'UTF-8'), 'UTF-8'); | |
} |
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 | |
namespace App\Entity; | |
use App\Status; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Entity() | |
*/ |
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 | |
namespace App; | |
use App\DoctrineType\AbstractEnumType; | |
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | |
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\HttpKernel\Kernel as BaseKernel; |
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 StatusType extends AbstractEnumType | |
{ | |
public const NAME = 'status'; | |
public function getName(): string // the name of the type. | |
{ | |
return self::NAME; | |
} |
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 | |
namespace App\DoctrineType; | |
use Doctrine\DBAL\Platforms\AbstractPlatform; | |
use Doctrine\DBAL\Types\Type; | |
abstract class AbstractEnumType extends Type | |
{ | |
abstract public static function getEnumsClass(): string; |
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 | |
namespace App; | |
enum Status: string { | |
case Draft = 'draft'; | |
case Deleted = 'deleted'; | |
case Published = 'published'; | |
} |
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 | |
namespace App\Domain; | |
final class Status | |
{ | |
public const DELETED = 'deleted'; | |
public function getDeletedStatus(): string | |
{ | |
return self::DELETED; |
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 | |
// Article.php | |
final class Article | |
{ | |
// properties, getters | |
public function markAsPublished(): self | |
{ | |
if ($this->status === Article::DELETED)) { | |
throw new LogicException(sprintf("Cannot mark as published as the article is deleted")); | |
} |
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 ArticleStatus | |
{ | |
public DRAFT = 'draft'; | |
public PUBLISHED = 'published'; | |
public DELETED = 'deleted'; | |
private string $value; | |
public function ALL = [ |
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 Article | |
{ | |
public const DELETED = 'deleted'; // ๐ Use this constant is more readable and prevent typos | |
public const PUBLISHED = 'published'; | |
private string $status; | |
// getters & setters | |
} |