Skip to content

Commit 4880181

Browse files
authored
Merge pull request #25 from byjg/6.0
# Micro ORM 6.0 - Major Release
2 parents 71ac84d + a028bd1 commit 4880181

File tree

134 files changed

+8067
-1986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+8067
-1986
lines changed

.github/workflows/phpunit.yml

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ on:
1212
jobs:
1313
Build:
1414
runs-on: 'ubuntu-latest'
15-
container: 'byjg/php:${{ matrix.php-version }}-cli'
15+
container:
16+
image: 'byjg/php:${{ matrix.php-version }}-cli'
17+
options: --user root --privileged
1618
strategy:
1719
matrix:
1820
php-version:
21+
- "8.5"
22+
- "8.4"
1923
- "8.3"
20-
- "8.2"
21-
- "8.1"
2224

2325
services:
2426
mysql:
@@ -38,10 +40,39 @@ jobs:
3840
MYSQL_TEST_HOST: mysql
3941

4042
steps:
41-
- uses: actions/checkout@v4
43+
- uses: actions/checkout@v5
4244
- run: composer install
43-
- run: ./vendor/bin/phpunit
44-
- run: ./vendor/bin/psalm
45+
- run: composer test
46+
47+
Psalm:
48+
name: Psalm Static Analyzer
49+
runs-on: ubuntu-latest
50+
permissions:
51+
# for github/codeql-action/upload-sarif to upload SARIF results
52+
security-events: write
53+
container:
54+
image: byjg/php:8.4-cli
55+
options: --user root --privileged
56+
57+
steps:
58+
- name: Git checkout
59+
uses: actions/checkout@v4
60+
61+
- name: Composer
62+
run: composer install
63+
64+
- name: Psalm
65+
# Note: Ignoring error code 2, which just signals that some
66+
# flaws were found, not that Psalm itself failed to run.
67+
run: ./vendor/bin/psalm
68+
--show-info=true
69+
--report=psalm-results.sarif || [ $? = 2 ]
70+
71+
- name: Upload Analysis results to GitHub
72+
uses: github/codeql-action/upload-sarif@v4
73+
if: github.ref == 'refs/heads/master'
74+
with:
75+
sarif_file: psalm-results.sarif
4576

4677
Documentation:
4778
if: github.ref == 'refs/heads/master'
@@ -50,5 +81,6 @@ jobs:
5081
with:
5182
folder: php
5283
project: ${{ github.event.repository.name }}
53-
secrets: inherit
84+
secrets:
85+
DOC_TOKEN: ${{ secrets.DOC_TOKEN }}
5486

.gitpod.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
tasks:
2+
- name: Run Composer
3+
command: |
4+
composer install
5+
6+
image: byjg/gitpod-image:latest
7+
8+
jetbrains:
9+
phpstorm:
10+
vmoptions: '-Xmx4g'
11+
plugins:
12+
- com.github.copilot
13+
- com.intellij.kubernetes
14+
- com.intellij.mermaid
15+
- ru.adelf.idea.dotenv
16+
- org.toml.lang
17+
18+
vscode:
19+
extensions:
20+
- ikappas.composer
21+
- hbenl.test-adapter-converter
22+
- hbenl.vscode-test-explorer
23+
- felixfbecker.php-debug
24+
- neilbrayfield.php-docblocker
25+
- bmewburn.vscode-intelephense-client
26+
- getpsalm.psalm-vscode-plugin
27+
- SonarSource.sonarlint-vscode
28+
- recca0120.vscode-phpunit

.idea/runConfigurations/psalm.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.vscode/launch.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Debug current Script in Console",
6+
"type": "php",
7+
"request": "launch",
8+
"program": "${file}",
9+
"cwd": "${fileDirname}",
10+
"port": 9003,
11+
"runtimeArgs": [
12+
"-dxdebug.start_with_request=yes"
13+
],
14+
"env": {
15+
"XDEBUG_MODE": "debug,develop",
16+
"XDEBUG_CONFIG": "client_port=${port}"
17+
}
18+
},
19+
{
20+
"name": "PHPUnit Debug",
21+
"type": "php",
22+
"request": "launch",
23+
"program": "${workspaceFolder}/vendor/bin/phpunit",
24+
"cwd": "${workspaceFolder}",
25+
"port": 9003,
26+
"runtimeArgs": [
27+
"-dxdebug.start_with_request=yes"
28+
],
29+
"env": {
30+
"XDEBUG_MODE": "debug,develop",
31+
"XDEBUG_CONFIG": "client_port=${port}"
32+
}
33+
}
34+
]
35+
}

