Skip to content

Commit db089d3

Browse files
committed
Update docs
1 parent df911d2 commit db089d3

File tree

10 files changed

+42
-39
lines changed

10 files changed

+42
-39
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# PHPFUI\ORM [![Tests](https://github.com/phpfui/ORM/actions/workflows/tests.yml/badge.svg)](https://github.com/phpfui/ORM/actions?query=workflow%3Atests) [![Latest Packagist release](https://img.shields.io/packagist/v/phpfui/ORM.svg)](https://packagist.org/packages/phpfui/ORM) ![](https://img.shields.io/badge/PHPStan-level%205-brightgreen.svg?style=flat)
22

33
### PHPFUI\ORM a minimal Object Relational Mapper (ORM) for MySQL, MariaDB and SQLite3
4-
Why another PHP ORM? In writing minimal and fast websites, it was determined that existing PHP ORM solutions were overly complex. **PHPFUI\ORM** is less than 6k lines of code in under 50 files. It is designed to have a minimal memory footprint and excellent execution times for most database needs.
4+
Why another PHP ORM? In writing minimal and fast websites, it was determined that existing PHP ORM solutions were overly complex. **PHPFUI\ORM** is a little more than 6K lines of code in under 50 files. It is designed to have a minimal memory footprint and excellent execution times for most database needs.
55

66
**PHPFUI\ORM** is not an attempt to write an abstraction around SQL as other ORMs do, rather it is a way to work with SQL that closely matches the semantics of SQL, with the power of PHP objects. It allows PHP to manipulate SQL queries without having to write SQL in plain text. This is very useful for queries generated via user interfaces where the user is given a lot of flexability in how a query is defined.
77

docs/1. Setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Deletion of unused models should be done manually when the table is removed from
2323
## PHP Class Naming Conventions
2424
All **PHPFUI\ORM** classes and namespaces use StudlyCase naming conventions. SQL table names are used the generate the PHP class names. Case is preserved except the first letter is the converted to upper case. Table names with underscores are converted to StudlyCase and underscores are removed. Field names are not affected and left unchanged.
2525

26-
Each table will generate 3 classes (4 if validators are generated) with the same class name, but in the specified namespaces (see below). **Definition** and **Validation** namespaces are children of the record namespace.
26+
Each table will generate 3 classes (4 if validators are generated) with the same class name, but in the specified namespaces (see below). **Definition** and **Validation** namespaces are children of the **Record** namespace.
2727

2828
## Configuration
2929
**PHPFUI\ORM** needs the following information to work with your code:

docs/10. Miscellaneous.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Returne the value from the first field in the first row returned by the querry,
3131
Returns the data values of the first element in each row of the query.
3232

3333
## **\PHPFUI\ORM\Record** Data Cleaning Helpers
34-
The Record class provides some simple data cleaning functions you can use where needed.
34+
The [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) class provides some simple data cleaning functions you can use where needed.
3535
* **cleanUpperCase**(string $field) Converts the field to all upper case
3636
* **cleanLowerCase**(string $field) Converts the field to all lower case
3737
* **cleanNumber**(string $field) removes all non-digits (0-9 and -) from string representation of a number

docs/2. Active Record.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ A **Record** constructor attempts to read the specified row from the table. It c
3131
- **array** record is attempted to be read from database using the values of the fields provided.
3232
- **null** (default) constructs an empty object.
3333

34-
Both int and string parameters to the constructor are type checked. Calling the constructor with a parameter can be see as the same as, but with type checking:
34+
Both int and string parameters to the constructor are type checked. Calling the constructor with a parameter can be see as the same as the following, but with type checking:
3535
```php
3636
$customer = new \App\Record\Customer();
3737
$customer->read($value);
@@ -41,7 +41,7 @@ $customer->read($value);
4141
- **insert**() or **create**()
4242
* Adds the current record to the database. If the primary key already exists in the database, the insert fails. The auto increment primary key is updated with the value inserted.
4343
* insert() returns the primary key value inserted, true if no primary key and the record was successfully inserted or false on error.
44-
- **insertOrUpdate**()
44+
- **insertOrUpdate**() or **save**()
4545
* Will try to insert the record and on a duplicate key, will update the record with the current values.
4646
* insertOrUpdate() returns the same values as insert().
4747
* If the record only consists of primary keys, then this method is equivalent to insertOrIgnore().
@@ -80,7 +80,7 @@ $customer->read($value);
8080
* Returns an array of errors indexed by field name. Empty array means the record has correctly validated.
8181

8282
## Related Records
83-
Related records are indicated by field name ending in the id suffix (default: 'Id'). The field name before the 'Id' must be the same as the corresponding table name. See See [Virtual Fields](<https://github.com/phpfui/ORM/blob/main/docs/5. Virtual Fields.md>) for more advanced Related Records.
83+
Related records are indicated by field name ending in the id suffix (default: 'Id'). The field name before the 'Id' must be the same as the corresponding table name. See See [Virtual Fields](https://github.com/phpfui/ORM/blob/main/docs/5.%20Virtual%20Fields.md) for more advanced Related Records.
8484

8585
### Accessing Related Records
8686
You access the related record by the base field name (without the id suffix). The field with the id suffix is the primary key of the related record.
@@ -145,7 +145,7 @@ Notice that we did not have to save the customer record. By assigning it to the
145145
You can always just assign the id's directly: `$orderDetail->purchase_order_id = $purchase_order->purchase_order_id;`. Saving the OrderDetail record is up to you.
146146

147147
### Other Types Of Related Records
148-
See [Virtual Fields](<https://github.com/phpfui/ORM/blob/main/docs/5. Virtual Fields.md>) for information on how to impliment child or many to many relationships.
148+
See [Virtual Fields](https://github.com/phpfui/ORM/blob/main/docs/5.%20Virtual%20Fields.md) for information on how to impliment child or many to many relationships.
149149

150150
### Multi Database Support
151151
Related Records will always return a record from the currently selected database. Care must be taken when using multiple databases that any references to related records are done while the correct database instance is active. Cursors will continue to use the database in effect when they were created.

docs/3. Active Table.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# PHPFUI\ORM Active Table
2-
While an **Active Record** represents a single row in the database table, an **Active Table** represents the entire table. [\PHPFUI\ORM\Table](http://phpfui.com/?n=PHPFUI%5CORM&c=Table) allows you to find, select, update and delete multiple records at a time.
2+
While an **Active Record** represents a single row in the database table, an **Active Table** represents the entire table. [\PHPFUI\ORM\Table](http://phpfui.com/?n=PHPFUI%5CORM&c=Table) allows you to find, select, update, insert and delete multiple records at a time.
33

44
**Active Tables** are easy to manipulate in code and free you from constructing SQL statements with plain text.
55

@@ -72,7 +72,7 @@ $condition->or($conditionB);
7272
```
7373
The above will produce the PDO equivalent of `(lastName >= 'R' AND lastName < 'S') OR (lastName >= 'F' AND lastName < 'G')`
7474

