grifart / enum Goto Github PK
View Code? Open in Web Editor NEWThe first if-less and switch-less enum for PHP. Push behaviour down to enumerated values.
Home Page: https://packagist.org/packages/grifart/enum
License: MIT License
The first if-less and switch-less enum for PHP. Push behaviour down to enumerated values.
Home Page: https://packagist.org/packages/grifart/enum
License: MIT License
ConsistencyChecker will throw Grifart\Enum\UsageException: You have forgotten to add @method annotations for enum 'Survilla\Enum\Enum'. Documentation block should contain
if Survilla\Enum\Enum is an abstract class declaring provideInstances method.
/**
*@method static ExampleEnum ONE()
*@method static ExampleEnum TWO()
*@method static ExampleEnum THREE()
*/
class ExampleEnum extends MyEnumsAbstract {
private const ONE = 'one';
private const TWO = 'two';
private const THREE = 'three';
}
abstract class MyEnumsAbstract extends \Grifart\Enum\Enum {
use Grifart\Enum\AutoInstances;
/** Some common behavior... **/
}
Hi, personally I don't like abstract classes and static calls... What do You think about this implementation?
interface DayOfWeek
{
public function nextDay(): self;
}
class Monday implements DayOfWeek
{
public function nextDay(): DayOfWeek
{
return new Tuesday();
}
}
class Tuesday implements DayOfWeek
{
public function nextDay(): DayOfWeek
{
return new Tuesday();
}
}
Hi, when I read the Enum
, I find a lots of abstract concepts that are difficult to understand... is anything wrong with this implementation?
abstract class DayOfWeek
{
protected const MONDAY = 'monday';
protected const TUESDAY = 'tuesday';
public abstract function nextDay(): self;
public static function MONDAY(): self
{
return new class extends DayOfWeek
{
public function nextDay(): DayOfWeek
{
return DayOfWeek::TUESDAY();
}
};
}
public static function TUESDAY(): self
{
return new class extends DayOfWeek
{
public function nextDay(): DayOfWeek
{
return DayOfWeek::WEDNESDAY();
}
};
}
}
They are technically required only when AutoInstances
are used.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.