davidkmenta / doctrine-simple-array-types
Extended simple array types for Doctrine
Installs: 115 350
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 1
Requires
- php: >=7.1
- doctrine/orm: ^2.4
Requires (Dev)
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2025-01-19 10:55:14 UTC
README
A Doctrine field type for simple arrays of integers, floats and strings.
Description
These types mainly solve two common problems:
- simple_string_array solves the problem with strings containing a comma symbol. Such strings cannot be persisted in the simple_array type provided by the Doctrine.
- simple_integer_array and simple_float_array extends the simple_array type from the Doctrine. These types solve the problem when a persisted integer or float is returned from the database as a string.
Installation
Run the following command:
composer require davidkmenta/doctrine-simple-array-types
Examples
To configure Doctrine to use this set of types, you'll need to set up the following in your bootstrap:
<?php \Doctrine\DBAL\Types\Type::addType('simple_string_array', 'DavidKmenta\DoctrineSimpleArrayTypes\SimpleStringArrayType'); $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('simple_string_array', 'simple_string_array'); \Doctrine\DBAL\Types\Type::addType('simple_integer_array', 'DavidKmenta\DoctrineSimpleArrayTypes\SimpleIntegerArrayType'); $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('simple_integer_array', 'simple_integer_array'); \Doctrine\DBAL\Types\Type::addType('simple_float_array', 'DavidKmenta\DoctrineSimpleArrayTypes\SimpleFloatArrayType'); $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('simple_float_array', 'simple_float_array');
Or, if you're using the Symfony, set types in your Doctrine configuration file (eg: doctrine.yml):
doctrine: dbal: types: simple_string_array: 'DavidKmenta\DoctrineSimpleArrayTypes\SimpleStringArrayType' simple_integer_array: 'DavidKmenta\DoctrineSimpleArrayTypes\SimpleIntegerArrayType' simple_float_array: 'DavidKmenta\DoctrineSimpleArrayTypes\SimpleFloatArrayType'
Then, in your entities, you may annotate properties by setting the @Column
type to simple_string_array
, simple_integer_array
or simple_float_array
.