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

Draft: 3.x #14

Merged
merged 67 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
00200eb
#6 Add php-cs-fixer, update php and illuminate/database versions, sta…
dimitriBouteille Sep 25, 2023
799de0a
#6 Add PingStatus & PostStatus
dimitriBouteille Sep 25, 2023
e4aeda3
#6 Add phpStan
dimitriBouteille Sep 26, 2023
7988eda
#6 Add rector, start API models support
dimitriBouteille Sep 26, 2023
d4a84c2
#6 CS
dimitriBouteille Sep 26, 2023
29d86d8
#6 WIP api
dimitriBouteille Sep 27, 2023
88a2d83
#6 Run rector
dimitriBouteille Sep 27, 2023
01ca641
#6 Some fix
dimitriBouteille Sep 27, 2023
57fcf36
#6 Fix UPDATED_AT & CREATED_AT Post constants
dimitriBouteille Oct 2, 2023
2cc1a56
#6 Fix UPDATED_AT & CREATED_AT User constants
dimitriBouteille Oct 2, 2023
7baab1f
Test github workflows
dimitriBouteille Oct 4, 2023
42cabda
#10 Start fix comment issue
dimitriBouteille Oct 21, 2023
9fbe26a
#10 Implement comment deprecated functions
dimitriBouteille Oct 21, 2023
9b3bf90
#11 Replace $cast date by datetime in Comment, Post and User models
dimitriBouteille Oct 28, 2023
a10b6e7
#12 Add User helpers
dimitriBouteille Nov 5, 2023
6bb6935
#12 Add Option helpers
dimitriBouteille Nov 5, 2023
d9eca33
#12 Add Attachment helpers
dimitriBouteille Nov 5, 2023
f295ecf
#12 CS
dimitriBouteille Nov 5, 2023
acd66c3
Update Doc
dimitriBouteille Nov 5, 2023
c8df7f1
Add some scopes, CS
dimitriBouteille Jan 13, 2024
e47cdf3
Support migration options config
dimitriBouteille Jan 13, 2024
1bfee5d
Use findOneBy*
dimitriBouteille Jan 13, 2024
f787814
Update Readme
dimitriBouteille Jan 13, 2024
816a556
Update Readme installation
dimitriBouteille Jan 13, 2024
70c5f86
#12 Update custom post feature, rollback customModelPost to CustomPos…
dimitriBouteille Jan 14, 2024
89fcfaf
#12 Update phpdoc, set deprecated findOne* in builder, fix Models\Pag…
dimitriBouteille Jan 14, 2024
532899c
#12 Update README.md
dimitriBouteille Jan 14, 2024
067a1c9
#12 Add CONTRIBUTING.md
dimitriBouteille Jan 14, 2024
ddf7423
#12 Add issue templates
dimitriBouteille Jan 14, 2024
3a13e81
#12 Add config.yml
dimitriBouteille Jan 14, 2024
4f35535
#12 Replace scope by taps, update blank_issues_enabled, change php-cs…
dimitriBouteille Jan 14, 2024
35f6c4e
#12 WIP doc
dimitriBouteille Jan 14, 2024
dfa984a
#12 Add eloquent version
dimitriBouteille Jan 14, 2024
0bbd718
Update CI
dimitriBouteille Jan 18, 2024
1c1c2f5
Update CI
dimitriBouteille Jan 18, 2024
285d9c2
Update CI
dimitriBouteille Jan 18, 2024
c3a94c3
Start clean Meta feature
dimitriBouteille Jan 19, 2024
02a9a63
WIP clean Meta feature
dimitriBouteille Jan 19, 2024
eb5574f
Finish clean Meta builder, CS, PHPStan level 5, clean Api models
dimitriBouteille Jan 19, 2024
26c75df
Update CI (remove rector)
dimitriBouteille Jan 19, 2024
807f445
Remove index.php, update doc
dimitriBouteille Jan 19, 2024
a23e7c6
Remove Api model interface
dimitriBouteille Jan 20, 2024
21c22ce
#7 Update doc
dimitriBouteille Jan 20, 2024
fa69875
#7 WIP doc
dimitriBouteille Jan 20, 2024
a508fab
#7 WIP doc
dimitriBouteille Jan 20, 2024
2d39ee4
Fix Post::findOneByName, Refactor meta management
dimitriBouteille Jan 21, 2024
1212d33
Fix CPT post_type in constructor args, add phpunit tests
dimitriBouteille Jan 21, 2024
edf35be
CS
dimitriBouteille Jan 21, 2024
5a2459f
Update CI PHPUnit
dimitriBouteille Jan 21, 2024
59b9e79
Update PHPUnit config
dimitriBouteille Jan 21, 2024
0418716
Add tests
dimitriBouteille Jan 21, 2024
335dcc2
Update CI
dimitriBouteille Jan 21, 2024
578d57c
Update CI
dimitriBouteille Jan 21, 2024
acc0aab
Split CI
dimitriBouteille Jan 21, 2024
49c31c0
Add test badge
dimitriBouteille Jan 21, 2024
1c0a220
Update composer.json, add badge links
dimitriBouteille Jan 21, 2024
affdd85
#7 WIP documentation
dimitriBouteille Jan 22, 2024
72eb1ff
Test to Tests directory
dimitriBouteille Jan 22, 2024
02869df
Add WithMetaBuilderTest, fix join meta value
dimitriBouteille Jan 29, 2024
a14ac66
Add Post::findOneByGuid()
dimitriBouteille Jan 29, 2024
b1e6500
Remove composer.json version
dimitriBouteille Jan 29, 2024
4d6f7b2
Some update
dimitriBouteille Jan 30, 2024
145d3fc
#7 Update documentation
dimitriBouteille Jan 30, 2024
55b71e9
Update CI, WIP doc
dimitriBouteille Feb 11, 2024
8f17795
Fix rector CI
dimitriBouteille Feb 11, 2024
effa124
Disable rector CI
dimitriBouteille Feb 11, 2024
b96161e
Update README.md
dimitriBouteille Feb 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Bug report
about: Create a report to help us improve
title: '[BUG]: '
labels: ["bug"]
assignees:
- dimitriBouteille

---

### Describe the bug

A clear and concise description of what the bug is.

### Steps to reproduce the issue

A clear and concise description to reproduce the bug.

### Expected behavior

A clear and concise description of what you expected to happen.

### Your setup

- Wordpress Version: [e.g. 6.4.2]
- Module version: [e.g. 3.0.0]
- Are you using framework ?: [e.g. Bedrock, Wordplate, ... - If yes, Please specify the framework and version]

### Additional context

Add any other context about the problem here.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: true
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Feature request
about: Suggest an idea for this project
title: '[FEATURE]: '
labels: ["enhancement"]
assignees:
- dimitriBouteille

---

### Introduction

Making your own contribution is easy, encouraged and greatly appreciated! We will put effort into reviewing and merging your PR quickly. For more info, please refer to the [contribution guidelines](https://github.com/dbout/wp-orm/blob/develop/CONTRIBUTING.md).

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

### Describe the solution you'd like

A clear and concise description of what you want to happen.

### Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

### Additional context

Add any other context or screenshots about the feature request here.
31 changes: 31 additions & 0 deletions .github/workflows/styles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Coding Styles

on:
pull_request:

jobs:
codingStyle:
name: Coding Style
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: PHPCsFixer
run: composer csFixer

#- name: Rector
# run: composer rector

- name: PHPStan Analyse
run: composer phpstan
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Tests

on:
pull_request:

jobs:
test:
name: Tests
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Configure PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
tools: composer:v2

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Running unit test
run: composer phpunit
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

vendor/
var/
.idea/

composer.lock
.php-cs-fixer.cache
48 changes: 48 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright (c) 2023 Dimitri BOUTEILLE
* See LICENSE.txt for license details.
*
* Author: Dimitri BOUTEILLE <bonjour@dimitri-bouteille.fr>
*/

$finder = \PhpCsFixer\Finder::create()
->name('*.php')
->in([
'src',
])
;

$header = <<<EOF
Copyright (c) 2024 Dimitri BOUTEILLE (https://github.com/dimitriBouteille)
See LICENSE.txt for license details.

Author: Dimitri BOUTEILLE <bonjour@dimitri-bouteille.fr>
EOF;

$config = new \PhpCsFixer\Config();
return $config
->setFinder($finder)
->setCacheFile(__DIR__ . '/var/.php-cs-fixer.cache')
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'@PHP81Migration' => true,
'strict_param' => true,
'array_syntax' => ['syntax' => 'short'],
'octal_notation' => false,
'trim_array_spaces' => true,
'phpdoc_order' => true,
'ordered_imports' => true,
'new_with_braces' => true,
'method_chaining_indentation' => true,
'no_unused_imports' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'header_comment' => [
'header' => $header,
'comment_type' => 'PHPDoc',
'location' => 'after_open',
'separate' => 'bottom',
],
]);
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Contribution guidelines

