EnumConcern is a freshly presented PHP bundle customized to simplify the use of PHP’s Enum attribute by offering a thorough collection of techniques. Backed by Laravel Collections, EnumConcern intends to use a smooth and also acquainted experience.
Trick Attributes of EnumConcern:
-
Adaptability: EnumConcern consists of a selection of techniques that allow very easy handling of Enums, such as
all
,has
,caseExists
, and also extra. - Conversion Capacities: The bundle uses techniques to transform Enums to numerous styles like JSON, variety, or key-value collections.
-
Personalization: There’s adaptability in getting parts of worths with the techniques
just
,onlyAsArray
,other than
,exceptAsArray
, and so on -
Energy Features: Features like
randomValue
,randomCase
,initially
, and alsolast
offer additional energy.
EnumConcern Use:
EnumConcern incorporates efficiently right into existing enums, allowing features like translation and also numerous checks. Below’s an instance of just how to convert shade Enums to Turkish:
namespace AppEnums;
usage EmreYarliganEnumConcernEnumConcern;
enum Shade: string
{
usage EnumConcern;
instance RED = " Red";
instance ENVIRONMENT-FRIENDLY = " Environment-friendly";
instance BLUE = " Blue";
public feature translateToTurkish(): string
{
return suit ($ this) {
self:: RED =>> ' Kırmızı',
self:: ENVIRONMENT-FRIENDLY =>> ' YeÅŸil',
self:: BLUE =>> ' Mavi',
};
}
}
Shade:: all();
// Outcome: IlluminateSupportCollection (7) [
// [0] => > 'Red',
// [1] => > 'Environment-friendly',
// [2] => > 'Blue
//]
Shade:: all(' translateToTurkish');
// Outcome: IlluminateSupportCollection (7) [
// [0] => > 'Kırmızı',
// [1] => > 'YeÅŸil',
// [2] => > 'Mavi
//]
Shade:: has(' Purple');
// incorrect
Shade:: has(' Mavi',' translateToTurkish');
// real
With features like Shade:: all(' translateToTurkish')
, you can recover converted worths easily.
EnumConcern Approaches
-
all
: Obtain all the worths as a Collection. Specifications:technique ="
(optional). Return Kind:Collection
-
allAsArray
: Obtain all the worths as a range. Specifications:technique ="
(optional). Return Kind:variety
-
has
: Examine if a details worth exists. Specifications:worth
,technique ="
(optional). Return Kind:bool
-
caseExists
: Examine if a details instance (crucial/ name) exists. Specifications:worth
,technique ="
(optional). Return Kind:bool
-
allCasesExists
: Examine if all the offered situations (keys/names) exist. Specifications:situations
,technique ="
(optional). Return Kind:bool
-
anyCaseExists
: Examine if any one of the offered situations (keys/names) exist. Specifications:situations
,technique ="
(optional). Return Kind:bool
-
caseByValue
: Obtain the instance (key/name) for a details worth. Specifications:worth
,technique ="
(optional). Return Kind:string
-
toJson
: Transform all the worths to a JSON string. Specifications:technique ="
(optional),jsonEncodeOption
(optional). Return Kind:string
-
toArray
: Transform all the worths to a range. Specifications:technique ="
(optional). Return Kind:variety
-
toKeyValueCollection
: Transform all the worths to a key-value style as a Collection. Specifications:technique ="
(optional). Return Kind:Collection
-
toKeyValueArray
: Transform all the worths to a key-value style as a range. Specifications:technique ="
(optional). Return Kind:variety
-
randomValue
: Obtain an arbitrary worth from the collection of worths. Specifications:technique ="
(optional). Return Kind:blended
-
randomCase
: Obtain an arbitrary instance (key/name) from the collection of worths. Specifications: None. Return Kind:string
-
casesCollection
: Obtain all the situations (keys/names) of the Enum as a Collection. Specifications: None. Return Kind:Collection
-
casesArray
: Obtain all the situations (keys/names) of the Enum as a range. Specifications: None. Return Kind:variety
-
allToArray
: Obtain all the worths as a range (Pen name fortoArray
technique). Specifications:technique ="
(optional). Return Kind:variety
-
just
: Obtain a part of the worths as a Collection, just consisting of the defined situations (keys/names). Specifications:situations
,technique ="
(optional). Return Kind:Collection
-
onlyAsArray
: Obtain a part of the worths as a range, just consisting of the defined situations (keys/names). Specifications:situations
,technique ="
(optional). Return Kind:variety
-
other than
: Obtain a part of the worths as a Collection, leaving out the defined situations (keys/names). Specifications:situations
,technique ="
(optional). Return Kind:Collection
-
exceptAsArray
: Obtain a part of the worths as a range, leaving out the defined situations (keys/names). Specifications:situations
,technique ="
(optional). Return Kind:variety
-
initially
: Obtain the very first worth in the Enum. Specifications:technique ="
(optional). Return Kind:blended
-
last
: Obtain the last worth in the Enum. Specifications:technique ="
(optional). Return Kind:blended
Final Thought:
EnumConcern uses a durable service for taking care of Enums in PHP, incorporating flawlessly with Laravel Collections and also offering a host of valuable techniques. Whether you require to inspect, transform, or adjust Enums, EnumConcern streamlines the procedure, conserving effort and time.
For even more in-depth instances and also extensive paperwork, you can describe the main EnumConcern paperwork.