PHPackages                             doctrineum/scalar - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. doctrineum/scalar

ActiveLibrary[Database &amp; ORM](/categories/database)

doctrineum/scalar
=================

Enumeration types and value dependent sub-types for Doctrine

4.0.0(7y ago)07.3k5MITPHPPHP &gt;=7.1

Since Mar 25Pushed 7y ago1 watchersCompare

[ Source](https://github.com/doctrineum/doctrineum-scalar)[ Packagist](https://packagist.org/packages/doctrineum/scalar)[ RSS](/packages/doctrineum-scalar/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (24)Used By (5)

[![Build Status](https://camo.githubusercontent.com/01e1f498be3030985868265ee36c4d73d0746ce30720747e549c2b9c75e729b1/68747470733a2f2f7472617669732d63692e6f72672f6a61726f736c61767479632f646f637472696e65756d2d7363616c61722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jaroslavtyc/doctrineum-scalar)[![Test Coverage](https://camo.githubusercontent.com/8152e53d8b40cf6c1c4761d4ebf422f41d65fcef3ac32539f160c896ca8e6fb2/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6a61726f736c61767479632f646f637472696e65756d2d7363616c61722f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/jaroslavtyc/doctrineum-scalar/coverage)[![Latest Stable Version](https://camo.githubusercontent.com/8fc5cce263a7e16af83d4ceb28eff1260de423bb49abaf75a0722aef503d551e/68747470733a2f2f706f7365722e707567782e6f72672f646f637472696e65756d2f7363616c61722f762f737461626c652e737667)](https://packagist.org/packages/doctrineum/scalar)[![License](https://camo.githubusercontent.com/f28483e0f55d8a355328bc0df5b31fe368d60356f7d7e209be0a218e63867244/68747470733a2f2f706f7365722e707567782e6f72672f646f637472696e65756d2f7363616c61722f6c6963656e73652e737667)](http://en.wikipedia.org/wiki/MIT_License)

##### Customizable enumeration type for Doctrine 2.4+

[](#customizable-enumeration-type-for-doctrine-24)

About custom Doctrine types, see the [official documentation](http://doctrine-orm.readthedocs.org/en/latest/cookbook/custom-mapping-types.html). For default types see the [official documentation as well](http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html).

Usage
-----

[](#usage)

1. [Installation](#installation)
2. [Custom type registration](#custom-type-registration)
3. [Map property as an enum](#map-property-as-an-enum)
4. [Create enum](#create-enum)
5. [Register subtype enum](#register-subtype-enum)
6. [NULL is NULL, not Enum](#null-is-null-not-enum)
7. [Understand the basics](#understand-the-basics)
8. [Exceptions philosophy](#exceptions-philosophy)

### Installation

[](#installation)

```
composer.phar require doctrineum/scalar
```

or manually edit composer.json at your project and `"require":` block (extend existing)

```
    "require": {
        "doctrineum/scalar": "dev-master"
    }
```

### Custom type registration

[](#custom-type-registration)

By helper method

```
ScalarEnum::registerSelf(); // quick self-registration
```

Or manually using "magic" [class::class constant](http://php.net/manual/en/language.oop5.basic.php#language.oop5.basic.class.class)

```
use Doctrineum\Scalar\ScalarEnumType;
// ...
Type::addType(ScalarEnumType::getTypeName(), ScalarEnumType::class);
Type::addType(BarScalarEnumType::getTypeName(), BarScalarEnumType::class);
```

Or manually by old fashion way

```