## How to contribute step-by-step

1. Fork the `dbout/wp-orm` repository.
2. Create a new branch from `main` in your fork. This makes it easier for you to keep track of your changes.
3. Make the desired changes to the code.
* If you are adding new functionality or fixing a bug, we recommend you add unit tests that cover it.
4. Push the changes to your fork.
5. Create a pull request to the `dbout/wp-orm` repository.
6. In your pull request, please describe in detail:
* What problem you’re solving
* Your approach to fixing the problem
* Any tests you wrote
7. Check Allow edits from maintainers.
8. Create the pull request.
9. Ensure that all checks have passed.

After you create your pull request, one of the code owners will review your code.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Dimitri BOUTEILLE
Copyright (c) 2024 Dimitri BOUTEILLE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
94 changes: 46 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,70 @@
# Wordpress ORM with Eloquent
# WordPress ORM with Eloquent

![GitHub Release](https://img.shields.io/github/v/release/dimitriBouteille/wp-orm) [![tests](https://img.shields.io/github/actions/workflow/status/dimitriBouteille/wp-orm/tests.yml?label=tests)](https://github.com/dimitriBouteille/wp-orm/actions/workflows/tests.yml) [![Packagist Downloads](https://img.shields.io/packagist/dt/dbout/wp-orm?color=yellow)](https://packagist.org/packages/dbout/wp-orm) ![Eloquent version](https://img.shields.io/packagist/dependency-v/dbout/wp-orm/illuminate%2Fdatabase?color=orange)

WordPress ORM wih Eloquent is a small library that adds a basic ORM into WordPress, which is easily extendable and includes models for core WordPress models such as posts, post metas, users, comments and more.
The ORM is based on [Eloquent ORM](https://laravel.com/docs/8.x/eloquent) and uses the Wordpress connection (`wpdb` class).
The ORM is based on [Eloquent ORM](https://laravel.com/docs/eloquent) and uses the WordPress connection (`wpdb` class).

The ORM also offers a system to simply manage database migrations based on [Phinx](https://phinx.org/).

Requirements
--------

The server requirements are basically the same as for [WordPress](https://wordpress.org/about/requirements/) with the addition of a few ones :
> 💡 To simplify the integration of this library, we recommend using WordPress with one of the following tools: [Bedrock](https://roots.io/bedrock/), [Themosis](https://framework.themosis.com/) or [Wordplate](https://github.com/wordplate/wordplate#readme).

- PHP >= 7.4
- [Composer](https://getcomposer.org/) ❤️
### Features

> To simplify the integration of this library, we recommend using Wordpress with one of the following tools: [Bedrock](https://roots.io/bedrock/), [Themosis](https://framework.themosis.com/) or [Wordplate](https://github.com/wordplate/wordplate#readme).
- ✅ Support core WordPress models: `Comment`, `Option`, `Post`, `TermTaxonomy`, `Term`, `User`, `PostMeta` and `UserMeta`
- ✅ Support core WordPress post type: `Article`, `Attachment` and `Page`
- ✅ Based on core WordPress database connection (`wpdb` class), no configuration required !
- ✅ Migration with `Phinx`
- ✅ Custom functions to filter models with meta
- ❤️ Easy integration of a custom post type
- ❤️ Easy model creation for projects with custom tables
- ❤️ All the features available in Eloquent, are usable with this library !

Installation
--------
**Not yet developed but planned in a future version:**

- 🗓️ Create custom comment type
- 🗓️ Meta casting (e.g. [Attribute Casting](https://laravel.com/docs/10.x/eloquent-mutators#attribute-casting))

Install with composer, in the root of the Wordpress project run:

```bash
composer require dbout/wp-orm
```
### Documentation

Basic usage with core Wordpress models
--------
This documentation only covers the specific points of this library, if you want to know more about Eloquent, the easiest is to look at [the documentation of Eloquent](https://laravel.com/docs/10.x/eloquent) :)

### Page model
- [Installation](#installation)
- [Use WordPress core models](doc/wordpress-core-models.md)
- [Filter data](/doc/filter-data.md)
- [With findOneBy*](/doc/filter-data.md#with-findoneby)
- [With taps](/doc/filter-data.md#with-taps)
- [With query builder](/doc/filter-data.md#with-query-builder)
- [Create custom model](doc/create-model.md)
- [Generic Model](doc/create-model.md#generic-model)
- [Custom Post Type Model](doc/create-model.md#custom-post-type-model)
- [Migration with Phinx](doc/migration.md)

#### Queries
## Installation

```php
# Get all pages
$pages = \Dbout\WpOrm\Models\Page::all();
**Requirements**

# Get one page by ID
$page = \Dbout\WpOrm\Models\Page::find(15);

# Get all pages by author
$pages = \Dbout\WpOrm\Models\Page::query()
->whereAuthor(1)
->get();

# Get all publish pages
$pages = \Dbout\WpOrm\Models\Page::query()
->whereStatus('publish')
->get();
```
The server requirements are basically the same as for [WordPress](https://wordpress.org/about/requirements/) with the addition of a few ones :

- PHP >= 8.1
- [Composer](https://getcomposer.org/)

### Migration
**Installation**

To use phinx, you must create a configuration file named `config-phinx.php` at the root of your project. To create this file, please see one of the following documentation:
You can use [Composer](https://getcomposer.org/). Follow the [installation instructions](https://getcomposer.org/doc/00-intro.md) if you do not already have composer installed.

- [Create config-phinx.php file for Bedrock Framework](doc/migration-with-bedrock.md)
~~~bash
composer require dbout/wp-orm
~~~

If you would like to learn more about the configuration file, please visit [Phinx - Configuration](https://phinx.readthedocs.io/en/latest/configuration.html).
In your PHP script, make sure you include the autoloader:

#### Create new migration :
~~~php
require __DIR__ . '/vendor/autoload.php';
~~~

```bash
php vendor/bin/phinx create -c config-phinx.php
```
🎉 You have nothing more to do, you can use the library now! Not even need to configure database accesses because it's the `wpdb` connection that is used.

#### Run migration :
## Contributing

```bash
php vendor/bin/phinx migrate -c config-phinx.php
```
We encourage you to contribute to this repository, so everyone can benefit from new features, bug fixes, and any other improvements. Have a look at our [contributing guidelines](CONTRIBUTING.md) to find out how to raise a pull request.
42 changes: 35 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "dbout/wp-orm",
"description": "Wordpress ORM with Eloquent and Phinx",
"description": "WordPress ORM with Eloquent and Phinx.",
"type": "package",
"license": "GPL-2.0-or-later",
"license": "MIT",
"authors": [
{
"name": "Dimitri BOUTEILLE",
Expand All @@ -12,16 +12,17 @@
}
],
"keywords": ["wordpress", "wp", "orm", "database", "eloquent", "db", "sql", "migration", "phinx"],
"homepage": "https://github.com/dimitriBouteille/wp-orm/",
"homepage": "https://github.com/dimitriBouteille/wp-orm",
"support": {
"issues": "https://github.com/dimitriBouteille/wp-orm/issues"
"issues": "https://github.com/dimitriBouteille/wp-orm/issues",
"source": "https://github.com/dimitriBouteille/wp-orm/"
},
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.4|^8.0",
"illuminate/database": "^8.0",
"robmorgan/phinx": "^0.12.5"
"php": ">=8.1",
"robmorgan/phinx": "^0.12.5",
"illuminate/database": "^10.0"
},
"suggest": {
"illuminate/events": "Add events to your models"
Expand All @@ -33,5 +34,32 @@
"psr-4": {
"Dbout\\WpOrm\\": "src/"
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.28",
"phpstan/phpstan": "^1.10",
"rector/rector": "^0.18.4",
"phpunit/phpunit": "^10.5",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/extension-installer": "^1.3"
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"extra": {
"phpstan": {
"includes": [
"extension.neon"
]
}
},
"scripts": {
"rector": "vendor/bin/rector process src --dry-run",
"phpstan": "vendor/bin/phpstan analyse -c phpstan.neon",
"phpunit": "vendor/bin/phpunit",
"csFixer": "vendor/bin/php-cs-fixer fix --verbose --diff --dry-run",
"fix:csFixer": "vendor/bin/php-cs-fixer fix"
}
}
Loading
Loading