Download the PHP package demoniacdeath/enum-bundle without Composer

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

Enum Bundle

Provides a MyCLabs\Enum integration with Doctrine for your Symfony projects.

Installation

Step 1: Download the Bundle

$ composer require fervo/enum-bundle "^2.0"

Step 2: Enable the Bundle

<?php

// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Fervo\EnumBundle\FervoEnumBundle(),
        );

        // ...
    }

    // ...
}

Step 3: Configure your enum

fervo_enum:
    enums:
        AppBundle\Enum\Gender:
            doctrine_type: gender # Type name used in doctrine annotations
            form_type: gender # Used in translation keys

Step 4: Create your enum

<?php

namespace AppBundle\Enum\Gender;

use MyCLabs\Enum\Enum;

class Gender extends Enum
{
    const MALE = 'male';
    const FEMALE = 'female';
}

Step 5: Use the enum in a doctrine entity

<?php

namespace AppBundle\Entity;

use AppBundle\Enum\Gender;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity()
 */
class Person
{
    // ...

    /**
     * @ORM\Column(type="gender")
     */
    protected $gender;

    // ...

    public function getGender()
    {
        return $this->gender;
    }

    public function setGender(Gender $gender)
    {
        $this->gender = $gender;
    }

    // ...
}

Step 6: Use the enum in Symfony forms

The bundle auto-generates a corresponding form type for each configured enum. The FQCN for the form type is on the format FervoEnumBundle\Generated\Form\{{enum class name}}Type. So with the enum class in the example above, it could be used in a form type in the following way.

<?php

namespace AppBundle\Form\Type;

use FervoEnumBundle\Generated\Form\GenderType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class EmployeeType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            // ...
            ->add('gender', GenderType::class)
            // ...
        ;
    }
}

If the underlying object of the form type is a doctrine mapped entity, the type can also be guessed by the framework. But it is a good practice to always specify the FQCN in form types.

Or you can use EnumType with configured options:

<?php

namespace AppBundle\Form\Type;

use AppBundle\Enum\Gender;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;

class EmployeeType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            // ...
            ->add('gender', EnumType::class, [
                'class' => Gender::class,
                'choice_label_prefix' => 'gender', // optional
            ])
            // ...
        ;
    }
}

Step 7: Specify translations for the enum values

The form type looks by default for the translation of the enum values in the enums translation domain. The translation keys are on the format {{configured form_type name}}.{{enum constant value}}. So going with the example the translation keys would be gender.male and gender.female.

Additional functionality

Use the enum with Symfony @ParamConverter

<?php

namespace AppBundle\Controller;

use AppBundle\Enum\Gender;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class EmployeeController extends Controller
{
    /**
     * @ParamConverter("gender")
     */
    public function indexAction(Gender $gender)
    {
        // ...
    }
}

Use the enum with JMS\Serializer

<?php

namespace AppBundle\Entity;

use AppBundle\Enum\Gender;
use JMS\Serializer\Annotation as JMS;

class Person
{
    // ...

    /**
     * @JMS\Type("gender")
     */
    protected $gender;

    // ...

    public function getGender()
    {
        return $this->gender;
    }

    public function setGender(Gender $gender)
    {
        $this->gender = $gender;
    }

    // ...
}

Customize value casting

In case the values of your enumeration are not strings, you can use the two magic function castValueIn and castValueOut to support non-string values:


All versions of enum-bundle with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
symfony/form Version ^3.4|^4.0|^5.0
symfony/framework-bundle Version ^3.4|^4.0|^5.0
symfony/translation Version ^3.4|^4.0|^5.0
doctrine/doctrine-bundle Version ^1.2|^2.0
myclabs/php-enum Version ^1.3
doctrine/common Version ^2.4
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 demoniacdeath/enum-bundle contains the following files

Loading the files please wait ....