Skip to content

Commit 6e4da55

Browse files
committed
Fixing doc typos
1 parent b236b29 commit 6e4da55

File tree

7 files changed

+75
-33
lines changed

7 files changed

+75
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Why another PHP ORM? In writing minimal and fast websites, it was determined tha
1313
- **Virtual Fields** Supports get and set semantics for any custom or calculated field such as Carbon dates.
1414
- **Migrations** Simple migrations offer atomic up and down migrations.
1515
- **Relations** Parent, children, one to one, many to many, and custom relationships.
16-
- **Transactions** Object based transaction meaning exceptions can not leave an open transacton.
16+
- **Transactions** Object based transactions meaning exceptions will not leave an open transacton.
1717
- **Type Safe** Prevents stupid type errors.
1818
- **Injection Safe** Uses PDO placeholders and field sanitation to prevent injection attacks.
1919
- **Raw SQL Query Support** Execute any valid SQL command.

docs/1. Setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
Once generated, the Record, Table and Validation models will not be overwritten by the generation tools. Developers can add any logic to these classes they desire.
1818

19-
The Definition models should only be modified the the generation tools and not updated by hand.
19+
The Definition models should only be modified by the generation tools and not updated by hand.
2020

2121
Deletion of unused models should be done manually when the table is removed from the schema.
2222

docs/2. Active Record.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,45 +39,45 @@ $customer->read($value);
3939

4040
### The basic CRUD methods:
4141
- **insert**() or **create**()
42-
* 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.
43-
* insert() returns the primary key value inserted, true if no primary key and the record was successfully inserted or false on error.
42+
- 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.
43+
- insert() returns the primary key value inserted, true if no primary key and the record was successfully inserted or false on error.
4444
- **insertOrUpdate**() or **save**()
45-
* Will try to insert the record and on a duplicate key, will update the record with the current values.
46-
* insertOrUpdate() returns the same values as insert().
47-
* If the record only consists of primary keys, then this method is equivalent to insertOrIgnore().
45+
- Will try to insert the record and on a duplicate key, will update the record with the current values.
46+
- insertOrUpdate() returns the same values as insert().
47+
- If the record only consists of primary keys, then this method is equivalent to insertOrIgnore().
4848
- **insertOrIgnore**()
49-
* Will try to insert the record and on a duplicate key, will not update.
50-
* insertOrIgnore() returns the same values as insert().
49+
- Will try to insert the record and on a duplicate key, will not update.
50+
- insertOrIgnore() returns the same values as insert().
5151
- **read**(int | string | array $find)
52-
* Will try to load the first record matching the values passed in. If $find is an array, each key is used as a where condition equal to the value.
53-
* If not an array, read uses $find to search by primary key.
54-
* read() returns true on success or false if no match found
52+
- Will try to load the first record matching the values passed in. If $find is an array, each key is used as a where condition equal to the value.
53+
- If not an array, read uses $find to search by primary key.
54+
- read() returns true on success or false if no match found
5555
- **update**()
56-
* Returns true if the record saved to the database.
56+
- Returns true if the record saved to the database.
5757
- **delete**()
58-
* Deletes the record from the database. Defined child records are also deleted. You can overload delete() to do other custom work, like deleting an associated file if desired.
59-
* delete() returns true on success
58+
- Deletes the record from the database. Defined child records are also deleted. You can overload delete() to do other custom work, like deleting an associated file if desired.
59+
- delete() returns true on success
6060

6161
### Other useful methods:
6262
- **empty**()
63-
* Returns true if all current values are the defaults
63+
- Returns true if all current values are the defaults
6464
- **loaded**()
65-
* Returns true if actually read from the database, rather than being created programitically.
65+
- Returns true if actually read from the database, rather than being created programitically.
6666
- **reload**()
67-
* Gets the most recent version from the database and overwrites existing data.
67+
- Gets the most recent version from the database and overwrites existing data.
6868
- **setEmpty**()
69-
* Sets all the record values to defaults.
69+
- Sets all the record values to defaults.
7070
- **setFrom**(array)
71-
* Sets fields from the key / value array passed in.
71+
- Sets fields from the key / value array passed in.
7272

7373
### Advanced methods:
7474
- **clean**()
75-
* Can be overridden to perform actions before any write to the database.
75+
- Can be overridden to perform actions before any write to the database.
7676
- **setCustomValidator**(string $className)
77-
* Overrides the default validator with this class name.
77+
- Overrides the default validator with this class name.
7878
- **validate**(string $optionalMethod = '', ?self $originalRecord = NULL)
79-
* Validates the record. You can pass an optional method to validate against and original record if required by the validation.
80-
* Returns an array of errors indexed by field name. Empty array means the record has correctly validated.
79+
- Validates the record. You can pass an optional method to validate against and original record if required by the validation.
80+
- Returns an array of errors indexed by field name. Empty array means the record has correctly validated.
8181

8282
## Related Records
8383
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.

docs/4. Cursors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ foreach ($customerTable->getDataObjectCursor() as $record)
4949
}
5050
```
5151

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.
52+
**Please Note:** 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 collection. **DataObjectCursor** and **ArrayCursor** return new objects.
5353

docs/5. Virtual Fields.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
You can define virtual fields with get and set semantics for any **\App\Record** class. Virtual fields are evaluated before any database field, so you can override the database defaults if needed, or create new functionality.
55

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.
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 to the **getValue** and **setValue** methods.
77

88
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

@@ -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 [\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.
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 by using your own Children class.
9292

9393
### Usage
9494
```php

