Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcred/phpred
Relationships, Entities and Datasources for PHP
https://github.com/mcred/phpred
codeclimate orm php7 phpunit-6 test-driven-development travis-ci
Last synced: about 16 hours ago
JSON representation
Relationships, Entities and Datasources for PHP
- Host: GitHub
- URL: https://github.com/mcred/phpred
- Owner: mcred
- Created: 2017-05-31T18:20:01.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-31T14:00:57.000Z (about 7 years ago)
- Last Synced: 2024-05-05T20:45:31.503Z (7 months ago)
- Topics: codeclimate, orm, php7, phpunit-6, test-driven-development, travis-ci
- Language: PHP
- Homepage:
- Size: 40 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHPRed
[![Build Status](https://travis-ci.org/mcred/phpred.svg?branch=master)](https://travis-ci.org/mcred/phpred)
[![Code Climate](https://codeclimate.com/github/mcred/phpred/badges/gpa.svg)](https://codeclimate.com/github/mcred/phpred)
[![Test Coverage](https://codeclimate.com/github/mcred/phpred/badges/coverage.svg)](https://codeclimate.com/github/mcred/phpred/coverage)
[![Issue Count](https://codeclimate.com/github/mcred/phpred/badges/issue_count.svg)](https://codeclimate.com/github/mcred/phpred)### Description
PHPRed is an opinionated light weight ORM. While there are many available ORMs for PHP, many contain features that I have never used. PHPRed contains very basic methods and usage.
### Requirements
* PHP 7.1+
* Composer
* Mysqli### Installation
```
composer require mcred/phpred
```### Setup
In addition to the example below, there are examples available in the `tests/mocks` folder. Setting up a model is very easy: create a model class that extends the `PHPRed/Models/Model` class then define the properties of that model in the constructor. Such as:
```php
model = 'MyClass';
$this->table = 'my_class';
$this->primaryKey = 'id';
$this->foreignKey = 'my_class_id';
$this->fields = ['id', 'name'];
$this->requiredFields = ['name'];
$this->uniqueFields = ['name'];
$this->hasMany = ['MyClassProperties'];
$this->hasAndBelongsToMany = ['Users'];parent::__construct($mysql);
}
}```
### Constructor Properties
* model: string
* table: string
* primaryKey: string
* foreignKey: string
* fields: array
* requiredFields: array
* uniqueFields: array
* hasMany: array
* belongsTo: array
* hasAndBelongsToMany: array### Methods
* getAll() : array
* getById(int $modelId) : array
* getBySearch(array ['key' => 'value']) : array
* insert(array $data) : array
* updateById(int $modelId, array $data) : array
* deleteById(int $modelId): void