75-
The [In](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=In) and [NotIn](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=NotIn) operators require the second parameter to [Condition](http://phpfui.com/?n=PHPFUI\ORM&c=Condition). The [Like](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=Like) and [NotLike](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=NotLike) operators will respect the % and _ characters, but you are responsible for putting them in the correct positions.
75+
The [In](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=In) and [NotIn](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=NotIn) operators require the second parameter to [Condition](http://phpfui.com/?n=PHPFUI\ORM&c=Condition) to be an array. The [Like](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=Like) and [NotLike](http://phpfui.com/?n=PHPFUI\ORM\Operator&c=NotLike) operators will respect the % and _ characters, but you are responsible for putting them in the correct positions.
7676

7777
#### Literal and Field classes
7878
Sometimes you need to compare something to a SQL constant or call a function. You can use `new \PHPFUI\ORM\Literal('CURRENT_TIMESTAMP()')`.

docs/4. Cursors.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ foreach ($customerTable->getDataObjectCursor() as $record)
3535
}
3636
```
3737
### RecordCursor
38-
A **RecordCursor** returns a **\PHPFUI\ORM\Record** typed from the table. It is a fully functional **Active Record**. It also implements [ArrayAccess](https://www.php.net/manual/en/class.arrayaccess.php), but is not an array.
38+
A **RecordCursor** returns a [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) typed from the table. It is a fully functional **Active Record**. It also implements [ArrayAccess](https://www.php.net/manual/en/class.arrayaccess.php), but is not an array.
3939
```php
4040
$customerTable = new \App\Table\Customer();
4141
$customerTable->setWhere(new \PHPFUI\ORM\Condition('first_name', 'Fred'));
@@ -49,5 +49,5 @@ foreach ($customerTable->getDataObjectCursor() as $record)
4949
}
5050
```
5151

52-
Please note that the **RecordCursor** reuses the same **\PHPFUI\ORM\Record** instance to conserve memory, so they will need to be cloned if added to an array or cursor. **DataObjectCursor** and **ArrayCursor** return new objects.
52+
Please note that the [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) reuses the same **\PHPFUI\ORM\Record** instance to conserve memory, so they will need to be cloned if added to an array or cursor. **DataObjectCursor** and **ArrayCursor** return new objects.
5353

docs/5. Virtual Fields.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ You can define virtual fields with get and set semantics for any **\App\Record**
55

66
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.
77

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.
8+
Note that virtual fields are created each time they are accessed and not stored or cached in the [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=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.
99

1010
The **VirtualField** class has two properties that will always be defined for use by the derived class:
1111
* $currentRecord is the current record that the virtual field should be based on.
@@ -35,13 +35,13 @@ Sometimes you can't name a related record with the name of the table. For examp
3535
You can make them all return employees with the following virtual field definitions:
3636
```php
3737
class Order extends \Tests\App\Record\Definition\Order
38-
{
39-
protected static array $virtualFields = [
40-
'salesPerson' => [\PHPFUI\ORM\RelatedRecord::class, \App\Record\Employee::class],
41-
'packedBy' => [\PHPFUI\ORM\RelatedRecord::class, \App\Record\Employee::class],
42-
'inspectedBy' => [\PHPFUI\ORM\RelatedRecord::class, \App\Record\Employee::class],
43-
];
44-
}
38+
{
39+
protected static array $virtualFields = [
40+
'salesPerson' => [\PHPFUI\ORM\RelatedRecord::class, \App\Record\Employee::class],
41+
'packedBy' => [\PHPFUI\ORM\RelatedRecord::class, \App\Record\Employee::class],
42+
'inspectedBy' => [\PHPFUI\ORM\RelatedRecord::class, \App\Record\Employee::class],
43+
];
44+
}
4545
```
4646
### Usage
4747
```php
@@ -88,7 +88,7 @@ class Order extends \Tests\App\Record\Definition\Order
8888
}
8989
```
9090

91-
By default, child records will be automatically deleted when the parent record is deleted. You can disable this functionality for a specific record class by setting the static property $deleteChildren to false, or using your own Children class.
91+
By default, child records will be automatically deleted when the parent record is deleted. You can disable this functionality for a specific [\PHPFUI\ORM\Record](http://phpfui.com/?n=PHPFUI%5CORM&c=Record) class by setting the static property $deleteChildren to false, or using your own Children class.
9292

9393
### Usage
9494
```php
@@ -137,12 +137,12 @@ Use \PHPFUI\ORM\Cast virtual field to accommplish this. The Cast virtual field w
137137
### Usage
138138
```php
139139
class Invoice extends \Tests\App\Record\Definition\Order
140-
{
141-
protected static array $virtualFields = [
142-
'due_date' => [\PHPFUI\ORM\Cast::class, \Carbon\Carbon::class],
143-
'invoice_date' => [\PHPFUI\ORM\Cast::class, \Carbon\Carbon::class],
144-
];
145-
}
140+
{
141+
protected static array $virtualFields = [
142+
'due_date' => [\PHPFUI\ORM\Cast::class, \Carbon\Carbon::class],
143+
'invoice_date' => [\PHPFUI\ORM\Cast::class, \Carbon\Carbon::class],
144+
];
145+
}
146146
$invoice = new Invoice(20);
147147
echo 'Lead Weeks: ' . $invoice->invoice_date->diffInWeeks($invoice->due_date);
148148
```

