Download the PHP package tomkyle/repository-persistence without Composer
On this page you can find all versions of the php package tomkyle/repository-persistence. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tomkyle/repository-persistence
More information about tomkyle/repository-persistence
Files in tomkyle/repository-persistence
Package repository-persistence
Short Description Scaffold for Repository-and-Persistence design pattern
License proprietary
Informations about the package repository-persistence
Repository · Persistence
Scaffold for Repository-and-Persistence design pattern.
Installation
Setup
The repository needs a persistence.
In this example, the Persistence works on a directory path/to/json
in which the items are stored in JSON files named by their ID. — Example: john-doe.json
Usage
Get item. This method may throw \OutOfBoundsException
Output will be like:
Find one item by criteria. This method may return null
.
Get all items:
Find items by criteria
Update item
Delete item
Create new item
If you need the new ID onbeforehand in your App controller, e.g. for redirecting the client to the new resource, you can obtain a new ID from the repo. It then looks exactly like updating, but the Repository implementation will figure out if the item has to be created or updated.
Persistence
Inside a repository, the Persistence actually manages the data storage.
Instantiation
Methods API
Method | Parameters | Return | Description |
---|---|---|---|
create | array data |
string¦int |
New ID |
read | string¦int id |
array |
The record |
readAll | array | All records | |
update | array data |
int |
Affected rows |
delete | string¦int |
int |
Affected rows |
Special implementations
FrontmatterFilePersistence
If your JSON or YAML files have frontmatters:
PersistenceChain
InMemoryPersistence
An empty Persistence you can write and read to.
NoPersistence
Mock implementation of Persistence that simulates data persistence operations without actually storing data. Note that read method will always throw \OutOfBoundsException
as it does not contain any data!
Repository
The repository is the thing you work with in your app.
Methods API
Method | Required Parameters | Optional | Return | Description |
---|---|---|---|---|
get | string¦int id |
array¦object |
The record | |
findOneBy | array criteria |
array¦object¦null |
One record | |
findAll | iterable |
All records | ||
findBy | array criteria |
?array orderBy,?int limit?int offset |
iterable |
Some records |
save | array¦object entity |
bool |
||
delete | array¦object entity |
bool |
Development
Install requirements
Watch source and run various tests
This will watch changes inside the src/ and tests/ directories and run a series of tests:
- Find and run the according unit test with PHPUnit.
- Find possible bugs and documentation isses using phpstan.
- Analyse code style and give hints on newer syntax using Rector.
Run all tests
Choose to your taste: