Skip to content

Use DBAL Type for Field type#727

Merged
mvorisek merged 22 commits intodevelopfrom
dbal_field_type
Sep 30, 2021
Merged

Use DBAL Type for Field type#727
mvorisek merged 22 commits intodevelopfrom
dbal_field_type

Conversation

@mvorisek
Copy link
Copy Markdown
Member

@mvorisek mvorisek commented Sep 16, 2020

If a custom typecasting is needed, easy, simply register own type in DBAL. If a library wants to provide some custom types by default, bootstrap (register on load time) using composer.

I think this is step in a good direction, as we can then leave all typecasting to standard DBAL Types and remove all hacky typing from the code. DBAL Types can also be easily replaced and/or a new/custom Type can be easily added.

  • yes, this will solve all typecasting across different Persistences
  • this PR is strictly focused on typecasting a managed value (php value) to an unmanaged value (string, scalar in general)
  • this PR is BC as much as possible, ie. it keep working without explicit Persistence nor Platform

BC breaks:

  • removed Field::serialize property, to use PHP serialization, use object type.
  • removed Field::typecast property, to use a custom typecasting, extend the target DBAL type class and register it or implement a custom persistence
  • removed Field::dateTimeClass/dateTimeZoneClass properties, see bullet point above
  • removed Field::persist_format/persist_timezone properties, see above, but you probably want to handle it using persistence/UI solely - if there was a shared format/TZ, different format/TZ was not possible to set for the database and UI
  • removed Model::strict_types property, was already enabled by default, normalization can still be disabled/broken by Model::HOOK_NORMALIZE hook
  • array type is temporary forbidden to be used, object type now serializes data using PHP serialization, to use JSON, use json type. For more details, see the following table:
Serialization purpose Original Atk4 3.0 (or lower) type New/DBAL type equivalent Notes
Encode array as JSON array json array type now behaves differently, thus temporary forbidden to be used in atk4/data
Encode object as JSON object json https://github.com/doctrine/dbal/blob/3.1.2/src/Types/JsonType.php
Serialize php data Field::serialize flag was needed object https://github.com/doctrine/dbal/blob/3.1.2/src/Types/ObjectType.php
Serialize php data Field::serialize flag was needed array forbidden, see the first table row and use object type instead

@mvorisek mvorisek changed the base branch from develop to dbal_platform October 12, 2020 18:18
@mvorisek mvorisek force-pushed the dbal_platform branch 2 times, most recently from e7d603c to a4b0d85 Compare October 12, 2020 19:11
@mvorisek mvorisek force-pushed the dbal_field_type branch 3 times, most recently from 7fcf3bc to 181d4ec Compare October 12, 2020 19:28
@mvorisek mvorisek force-pushed the dbal_field_type branch 16 times, most recently from 5e853c9 to 5ee9f91 Compare September 30, 2021 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants