Download the PHP package doctrineum/scalar without Composer
On this page you can find all versions of the php package doctrineum/scalar. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download doctrineum/scalar
More information about doctrineum/scalar
Files in doctrineum/scalar
Package scalar
Short Description Enumeration types and value dependent sub-types for Doctrine
License MIT
Informations about the package scalar
Customizable enumeration type for Doctrine 2.4+
About custom Doctrine types, see the official documentation. For default types see the official documentation as well.
Usage
- Installation
- Custom type registration
- Map property as an enum
- Create enum
- Register subtype enum
- NULL is NULL, not Enum
- Understand the basics
- Exceptions philosophy
Installation
or manually edit composer.json at your project and "require":
block (extend existing)
Custom type registration
By helper method
Or manually using "magic" class::class constant
Or manually by old fashion way
Or if your project uses Symfony2
Map property as an enum
Create enum
Register subtype enum
You can register infinite number of enums, which are built according to a regexp of your choice.
NULL is NULL, Enum can not hold it
You can not create ScalarEnum with NULL value. Just use NULL directly for such column value.
Beware on using subtypes only when main enum is an abstract class. You have to resolve from-database-NULL->to-PHP-value conversion, or register subtype explicitly for NULL value (empty string respectively), otherwise fatal error by abstract class instance creation occurs.
Understand the basics
There are two roles - the factory and the value.
- ScalarEnumType is the factory (as part of the Doctrine\DBAL\Types\Type family), building an ScalarEnum by following ScalarEnumType rules.
- ScalarEnum is the value holder, de facto singleton, represented by a class. And class, as you know, can do a lot of things, which makes enum more sexy then whole scalar value.
- Subtype is an ScalarEnumType, but ruled not just by type, but also by current value itself. One type can has any number of subtypes, in dependence on your imagination and used enum values.
Exceptions philosophy
Doctrineum adopts Granam exception hierarchy ideas. That means every exceptionable state is probably by a logic mistake, rather than a runtime situation.
All versions of scalar with dependencies
doctrine/dbal Version ~2.4
doctrineum/self-registering-type Version ~2.1
granam/scalar-enum Version ~1.0
granam/tools Version ^3.0