litgroup / enumerable.php Goto Github PK
View Code? Open in Web Editor NEWLibrary for implementation of the enumerable types in PHP.
License: MIT License
Library for implementation of the enumerable types in PHP.
License: MIT License
Remove deprecated methods:
Enumerable::getIndex()
EnumerableTestCase::assertEnumIndex()
EnumerableTestCase::assertEnumIndexs()
Allow only string
and int
for indexes.
Enumerable
should implement Equatable
interface from litgroup/equatable
package to be consistent with other objects.
This is the reminder for myself.
Implement __toString()
, which will return information for debug.
Example
Let we have some enum class:
namespace Acme;
use LitGroup\Enumerable\Enumerable;
final class ColorEnum extends Enumerable
{
public static function red()
{
return self::createEnum('#FF0000');
}
public static function green()
{
return self::createEnum('#00FF00');
}
public static function blue()
{
return self::createEnum('#0000FF');
}
}
If we convert enumerable value to string:
echo (string) Acme\ColorEnum::green();
Then next line should be printed:
Acme\ColorEnum::green
Next assertion should fail, because not all values were enumerable as $payload
of the assertion:
$this->assertEnumIndexes([
self::MALE => Gender::male(),
]);
Successful example:
$this->assertEnumIndexes([
self::MALE => Gender::male(),
self::FEMALE => Gender::female(),
]);
Mark Enumerable::getValue()
as deprecated and add Enumerable::getValueOf()
Currently Enumerable::getValues()
returns an associative array of enumerable with index
of enum used for array's key.
Order of keys in array is predicted by order of static methods, which defines available values of enum.
It may be useful to sort values
on the moment of the first initialization of enum class.
I think that it can be useful only if indexes of enum are sequence of integers.
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.