You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,14 +7,15 @@ Why another PHP ORM? In writing minimal and fast websites, it was determined tha
7
7
8
8
## Features
9
9
-**Active Records** A fully type checked object interface and implement basic CRUD functionality.
10
-
-**Active Tables** Full table operations including support for where, having, limits, ordering, grouping, joins and unions.
10
+
-**Active Tables** Full table operations (select, update, insert and delete) including support for where, having, limits, ordering, grouping, joins and unions.
11
11
-**Data Cursors** Cursors implement **iterable** and **Countable** eliminating the need for full arrays read into memory.
12
12
-**Validation** Fully customizable and translatable backend validation.
13
-
-**Virtual Fields** Supports get and set semantics for any custom or calculated field.
13
+
-**Virtual Fields** Supports get and set semantics for any custom or calculated field such as Carbon dates.
14
14
-**Migrations** Simple migrations offer atomic up and down migrations.
15
15
-**Relations** Parent, children, one to one, many to many, and custom relationships.
16
16
-**Transactions** Object based transaction meaning exceptions can not leave an open transacton.
17
-
-**Type Safe** Prevent stupid type errors.
17
+
-**Type Safe** Prevents stupid type errors.
18
+
-**Injection Safe** Uses PDO placeholders and field sanitation to prevent injection attacks.
18
19
-**Raw SQL Query Support** Execute any valid SQL command.
19
20
-**Multiple Database Support** Work with multiple databases simultaneously.
20
21
-**Multi-Vendor Support** Built on PDO with support for MySQL, MariaDB and SQLite.
@@ -115,7 +116,7 @@ Exceptions are generated in the following conditions:
115
116
All of the above exceptions are programmer errors and strictly enforced. Empty queries are not considered errors. SQL may also return [Exceptions](https://www.php.net/manual/en/class.exception.php) if invalid fields are used.
116
117
117
118
### Type Conversions
118
-
If you set a field to the wrong type, the library logs an warning then converts the type via the appropriate PHP cast.
119
+
If you set a field to the wrong type, the library logs a warning then converts the type via the appropriate PHP cast.
119
120
120
121
## Multiple Database Support
121
122
While this is primarily a single database ORM, you can switch databases at run time. Save the value from `$connectionId = \PHPFUI\ORM::addConnection($pdo);` and then call `\PHPFUI\ORM::useConnection($db);` to switch. `\PHPFUI\ORM::addConnection` will set the current connection.
Copy file name to clipboardExpand all lines: docs/5. Virtual Fields.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ You can define virtual fields with get and set semantics for any **\App\Record**
5
5
6
6
Every **\App\Record** class has a static $virtualFields array defined. The key of the array is the name of the virtual key. The value for each virtual field is an array of strings. The first string is the virtual field class name. Subsequent parameters are are passed the the **getValue** and **setValue** methods.
7
7
8
+
Note that virtual fields are created each time they are accessed and not stored or cached in the \PHPFUI\ORM\Record object. This means you can not change the virtual field on the Record object itself. You can only assign it to the Record object, which will store the value represented by the virtual field in the object, but not the virtual field itself.
9
+
8
10
The **VirtualField** class has two properties that will always be defined for use by the derived class:
9
11
* $currentRecord is the current record that the virtual field should be based on.
10
12
* $fieldName the field name that the VirtualField object was created from. This is the key of the $virtualFields array in the Record class.
@@ -125,3 +127,20 @@ foreach ($suppliers as $supplier)
125
127
echo $supplier->company . "\n";
126
128
}
127
129
```
130
+
131
+
## Cast Virtual Field
132
+
Often you want to use PHP class instead of a native scalar type (string, int, float, bool) to make your life easier. The Carbon class is an excellent example of a widely used package. It would be nice to get and set Carbon objects instead of strings formatted to the MySQL date format.
133
+
134
+
Use \PHPFUI\ORM\Cast virtual field to accommplish this. The Cast virtual field works with a wide variety of packages, as its only requirements are to implement **__toString** and a construct from a value.
135
+
### Usage
136
+
```php
137
+
class Invoice extends \Tests\App\Record\Definition\Order
0 commit comments