README.md

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# MicroOrm for PHP
22

3+
[![Sponsor](https://img.shields.io/badge/Sponsor-%23ea4aaa?logo=githubsponsors&logoColor=white&labelColor=0d1117)](https://github.com/sponsors/byjg)
34
[![Build Status](https://github.com/byjg/php-micro-orm/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/php-micro-orm/actions/workflows/phpunit.yml)
45
[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)
56
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/php-micro-orm/)
@@ -14,10 +15,21 @@ Key Features:
1415
* Can be used with any DTO, Entity, Model or whatever class with public properties or with getter and setter
1516
* The repository support a variety of datasources: MySql, Sqlite, Postgres, MySQL, Oracle (see byjg/anydataset)
1617
* A class Mapper is used for mapping the Entity and the repository
18+
* Powerful mapper functions for automatic data transformation between models and database
1719
* Small and simple to use
1820

1921
## Architecture
2022

23+
MicroORM implements **Martin Fowler's enterprise patterns**:
24+
25+
- **[Repository](https://martinfowler.com/eaaCatalog/repository.html)**: Mediates between domain and data mapping layers
26+
- **[Data Mapper](https://martinfowler.com/eaaCatalog/dataMapper.html)**: Separates domain objects from database tables
27+
- **[Active Record](https://martinfowler.com/eaaCatalog/activeRecord.html)**: Wraps database rows with domain logic (
28+
alternative approach)
29+
30+
You can choose the pattern that best fits your application: use Repository + Data Mapper for complex domains, or Active
31+
Record for simpler CRUD-focused applications.
32+
2133
These are the key components:
2234

2335
```text
@@ -35,26 +47,35 @@ These are the key components:
3547
│ ┌───────────────┴─────┐
3648
│ │ Query │
3749
│ └───────────────┬─────┘
38-
39-
│ ┌───────────────┴─────┐
40-
│ │ DbDriverInterface │───────────────┐
41-
│ └───────────────┬─────┘
42-
│ │
43-
└──────────────────────────┘ .─────────.
44-
│ │
45-
│`─────────'│
46-
│ │
47-
│ DB │
48-
│ │
49-
│ │
50-
`─────────'
50+
51+
│ ┌───────────────┴─────┐ ┌──────────────────────┐
52+
│ │ DatabaseExecutor │────────│ DbDriverInterface │
53+
│ └───────────────┬─────┘ └────────────┬─────────┘
54+
│ │
55+
└──────────────────────────┘ .─────────.
56+
│ │
57+
│`─────────'│
58+
│ │
59+
│ DB │
60+
│ │
61+
│ │
62+
`─────────'
5163
```
5264

53-
* Model is a get/set class to retrieve or save the data into the database
54-
* Mapper will create the definitions to map the Model into the Database.
55-
* Query will use the Mapper to prepare the query to the database based on DbDriverInterface
56-
* DbDriverIntarce is the implementation to the Database connection.
57-
* Repository put all this together
65+
* **Model** can be any class with public properties or with getter and setter. It is used to retrieve or save the data
66+
into the database
67+
* **Mapper** defines the relationship between the Model properties and the database fields
68+
* **FieldMapping** defines individual field mappings within the Mapper (field names, transformations, relationships via
69+
`parentTable`)
70+
* **Query** defines what to retrieve from/update in the database. It uses the Mapper to prepare the query to the
71+
database converting the Model properties to database fields
72+
* **DatabaseExecutor** (external package) wraps the DbDriver and provides transaction management, query execution, and
73+
access to database helpers
74+
* **DbDriverInterface** (external package) is the actual database driver implementation that connects to the database
75+
* **Repository** orchestrates all MicroORM components and uses DatabaseExecutor to interact with the database
76+
77+
For a detailed explanation of the architecture and when to use each layer,
78+
see [Architecture Layers: Infrastructure vs Domain](docs/architecture-layers.md).
5879

5980

6081
## Getting Started
@@ -89,20 +110,21 @@ Let's look at an example:
89110
class MyModel
90111
{
91112
#[FieldAttribute(primaryKey: true)]
92-
public ?int $id;
113+
public ?int $id = null;
93114

94115
#[FieldAttribute()]
95-
public ?string $name;
116+
public ?string $name = null;
96117

97118
#[FieldAttribute(fieldName: 'company_id')
98-
public ?int $companyId;
119+
public ?int $companyId = null;
99120
}
100121
```
101122

102123
In this example, we have a class `MyModel` with three properties: `id`, `name`, and `companyId`.
103124

104-
The `id` property is marked as a primary key. The `name` property is a simple field.
105-
The `companyId` property is a field with a different name in the database `company_id`.
125+
* The `id` property is marked as a primary key.
126+
* The `name` property is a simple field.
127+
* The `companyId` property is a field with a different name in the database `company_id`.
106128

107129
The `TableAttribute` is used to define the table name in the database.
108130

@@ -111,8 +133,7 @@ The `TableAttribute` is used to define the table name in the database.
111133
After defining the Model, you can connect the Model with the repository.
112134

113135
```php
114-
$dbDriver = \ByJG\AnyDataset\Db\Factory::getDbRelationalInstance('mysql://user:password@server/schema');
115-
136+
$dbDriver = \ByJG\AnyDataset\Db\Factory::getDbInstance('mysql://user:password@server/schema');
116137
$repository = new \ByJG\MicroOrm\Repository($dbDriver, MyModel::class);
117138
```
118139

@@ -153,6 +174,11 @@ $result = $repository->getByQuery($query);
153174
* [Querying the Database](docs/querying-the-database.md)
154175
* [Updating the database](docs/updating-the-database.md)
155176
* [Using the Mapper Object](docs/using-mapper-object.md)
177+
* [The Model Attributes](docs/model-attribute.md)
178+
* [The Repository Class](docs/repository.md)
179+
* [Common Traits for Timestamp Fields](docs/common-traits.md)
180+
* [Architecture Layers: Infrastructure vs Domain](docs/architecture-layers.md)
181+
* [Comparison with Other ORMs (Eloquent, Doctrine)](docs/comparison-with-other-orms.md)
156182

157183
## Advanced Topics
158184

@@ -163,10 +189,14 @@ $result = $repository->getByQuery($query);
163189
* [Caching the Results](docs/cache.md)
164190
* [Observing the Database](docs/observers.md)
165191
* [Controlling the data queried/updated](docs/controlling-the-data.md)
192+
* [Mapper Functions](docs/mapper-functions.md)
166193
* [Using FieldAlias](docs/using-fieldalias.md)
167194
* [Tables without auto increments fields](docs/tables-without-auto-increment-fields.md)
168195
* [Using With Recursive SQL Command](docs/using-with-recursive-sql-command.md)
169196
* [QueryRaw (raw SQL)](docs/query-raw.md)
197+
* [Update Constraints](docs/update-constraints.md)
198+
* [Building SQL Queries](docs/query-build.md)
199+
* [UUID Support](docs/uuid-support.md)
170200

171201
## Install
172202

@@ -199,4 +229,4 @@ flowchart TD
199229
```
200230

201231
----
202-
[Open source ByJG](http://opensource.byjg.com)
232+
[Open source ByJG](http://opensource.byjg.com)

composer.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "byjg/micro-orm",
3-
"description": "A micro framework for create a very simple decoupled ORM (sqlite, mysql, postgres, sqlserver)",
3+
"description": "A micro framework for create a very simple decoupled ORM. This library intended to be very small and very simple to use",
44
"autoload": {
55
"psr-4": {
66
"ByJG\\MicroOrm\\": "src/"
@@ -14,19 +14,23 @@
1414
"prefer-stable": true,
1515
"minimum-stability": "dev",
1616
"require": {
17-
"php": ">=8.1 <8.4",
17+
"php": ">=8.3 <8.6",
1818
"ext-json": "*",
1919
"ext-pdo": "*",
20-
"byjg/anydataset-db": "^5.0"
20+
"byjg/anydataset-db": "^6.0"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "^9.6",
24-
"byjg/cache-engine": "^5.0",
25-
"vimeo/psalm": "^5.9"
23+
"phpunit/phpunit": "^10.5|^11.5",
24+
"byjg/cache-engine": "^6.0",
25+
"vimeo/psalm": "^5.9|^6.13"
2626
},
2727
"suggest": {
2828
"ext-curl": "*",
2929
"ext-pdo_mysql": "*"
3030
},
31+
"scripts": {
32+
"test": "vendor/bin/phpunit",
33+
"psalm": "vendor/bin/psalm --threads=1"
34+
},
3135
"license": "MIT"
3236
}

0 commit comments

Comments
 (0)