docs/7. Validation.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (! validationErrors)
1616
$insertedId = $record->insert();
1717
}
1818
```
19-
$validationErrors is an array indexed by field name containing an array of translated errors.
19+
**$validationErrors** is an array indexed by field name containing an array of translated errors.
2020
```php
2121
foreach ($validationErrors as $field => $fieldErrors)
2222
{
@@ -106,6 +106,18 @@ You want the name to be unique per division with in the company: *unique:company
106106
You want the name to be unique for a specific type in the division: *unique:type,shoes,division*
107107
You want the name to be unique for a specific type and division: *unique:type,shoes,division,10*
108108

109+
## NOT Operator
110+
You can reverse any validator by preceding the validator with an ! (exclamation mark).
111+
112+
**Example:**
113+
!starts_with:/ will fail if the field starts with a /
114+
115+
## OR Operator
116+
You can validate a field if any one of the validators passes. Use the vertical bar (|) to separate validators. If one of the validators passes, then the the field is valid.
117+
118+
**Example:**
119+
website|starts_with:/ will validate a fully qualified http url, or a root relative url.
120+
109121
## Optional Validation
110122
You may need to do additional checks for a specific record type. A second parameter can be passed to the contructor which would represent the original values of the record.
111123

src/PHPFUI/ORM/Validator.php

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,27 @@
1010
* ## Usage
1111
*
1212
* ```php
13-
* $record = new \PHPFUI\ORM\Record\Example($_POST);
13+
* $record = new \App\Record\Example();
14+
* $record->setFrom($_POST);
1415
* $validationErrors = $record->validate();
16+
* if (! validationErrors)
17+
* {
18+
* $insertedId = $record->insert();
19+
* }
20+
* ```
21+
* **$validationErrors** is an array indexed by field name containing an array of translated errors.
22+
* ```php
23+
* foreach ($validationErrors as $field => $fieldErrors)
24+
* {
25+
* echo "Field {$field} has the following errors:\n";
26+
* foreach ($fieldErrors as $error)
27+
* {
28+
* echo $error . "\n";
29+
* }
30+
* }
1531
* ```
16-
* <br>$validationErrors is an array indexed by field name containing an array of translated errors.
1732
*
18-
* | Validator Name | Description | Parameters |
33+
* | Validator Name | Description | Parameters |
1934
* | -------------- | ----------- | ----------- |
2035
* | alnum | Numbers and characters only (ctype_alnum) | None |
2136
* | alpha | Characters only (ctype_alpha) | None |
@@ -38,6 +53,7 @@
3853
* | gt_field | Greater Than field | field, required |
3954
* | gte_field | Greater Than or Equal to field | field, required |
4055
* | icontains | Field must contain (case insensitive) | comma separated list of strings |
56+
* | iends_with | Field must end with (case insensitive) | comma separated list of strings |
4157
* | integer | Whole number, no fractional part | None |
4258
* | istarts_with | Field must start with (case insensitive) | comma separated list of strings |
4359
* | lt_field | Less Than field | field, required |
@@ -48,6 +64,8 @@
4864
* | minvalue | Must be less than or equal | value, required |
4965
* | month_day_year | Loosely formatted date (M-D-Y) | None |
5066
* | month_year | Loosely formatted Month Year | None |
67+
* | neq_field | Not Equal to field | field, required |
68+
* | not_equal | Value must not be equal | value, required |
5169
* | number | Floating point number or whole number | None |
5270
* | required | Field is required, can't be null or blank, 0 is OK | None |
5371
* | starts_with | Field must start with (case sensitive) | comma separated list of strings |
@@ -58,14 +76,15 @@
5876
* | year_month | Loosely formatted Year Month | None |
5977
*
6078
* ## Field Comparison Validators
61-
* You can compare one field to another on the same Record with the field validators.
79+
* You can compare one field to another on the same **\App\Record** with the field validators.
6280
* * gt_field
6381
* * lt_field
6482
* * gte_field
6583
* * lte_field
6684
* * eq_field
85+
* * neq_field
6786
*
68-
* Field validators take another field name as a parameter and perform the specified condition test. To compare against a specific value, use minvalue, maxvalue, or equal.
87+
* Field validators take another field name as a parameter and perform the specified condition test. To compare against a specific value, use minvalue, maxvalue, equal or not_equal.
6988
*
7089
* ## Unique Parameters
7190
* Without any parameters, the **unique** validator will make sure no other record has a matching value for the field being validated. The current record is always exempted from the unique test so it can be updated.
@@ -105,6 +124,17 @@
105124
* You may need to do additional checks for a specific record type. A second parameter can be passed to the contructor which would represent the original values of the record.
106125
*
107126
* You can also pass an optional method to validate to perform more complex validation. If you use an optional method, the validator will not perform the standard validations unless you specifically call the validate() method again without the optional method parameter.
127+
*
128+
* ## Multi Validator Example
129+
* ```php
130+
* class Order extends \PHPFUI\ORM\Validator
131+
* {
132+
* /** @var array<string, string[]> */
133+
* public static array $validators = [
134+
* 'order_date' => ['required', 'maxlength', 'datetime', 'minvalue:2000-01-01', 'maxvalue:2099-12-31'],
135+
* ];
136+
* }
137+
* ```
108138
*/
109139
abstract class Validator
110140
{

0 commit comments

Comments
 (0)