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

Fix field typecast and drop Boolean field class #897

Merged
merged 15 commits into from
Oct 4, 2021
Merged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Agile Data has a usage patters that will automatically restrict access by this c

With Agile Data you can move your data from one persistence to another seamlessly. If you rely on some feature that your new persistence does not support (e.g. Expression) you can replace them a callback calculation, that executes on your App server.

As usual - the rest of your application is not affected and you can even use multiple types of different persistences and still navigate through references.
As usual - the rest of your application is not affected and you can even use multiple types of different persistencies and still navigate through references.

#### Support

Expand Down
2 changes: 1 addition & 1 deletion bootstrap-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
return (string) round((float) $value, 4);
}

public function convertToPHPValue($value, AbstractPlatform $platform): float
public function convertToPHPValue($value, AbstractPlatform $platform): ?float
{
$v = $this->convertToDatabaseValue($value, $platform);

Expand Down
1 change: 0 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
ignore:
- docs
- locale
comment: false
coverage:
status:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@
}
],
"require": {
"php": ">=7.4.0",
"php": ">=7.4 <8.2",
"ext-intl": "*",
"ext-pdo": "*",
"atk4/core": "dev-develop",
"doctrine/dbal": "^2.13.3 || ^3.0",
"mvorisek/atk4-hintable": "~1.5.0"
},
"require-release": {
"php": ">=7.4.0",
"php": ">=7.4 <8.2",
"ext-intl": "*",
"ext-pdo": "*",
"atk4/core": "~3.1.0",
Expand Down
4 changes: 2 additions & 2 deletions docs/design.rst
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ So getting back to the operation above, lets look at it in more details::

While "vip_orders" is actually a DataSet, executing count() will cross you over
into persistence layer. However this method is returning a new object, which is then
executed when you call getOne(). For SQL persistences it returns \Atk4\Data\Persistence\Sql\Query
executed when you call getOne(). For SQL persistencies it returns \Atk4\Data\Persistence\Sql\Query
object, for example.

Even though for a brief moment you had your hands on a "database-vendor specific"
Expand All @@ -534,7 +534,7 @@ will not violate SRP (Single Responsibility Principle)

Unique Features of Persistence Layer
------------------------------------
More often than not, your application is designed and built with a specific
More often thannot, your application is designed and built with a specific
persistence layer in mind. If you are using SQL database, you want to


Expand Down
8 changes: 0 additions & 8 deletions docs/field_boolean.rst

This file was deleted.

9 changes: 1 addition & 8 deletions docs/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,9 @@ Second argument to addField() will contain a seed for the Field class::

$this->addField('surname', ['default' => 'Smith']);

Additionally, `type` property can be used to determine the best `Field` class to handle
the type::

$field = $this->addField('is_married', ['type' => 'boolean']);

// $field class now will be Field\Boolean

You may also specify your own Field implementation::

$field = $this->addField('amount_and_currency', new MyAmountCurrencyField());
$field = $this->addField('amount_and_currency', [MyAmountCurrencyField::class]);

Read more about :php:class:`Field`

Expand Down
8 changes: 4 additions & 4 deletions docs/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ basic functionality is divided into 3 major areas:

- Fields (or Columns)
- DataSets (or Rows)
- Databases (or Persistences)
- Databases (or Persistencies)

Each of the above corresponds to a PHP class, which may use composition principle
to hide implementation details.
Expand Down Expand Up @@ -171,7 +171,7 @@ MongoDB), you would need to define the field differently::
});

When you use persistence-specific code, you must be aware that it will not map
into persistences that does not support features you have used.
into persistencies that does not support features you have used.

In most cases that is OK as if you prefer to stay with same database type, for
instance, the above expression will still be usable with any SQL vendor, but if
Expand Down Expand Up @@ -217,7 +217,7 @@ Persistence Scaling
===================

