Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on May 18, 2024 via composer

dasprid/enum 1.0.5

PHP 7.1 enum implementation
Package summary
Share
0
issues
1
license
1
BSD-2-Clause
Package created
25 Oct 2017
Version published
25 Aug 2023
Maintainers
1
Total deps
1
Direct deps
0
License
BSD-2-Clause

Issues

0
This package has no issues

Licenses

BSD 2-Clause "Simplified" License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
place-warranty
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
dasprid/enum@1.0.5
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of dasprid/enum 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does dasprid/enum do?

The dasprid/enum is a PHP 7.1 package that provides an efficient implementation of enumerations. PHP, by nature, does not have a robust built-in enum support. Although it does offer SplEnum implementation as a part of the PECL extension, it is not complete and necessitates the use of userland implementations. The dasprid/enum package bridges this gap by providing a sound and reliable enum implementation, operating with constants and allowing for more manageable code.

How do you use dasprid/enum?

To use the dasprid/enum package, you first need to include it in your project using composer. From there, you can create enums by subclassing the DASPRiD\Enum\AbstractEnum class and defining the constants with the protected scope. It's best to illustrate this with an example code:

use DASPRiD\Enum\AbstractEnum;

/**
 * @method static self MONDAY()
 * @method static self TUESDAY()
 * @method static self WEDNESDAY()
 * @method static self THURSDAY()
 * @method static self FRIDAY()
 * @method static self SATURDAY()
 * @method static self SUNDAY()
 */
final class WeekDay extends AbstractEnum
{
    protected const MONDAY = null;
    protected const TUESDAY = null;
    protected const WEDNESDAY = null;
    protected const THURSDAY = null;
    protected const FRIDAY = null;
    protected const SATURDAY = null;
    protected const SUNDAY = null;
}

In this example, a WeekDay enum is defined with constants for each day of the week. To use these enums, simply call them like functions. They are singletons, which guarantees there is always only one instance of the same type:

function tellItLikeItIs(WeekDay $weekDay)
{
    switch ($weekDay) {
        case WeekDay::MONDAY():
            echo 'Mondays are bad.';
            break;

        case WeekDay::FRIDAY():
            echo 'Fridays are better.';
            break;

        case WeekDay::SATURDAY():
        case WeekDay::SUNDAY():
            echo 'Weekends are best.';
            break;

        default:
            echo 'Midweek days are so-so.';
    }
}

tellItLikeItIs(WeekDay::MONDAY());
tellItLikeItIs(WeekDay::WEDNESDAY());
  • More complex enums can also be created using construction parameters and additional methods, as demonstrated in the readme file found on GitHub.

Where are the dasprid/enum docs?

As for the documentation, it can be found in the readme file located within the dasprid/enum repository on GitHub. The readme delivers a thorough introduction to this package, along with its description, usage examples, and detailed code snippets that showcase the package's functionalities and how to implement them effectively. Simply visit the repository's URL to access this information: https://github.com/DASPRiD/Enum.git.