Download the PHP package eclipxe/enum without Composer

On this page you can find all versions of the php package eclipxe/enum. 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

eclipxe/enum

Source Code Packagist PHP Version Support Latest Version Software License Build Status Scrutinizer Coverage Status Total Downloads

Enum based on the Brent Roose enum idea https://stitcher.io/blog/php-enums

After reading the article PHP Enums from Brent Roose and review the implementation made on spatie/enum I think that it overloaded my expectations. Maybe spatie/enum version 1.0 was more close to what I needed.

So, I created this framework-agnostic implementation library about the same concept.

As of PHP 8.1 enums are part of the language, it means that this library will not be required anymore. Read the PHP documentation https://www.php.net/manual/en/language.enumerations.php and adapt your code. One big difference between PHP enums and the objects on this library is that native PHP enums cannot use the magic method __toString (they are not Stringable), and the enums on this library are.

Installation

Use composer, install using:

Usage

Enum in other languages are TEXT for code, INTEGER for values.

There are two meaningful information: index (integer) and value (string).

This library provides Eclipxe\Enum abstract class to be extended. The value is the method's name as declared in docblock. The index is the position (starting at zero) in the docblock.

Values are registered one by one taking the overridden value, or the method's name.

Indices are registered one by one taking the overridden index, or the maximum registered value plus 1.

Enum example

Creation of instances

You can create new instances from values using construct with value, construct with index or static method name.

List all the options

The only static method exposed on the Enum is Enum::toArray(): array that export the list of registered possible values as an array of indices and values.

Check if instance is of certain type

Use the methods is<name>() to compare to specific value.

You have to define these methods in your docblock to let your IDE or code analyzer detect what you are doing.

Or use weak comparison (equality, not identity):

Overriding values or indices

You can override values or indices by overriding the methods overrideValues() or overrideIndices().

Rules:

This will define these array<index, value>, retrieved using static method WeekDays::toArray():

Remember that Enum creation depends on registered values and indices, if and invalid value or index is used then an exception is thrown:

Extending

When creating an Enum extending from other, the parent Enum have priority on indices and values. You cannot override indices or values of previous classes.

I recommend you to declare your Enum classes as final to disable extension.

If using class extension, do not use @method static self name() syntax, use @method static static name() syntax instead to help analysis tools.

See examples at tests/Fixtures/ColorsBasic.php, tests/Fixtures/ColorsExtended.php and tests/Fixtures/ColorsExtendedWithBlackAndWhite.php.

Exceptions

Exceptions thrown from this package implements the empty interface Eclipxe\Enum\Exceptions\EnumExceptionInterface.

PHP Support

This library is compatible with at least the oldest PHP Supported Version with active support. Please, try to use PHP full potential.

We adhere to Semantic Versioning. We will not introduce any compatibility backwards change on major versions.

Internal classes (using @internal annotation) are not part of this agreement as they must only exist inside this project. Do not use them in your project.

Contributing

Contributions are welcome! Please read CONTRIBUTING for details and don't forget to take a look the TODO and CHANGELOG files.

Copyright and License

The eclipxe/enum library is copyright © Carlos C Soto and licensed for use under the MIT License (MIT). Please see LICENSE for more information.


All versions of enum with dependencies

PHP Build Version
Package Version
Requires php Version >=7.2
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 eclipxe/enum contains the following files

Loading the files please wait ....