Download the PHP package emreyarligan/enum-concern without Composer

On this page you can find all versions of the php package emreyarligan/enum-concern. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package enum-concern

EnumConcern - A PHP Package for Effortless Enumeration Handling ๐Ÿ“ฆ โœจ

EnumConcern is a PHP package designed to enhance the usage of PHP's Enum feature with a set of convenient methods. This package includes a Trait file that enables easy handling of Enums.

Powered by Laravel Collections to make you feel at home. ๐Ÿงก

Latest Version Total Downloads


Installation

To install EnumConcern package, require it via composer:

Now, you can use EnumConcern in your Enums.


Methods

Method Description Parameters Return Type
all Get all the values as a Collection. method = '' (optional) Collection
allAsArray Get all the values as an array. method = '' (optional) array
has Check if a specific value exists. value, method = '' (optional) bool
caseExists Check if a specific case (key / name) exists. value, method = '' (optional) bool
allCasesExists Check if all the given cases (keys / names) exist. cases, method = '' (optional) bool
anyCaseExists Check if any of the given cases (keys / names) exist. cases, method = '' (optional) bool
caseByValue Get the case (key / name) for a specific value. value, method = '' (optional) string
toJson Convert all the values to a JSON string. method = '' (optional),jsonEncodeOption (optional) string
toArray Convert all the values to an array. method = '' (optional) array
toKeyValueCollection Convert all the values to a key-value format as a Collection. method = '' (optional) Collection
toKeyValueArray Convert all the values to a key-value format as an array. method = '' (optional) array
randomValue Get a random value from the collection of values. method = '' (optional) mixed
randomCase Get a random case (key / name) from the collection of values. None string
casesCollection Get all the cases (keys / names) of the Enum as a Collection. None Collection
casesArray Get all the cases (keys / names) of the Enum as an array. None array
allToArray Get all the values as an array. (Alias for toArray method) method = '' (optional) array
only Get a subset of the values as a Collection, only including the specified cases (keys / names). cases,method = '' (optional) Collection
onlyAsArray Get a subset of the values as an array, only including the specified cases (keys / names). cases, method = '' (optional) array
except Get a subset of the values as a Collection, excluding the specified cases (keys / names). cases, method = '' (optional) Collection
exceptAsArray Get a subset of the values as an array, excluding the specified cases (keys / names). cases, method = '' (optional) array
first Get the first value in the Enum. method = '' (optional) mixed
last Get the last value in the Enum. method = '' (optional) mixed
fromValue Create an Enum object from a string value. value object
valueNamePairs Get the key-value pairs of value and transformed value (if a method is specified). method = '' (optional) Collection
is Check if the Enum object is equal to the given object. object bool
isNot Check if the Enum object is not equal to the given object. object bool
isAny Check if the Enum object is equal to any of the given objects. objects bool
isNotAny Check if the Enum object is not equal to any of the given objects. objects bool

Basic Usage

You can check the Examples with All Methods section at the bellow of the document for more details.


Examples With All Methods

Step 1: Create Your Enum

Create an Enum class and uses the EnumConcern Trait.

Here's an example for this paper. I created a trait about fruits for the example, isn't it ingenious? ๐Ÿ˜›

Note: This README includes examples that are valid for both int and string types of Enum values. The EnumConcern Trait handles both types of Enum values in the same way. This allows you to use the EnumConcern Trait for both types of Enum in your project and facilitate the handling of Enum values.

Here's string Enum example:


Step 2: Enum Handling with EnumConcern

EnumConcern provides several convenient methods to handle your Enum values.

all() Method

Get all the Enum values as a Collection (empty $method)

Result:

Get all the Enum values as a Collection using 'emojis' method

Result:

Get all the Enum values as a Collection using 'names' method.

Result:


has() method

Check if a specific value exists (empty $method)

Check if a specific value exists using 'emojis' method

Check if a specific value exists using 'names' method


keyByValue() method

Get the case (key / name) for a specific value (empty $method)

Get the case (key / name) for a specific value using 'emojis' method

Get the case (key / name) for a specific value using 'names' method


toJson() method

Convert all the values to a JSON string (empty $method)

Convert all the values to a JSON string using 'emojis' method

Convert all the values to a JSON string using 'names' method


toArray() method

Convert all the values to an array (empty $method)

Result:

Convert all the values to an array using 'emojis' method

Result:

Convert all the values to an array using 'names' method

Result:


toKeyValueCollection() method

Convert all the values to a key-value format as a Collection (empty $method)

Result:

Convert all the values to a key-value format as a Collection with keyAttributeName and valueAttributeName parameters (empty $method)

Result:

Convert all the values to a key-value format as a Collection using 'emojis' method

Result:

Convert all the values to a key-value format as a Collection using 'emojis' method with keyAttributeName and valueAttributeName parameters

Result:

Convert all the values to a key-value format as a Collection using 'names' method

Result:

Convert all the values to a key-value format as a Collection using 'names' method with keyAttributeName and valueAttributeName parameters.

Result:


toKeyValueArray() method

Convert all the values to a key-value format as an array (empty $method)

Result:

Convert all the values to a key-value format as an array with keyAttributeName and valueAttributeName parameters (empty $method)

Result:

Convert all the values to a key-value format as an array using 'emojis' method

Result:

Convert all the values to a key-value format as an array using 'emojis' method with keyAttributeName and valueAttributeName parameters (empty $method)

Result:

Convert all the values to a key-value format as an array using 'names' method

Result:

Convert all the values to a key-value format as an array using 'names' method with keyAttributeName and valueAttributeName parameters (empty $method)

Result:


randomValue() method

Get a random value from the collection of values (empty $method)

Get a random value from the collection of values using 'emojis' method

Get a random value from the collection of values using 'names' method


randomKey() method

Get a random case (key / name) from the collection of values

only() Method

Get values of only certain keys as a Collection (empty $method)

Result:

Get values of only certain keys as a Collection using 'emojis' method

Result:

Get values of only certain keys as a Collection using 'names' method

Result:


onlyAsArray() Method

Get values of only certain keys as an array (empty $method)

Result:

Get values of only certain keys as an array using 'emojis' method

Result:

Get values of only certain keys as an array using 'names' method

Result:


except() Method

Get all values except certain keys as a Collection (empty $method)

Result:

Get all values except certain keys a Collection using 'emojis' method

Result:

Get all values except certain keys a Collection using 'names' method

Result:


exceptAsArray() Method

Get all values except certain keys as an array (empty $method)

Result:

Get all values except certain keys an array using 'emojis' method

Result:

Get all values except certain keys an array using 'names' method

Result:


first() Method

Get the first value from the Enum (empty $method)

Get the first value from the Enum using 'emojis' method

Get the first value from the Enum using 'names' method


last() Method

Get the last value from the Enum (empty $method)

Get the last value from the Enum using 'emojis' method

Get the last value from the Enum using 'names' method


fromValue() Method

Create an Enum object from a string value.

If the value "Green" exists in the Color Enum, this method will return the corresponding Enum object. If not, it will throw an InvalidArgumentException.

valueNamePairs() Method

Get the key-value pairs of value and transformed value (if a method is specified).


is() Method

Checks if the Enum value is equal to the given value.

isNot() Method

Checks if the Enum value is not equal to the given value.

isAny() Method

Checks if the Enum value is equal to any of the given values.

isNotAny() Method

Checks if the Enum value is not equal to any of the given values.

Tests


All versions of enum-concern with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
illuminate/collections Version ^8.65 || ^9.0 || ^10.0 || ^11.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package emreyarligan/enum-concern contains the following files

Loading the files please wait ....