docs/7. Validation.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# PHPFUI\ORM Validation
22
*__Note__: Referenced namespaces in this document refer to the **PHPFUI\ORM** defaults.*
33

4-
Validator is an abstract class for Record validation See [\PHPFUI\ORM\Validator](http://phpfui.com/?n=PHPFUI%5CORM&c=Validator) namespace for examples.
4+
Validator is an abstract class for **\App\Record** validation See [\PHPFUI\ORM\Validator](http://phpfui.com/?n=PHPFUI%5CORM&c=Validator) namespace for examples.
55

66
Individual validators are listed in the table below. Validators can be combined. For example, a field can be **required**, and have a **minlength** and **maxlength**. Validators can have parameters. Parameters are separated by a colon (:) and then commas for each separate parameter.
77

@@ -22,9 +22,9 @@ foreach ($validationErrors as $field => $fieldErrors)
2222
{
2323
echo "Field {$field} has the following errors:\n";
2424
foreach ($fieldErrors as $error)
25-
{
26-
echo $error . "\n";
27-
}
25+
{
26+
echo $error . "\n";
27+
}
2828
}
2929
```
3030

@@ -73,7 +73,7 @@ foreach ($validationErrors as $field => $fieldErrors)
7373
| year_month | Loosely formatted Year Month | None |
7474

7575
## Field Comparison Validators
76-
You can compare one field to another on the same Record with the field validators.
76+
You can compare one field to another on the same **\App\Record** with the field validators.
7777
* gt_field
7878
* lt_field
7979
* gte_field
@@ -113,10 +113,10 @@ You can also pass an optional method to validate to perform more complex validat
113113
## Multi Validator Example
114114
```php
115115
class Order extends \PHPFUI\ORM\Validator
116-
{
117-
/** @var array<string, string[]> */
118-
public static array $validators = [
119-
'order_date' => ['required', 'maxlength', 'datetime', 'minvalue:2000-01-01', 'maxvalue:2099-12-31'],
120-
];
121-
}
116+
{
117+
/** @var array<string, string[]> */
118+
public static array $validators = [
119+
'order_date' => ['required', 'maxlength', 'datetime', 'minvalue:2000-01-01', 'maxvalue:2099-12-31'],
120+
];
121+
}
122122
```

docs/9. Transactions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ $transaction = new \PHPFUI\ORM\Transaction();
77
if ($allGood)
88
{
99
$transaction->commit();
10-
}
10+
}
1111
else
1212
{
1313
$transaction->rollBack();
14-
}
14+
}
1515
```
1616
The above creates a transaction on the current database. Commit and rollback will also be called on the correct database even if you are working on another database at the time.
1717

src/PHPFUI/ORM/Table.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,9 @@ public function setOrderBy(string $field, string $ascending = 'ASC') : self
826826
return $this->addOrderBy($field, $ascending);
827827
}
828828

829+
/**
830+
* Set user defined select fields.
831+
*/
829832
public function setSelectFields(string $clause) : static
830833
{
831834
$fields = \explode(',', $clause);

0 commit comments

Comments
 (0)