Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DBAL Type for Field type #727

Merged
merged 22 commits into from
Sep 30, 2021
Merged

Use DBAL Type for Field type #727

merged 22 commits into from
Sep 30, 2021

Conversation

mvorisek
Copy link
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 10 times, most recently from 6e9306c to 224ea0b Compare September 30, 2021 15:53
@mvorisek mvorisek added RTM and removed help wanted labels Sep 30, 2021
@mvorisek mvorisek merged commit 8d8cb49 into develop Sep 30, 2021
@mvorisek mvorisek deleted the dbal_field_type branch September 30, 2021 20:46
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