Although in most cases you would be executing operation against SQL persistence,
Agile Data makes it very easy to use models with a simpler persistences.
Agile Data makes it very easy to use models with a simpler persistencies.

For example, consider you want to output a "table" to the user using HTML by
using Agile UI::
Expand All @@ -229,7 +229,7 @@ using Agile UI::

echo $htmltable->render();

Class `\\Atk4\\Ui\\Table` here is designed to work with persistences and models -
Class `\\Atk4\\Ui\\Table` here is designed to work with persistencies and models -
it will populate columns of correct type, fetch data, calculate totals if needed.
But what if you have your data inside an array?
You can use :php:class:`Persistence\Static_` for that::
Expand Down
88 changes: 44 additions & 44 deletions docs/persistence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,48 +297,48 @@ Type Matrix

.. todo:: this section might need cleanup

+----+----+----------------------------------------------------------+------+----+-----+
| ty | al | description | nati | sq | mon |
| pe | ia | | ve | l | go |
| | s( | | | | |
| | es | | | | |
| | ) | | | | |
+====+====+==========================================================+======+====+=====+
| st | | Will be trim() ed. | | | |
| ri | | | | | |
| ng | | | | | |
+----+----+----------------------------------------------------------+------+----+-----+
| in | in | will cast to int make sure it's not passed as a string. | -394 | 49 | 49 |
| t | te | | , | | |
| | ge | | "49" | | |
| | r | | | | |
+----+----+----------------------------------------------------------+------+----+-----+
| fl | | decimal number with floating point | 3.28 | | |
| oa | | | 84, | | |
| t | | | | | |
+----+----+----------------------------------------------------------+------+----+-----+
| mo | | Will convert loosly-specified currency into float or | "£3, | 38 | |
| ne | | dedicated format for storage. Optionally support 'fmt' | 294. | 29 | |
| y | | property. | 48", | 4. | |
| | | | 3.99 | 48 | |
| | | | 999 | , | |
| | | | | 4 | |
+----+----+----------------------------------------------------------+------+----+-----+
| bo | bo | true / false type value. Optionally specify | true | 1 | tru |
| ol | ol | 'enum' => ['N','Y'] to store true as 'Y' and false as 'N'. | | | e |
| | ea | By default uses [0,1]. | | | |
| | n | | | | |
+----+----+----------------------------------------------------------+------+----+-----+
| ar | | Optionally pass 'fmt' option, which is 'json' by | [2 => | {2 | sto |
| ra | | default. Will json\_encode and json\_decode(..., true) | "bar | :" | red |
| y | | the value if database does not support array storage. | "] | ba | as- |
| | | | | r" | is |
| | | | | } | |
+----+----+----------------------------------------------------------+------+----+-----+
| bi | | Supports storage of binary data like BLOBs | | | |
| na | | | | | |
| ry | | | | | |
+----+----+----------------------------------------------------------+------+----+-----+
+----+----------------------------------------------------------+------+----+-----+
| ty | description | nati | sq | mon |
| pe | | ve | l | go |
| | | | | |
| | | | | |
| | | | | |
+====+==========================================================+======+====+=====+
| st | Will be trim() ed. | | | |
| ri | | | | |
| ng | | | | |
+----+----------------------------------------------------------+------+----+-----+
| in | will cast to int make sure it's not passed as a string. | -394 | 49 | 49 |
| te | | , | | |
| ge | | "49" | | |
| r | | | | |
+----+----------------------------------------------------------+------+----+-----+
| fl | decimal number with floating point | 3.28 | | |
| oa | | 84, | | |
| t | | | | |
+----+----------------------------------------------------------+------+----+-----+
| at | Will convert loosly-specified currency into float or | "£3, | 38 | |
| k4 | dedicated format for storage. Optionally support 'fmt' | 294. | 29 | |
| _m | property. | 48", | 4. | |
| on | | 3.99 | 48 | |
| y | | 999 | , | |
| | | | 4 | |
+----+----------------------------------------------------------+------+----+-----+
| bo | true / false type value. | true | 1 | tru |
| ol | | | | e |
| ea | | | | |
| n | | | | |
+----+----------------------------------------------------------+------+----+-----+
| js | Optionally pass 'fmt' option, which is 'json' by | [2 => | {2 | sto |
| on | default. Will json_encode and json_decode(..., true) | "bar | :" | red |
| | the value if database does not support array storage. | "] | ba | as- |
| | | | r" | is |
| | | | } | |
+----+----------------------------------------------------------+------+----+-----+
| bi | Supports storage of binary data like BLOBs | | | |
| na | | | | |
| ry | | | | |
+----+----------------------------------------------------------+------+----+-----+

- Money: http://php.net/manual/en/numberformatter.parsecurrency.php.
- money: See also
Expand Down Expand Up @@ -544,7 +544,7 @@ The other, more appropriate option is to re-use a vanilla Order record::
}


Working with Multiple Persistences
Working with Multiple Persistencies
==================================

Normally when you load the model and save it later, it ends up in the same
Expand Down Expand Up @@ -573,7 +573,7 @@ Agile Data, so you will have to create logic yourself, which is actually quite
simple.

You can use several designs. I will create a method inside my application class
to load records from two persistences that are stored inside properties of my
to load records from two persistencies that are stored inside properties of my
application::

function loadQuick($class, $id) {
Expand Down
2 changes: 1 addition & 1 deletion docs/references.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ model that has a persistence set. (See Reference::getModel())
Persistence
-----------

Agile Data supports traversal between persistences. The code above does not
Agile Data supports traversal between persistencies. The code above does not
explicitly assign database to Model_Order. But what if destination model does
not reside inside the same database?

Expand Down
4 changes: 2 additions & 2 deletions docs/sql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ procedures you will loose portability of your application.

We do have our legacy applications to maintain, so Stored Procedures and SQL
extensions are here to stay. By making your Model rely on those extensions you
will loose ability to use the same model with non-sql persistences.
will loose ability to use the same model with non-sql persistencies.

Sometimes you can fence the code like this::

Expand All @@ -338,7 +338,7 @@ Sometimes you can fence the code like this::
}

Or define your pure model, then extend it to add SQL capabilities. Note that
using single model with cross-persistences should still be possible, so you
using single model with cross-persistencies should still be possible, so you
should be able to retrieve model data from stored procedure then cache it.

as a Model method
Expand Down
2 changes: 1 addition & 1 deletion docs/typecasting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Field may use serialization to further encode field value for the storage purpos
Array and Object types
----------------------

Some types may require serialization for some persistences, for instance types
Some types may require serialization for some persistencies, for instance types
'json' and 'object' cannot be stored in SQL natively. `json` type can be used
to store these in JSON.

Expand Down
16 changes: 1 addition & 15 deletions docs/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Supported Types
ATK Data prior to 1.5 supports the following types:

- string
- boolean ([':php:class:`Boolean`'])
- boolean
- integer ([':php:class:`Number`', 'precision' => 0])
- money ([':php:class:`Number`', 'prefix' => '€', 'precision' => 2])
- float ([':php:class:`Number`', 'type' => 'float'])
Expand Down Expand Up @@ -118,17 +118,3 @@ All measurements are implemented with :php:class:`Units` and can be further exte
echo $model->getField('speed')->format(); // 30km/s
echo $model->getField('speed')->format('m'); // 30000m/s


List of Field Classes
=====================

.. toctree::
:maxdepth: 1

field_boolean
field_text
field_number
field_datetime
field_units


23 changes: 0 additions & 23 deletions locale/en/atk.php

This file was deleted.

22 changes: 0 additions & 22 deletions locale/it/atk.php

This file was deleted.

21 changes: 0 additions & 21 deletions locale/ru/atk.php

This file was deleted.

Loading