Download the PHP package tezmanian/utils-enum without Composer

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

tez-utils-enum

CI Packagist Version PHP

Composable PHP 8.3 traits that extend native enums with lookup, comparison, navigation, bitmask, label, and collection helpers.

Zero dependencies · PHPStan level 9 · MIT

Installation

Package: tezmanian/utils-enum · Namespace: Tezmanian\Utils\Enum

Requires PHP ≥ 8.3.

Traits

Trait Enum type Purpose
EnumTrait Unit Base helpers: lookup, filtering, ordering
BackedEnumTrait Backed Extends EnumTrait with value-based helpers
BitFlagTrait Int-backed Bitmask operations
ComparableTrait Int-backed Comparison and range checks
StepTrait Any Navigate to adjacent cases
TranslatableTrait Any Human-readable labels
EnumCollectionTrait Any Collection-style selection

EnumTrait

Base trait for pure (unit) enums. Use BackedEnumTrait instead when your enum has backing values.

Methods

Method Description
is($value) True if the case matches by identity or name. Null always returns false.
isOneOf(?array $values) True if the case matches any value in the list.
isNoneOf(?array $values) Inverse of isOneOf().
find($value, $ignoreCase) Returns a matching case or null. Matches by identity or name.
filter(callable $cb) Returns all cases for which the callback returns true.
toArray() Returns [name => name] for all cases.
ordinal() Zero-based position of this case in the enum definition.
first() Returns the first defined case.
last() Returns the last defined case.

BackedEnumTrait

Extends EnumTrait for string- or int-backed enums. Overrides is() to match by backing value, and toArray() to return [value => name].

toArray() vs toValueArray() — toArray() returns [value => name], useful for form selects. toValueArray() returns [name => value], useful for serialization. The directions are opposite.

Additional methods

Method Description
values() All backing values as a list.
hasValue($value) True if any case has this backing value.
fromName(string $name) Returns a case by name, or throws ValueError.
tryFromName(string $name) Returns a case by name, or null.
toValueArray() Returns [name => value] for all cases.

BitFlagTrait

Bitmask helpers for int-backed enums used as flag sets. Case values must be powers of 2 (1, 2, 4, 8, …). This constraint is not enforced at runtime.

Does not include BackedEnumTrait — combine them explicitly if needed.

Methods

Method Description
combine(self ...$cases) OR-combines case values into a bitmask. Returns 0 with no arguments.
fromBitmask(int $mask) Returns all cases whose bit is set in the mask. Skips cases with value 0.
isSetIn(int $mask) True if this case's bit is set in the mask.
addTo(int $mask) Returns the mask with this case's bit set.
removeFrom(int $mask) Returns the mask with this case's bit cleared.

ComparableTrait

Comparison helpers for int-backed enums, comparing cases by their backing values.

Methods

Method Description
isGreaterThan(self $other) True if this case's value is strictly greater.
isGreaterThanOrEqual(self $other) True if this case's value is greater or equal.
isLessThan(self $other) True if this case's value is strictly less.
isLessThanOrEqual(self $other) True if this case's value is less or equal.
between($min, $max) True if within the inclusive range [$min, $max].
clamp($min, $max) Returns this case, or $min/$max if out of range.

StepTrait

Navigate to adjacent cases by definition order. Designed for state machines and ordered workflows. Works with both unit and backed enums.

Order is determined by definition order (ordinal), not backing value. Returns null at boundaries — no wrap-around.

Methods

Method Description
next() Returns the next case by definition order, or null at the last case.
prev() Returns the previous case by definition order, or null at the first case.

TranslatableTrait

Human-readable labels for enum cases, without any framework dependency. Override labels() to supply custom mappings keyed by case name. Falls back to the case name when no label is defined.

Methods

Method Description
label() Human-readable label for this case. Falls back to $case->name.
labelsArray() All cases mapped to their labels as [caseName => label].
labels() (protected) Override in your enum to supply custom label mappings.

EnumCollectionTrait

Collection-style selection helpers. Can be combined with EnumTrait or BackedEnumTrait. Works with any enum type.

Both except() and only() preserve enum definition order.

Methods

Method Description
random() Returns a random case.
except(self ...$excluded) All cases except the given ones, in definition order.
only(self ...$included) Only the given cases, in definition order.

Combining traits

Traits are designed to be freely mixed. A few common combinations:

All traits use @phpstan-require-implements to enforce the correct enum type at static analysis time. Mixing BitFlagTrait or ComparableTrait with non-int-backed enums will surface as a PHPStan error.

Requirements

Development

License

MIT — see LICENSE.

Author: René Halberstadt


All versions of utils-enum with dependencies

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

Loading the files please wait ...