Download the PHP package datomatic/laravel-enum-helper without Composer

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

Laravel Enum Helper

Latest Version on Packagist Pest Tests number GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This is an extension of the datomatic/enum-helper package based on Laravel Framework. The package consists on a LaravelEnumHelper trait that extends EnumInvokable, EnumFroms, EnumNames, EnumValues, EnumEquality, EnumDescription and add dynamic methods to return a translation or "property" method and relative helper methods.

You can think about it as an EnumDescription trait but completely dynamic.

So you can define a custom method() and have these functions available: [method]s(), [method]sByName(), [method]sByValue(). For example with color() you obtain colors(), colorsByName(), colorsByValue() methods.

The cool thing is you can also avoid writing the method and write only the translations. For example, you can define the property excerpt by writing only the translations on enums.php (see below for explanation) and obtain excerpt(), excerpts(), excerptsByName(), excerptsByValue() methods.

The package use the Laravel Pluralizer component to get the singular method to call or to translate.

Related Packages

The enum-helper base package summary

You should see the datomatic/enum-helper details on his repository, this is a summary:

Installation

Laravel 8 or above and PHP 8.1+ are required.

Usage

You can use this functionality simply using the LaravelEnumHelper trait.

After that you can define a custom "property" method like color() or color(?string $lang = null) or define the translations instead.

Annotation command

A convenient command is available to generate DocBlock annotations for enum classes.

This command generate the phpDoc annotations for invokable case methods.

Translations

Using this trait there is 2 way to manage translation strings.

Using Short Keys

Language strings may be stored in enums.php files within the lang directory. Within this directory, there may be subdirectories for each language supported by the application.

All language files return an array of keyed strings. The array has 3 levels:

The default property is description so if you use only that property you can use just a 2 level array.

Using Translation Strings As Keys

Language strings are stored as JSON files in the lang directory (e.g. lang/it.json). In this example the description property is translated:

But if you want to use this way, you can simply define the method on Enum class like this description method.

[property]() method

This dynamic method try to resolve property() method on the enum.
If the method not exist try to translate the instance value with the framework translation function __("enums.Namespace\EnumClass.property.CASE_NAME").
Because the default property is description, if there isn't a translation to that property there is a fallback that takes the case name humanized. With the other properties, if the translation does not exist, the package throws a TranslationMissing exception.

static [property]s() method

This dynamic method gets a list of case property() returns of the enum. The name of the method is the plural of the property so if you are using property it will be properties().

static [property]sByName() method

This dynamic method returns an associative array of [case name => property() result]. The name of the method is the plural of the property so if you are using property it will be propertiesByName().

static [property]sByValue() method

This dynamic method returns an associative array of [case value => property() result] on BackedEnum, [case name => property() result] otherwise. The name of the method is the plural of the property so if you are using property it will be propertiesByValue().


All versions of laravel-enum-helper with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
composer/class-map-generator Version ^1.0
datomatic/enum-helper Version ^2.0
illuminate/translation Version ^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
laminas/laminas-code Version ^4.0
jawira/case-converter Version ^3.5
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 datomatic/laravel-enum-helper contains the following files

Loading the files please wait ....