Download the PHP package tobento/service-repository without Composer
On this page you can find all versions of the php package tobento/service-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tobento/service-repository
More information about tobento/service-repository
Files in tobento/service-repository
Package service-repository
Short Description Repository interfaces for PHP applications.
License MIT
Homepage https://www.tobento.ch
Informations about the package service-repository
Repository Service
Repository interfaces for PHP applications.
Table of Contents
- Getting started
- Requirements
- Highlights
- Documentation
- Interfaces
- Repository Interface
- Read Repository Interface
- Write Repository Interface
- Locales Aware Interface
- Entity Factory Interface
- Null Repository
- Read Only Repository Adapter
- Events Repository Adapter
- Eventer
- Interfaces
- Credits
Getting started
Add the latest version of the repository service project running this command.
Requirements
- PHP 8.4 or greater
Highlights
- Framework-agnostic, will work with any project
- Decoupled design
Documentation
Interfaces
Repository Interface
Read Repository Interface
Write Repository Interface
Locales Aware Interface
You may implement the locales aware interface into your repository using the trait.
Entity Factory Interface
Null Repository
The NullRepository is a no-operation implementation of RepositoryInterface.
It accepts all read and write operations without performing any side effects and returns neutral, predictable values.
This makes it useful for:
- disabling persistence in development or testing environments
- providing a safe fallback when no repository is configured
- stubbing repository dependencies in prototypes
- avoiding conditional logic (
if ($repo) { ... }) - ensuring repository calls never throw or mutate state
Features
- Implements the full
RepositoryInterface - All read operations return neutral values:
nullfor single-entity lookups- empty arrays/iterables for multi-entity queries
0for counts
- All write operations return simple objects based on the provided attributes
- No exceptions are thrown
- No state is stored and no side effects occur
Returned Values Overview
| Method | Return Value |
|---|---|
findById() |
null |
findByIds() |
[] |
findOne() |
null |
findAll() |
[] |
findColumn() |
[] |
count() |
0 |
create() |
(object)$attributes |
updateById() |
(object)$attributes |
update() |
[] |
deleteById() |
(object)['id' => $id] |
delete() |
[] |
Example
Read Only Repository Adapter
Any repository implementing the can be made read-only by decorating them using the :
Events Repository Adapter
Any repository implementing the or can be made to dispatch default events by decorating them using the :
Default Events
| Event | Description |
|---|---|
| The event will dispatch after an entity is retrieved from the read methods only. | |
| The event will dispatch before an entity is created. | |
| The event will dispatch after an entity is created. | |
| The event will dispatch before an entity is updated. | |
| The event will dispatch after an entity is updated. | |
| The event will dispatch before an entity is deleted. | |
| The event will dispatch after an entity is deleted. |
Eventer
The eventer may be used to easily create a if you want only to have certain events dispatched.
Create Eventer
Using Eventer
Credits
- Tobias Strub
- All Contributors
All versions of service-repository with dependencies
tobento/service-collection Version ^2.0
tobento/service-iterable Version ^2.0