Skip to content

Instantly share code, notes, and snippets.

View ismail1432's full-sized avatar
๐Ÿ 
Looking for remote job

Smaine Milianni ismail1432

๐Ÿ 
Looking for remote job
View GitHub Profile
<?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');
}
<?php
namespace App\Entity;
use App\Status;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
<?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;
<?php
class StatusType extends AbstractEnumType
{
public const NAME = 'status';
public function getName(): string // the name of the type.
{
return self::NAME;
}
<?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;
<?php
namespace App;
enum Status: string {
case Draft = 'draft';
case Deleted = 'deleted';
case Published = 'published';
}
<?php
namespace App\Domain;
final class Status
{
public const DELETED = 'deleted';
public function getDeletedStatus(): string
{
return self::DELETED;
<?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"));
}
<?php
final class ArticleStatus
{
public DRAFT = 'draft';
public PUBLISHED = 'published';
public DELETED = 'deleted';
private string $value;
public function ALL = [
<?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
}