analogue / orm
An intuitive Data Mapper ORM for PHP and Laravel
Installs: 46 122
Dependents: 4
Suggesters: 0
Security: 0
Stars: 632
Watchers: 30
Forks: 52
Open Issues: 8
Requires
- php: >=7.2.0
- doctrine/instantiator: ^1.0.0
- illuminate/database: 6.0.* | 6.1.* | 6.2.*
- illuminate/events: 6.0.* | 6.1.* | 6.2.*
- illuminate/pagination: 6.0.* | 6.1.* | 6.2.*
- ocramius/generated-hydrator: ^2.0.0
- ocramius/proxy-manager: ^2.0.0
- psr/container: ~1.0
- psr/simple-cache: ~1.0
Requires (Dev)
- analogue/factory: 1.2.*|1.3.*
- fzaninotto/faker: ~1.4
- laravel/browser-kit-testing: ^1.0
- laravel/laravel: 6.0.* | 6.1.* | 6.2.*
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~8.0
- symfony/css-selector: 2.8.*|3.0.*|4.0.*
- symfony/dom-crawler: 2.8.*|3.0.*|4.0.*
Suggests
- analogue/factory: Create simple dummy entities for your tests
- analogue/laravel-auth: Analogue's authentication driver for Laravel.
- analogue/mongodb: MongoDB driver for Analogue ORM
- 6.2.x-dev
- v6.2.0
- 6.0.x-dev
- v6.0.1
- v6.0.0
- 5.6.x-dev
- v5.6.15
- v5.6.14
- v5.6.13
- v5.6.12
- v5.6.11
- v5.6.10
- v5.6.9
- v5.6.8
- v5.6.7
- v5.6.6
- v5.6.5
- v5.6.4
- v5.6.3
- v5.6.2
- v5.6.1
- v5.6.0
- 5.5.x-dev
- v5.5.22
- v5.5.21
- v5.5.20
- v5.5.19
- v5.5.18
- v5.5.17
- v5.5.16
- v5.5.15
- v5.5.14
- v5.5.13
- v5.5.12
- v5.5.11
- v5.5.10
- v5.5.9
- v5.5.8
- v5.5.7
- v5.5.6
- v5.5.4
- v5.5.3
- v5.5.2
- v5.5.1
- v5.5.0
- 5.4.x-dev
- v5.4.2
- v5.4.1
- v5.4.0
- 5.3.x-dev
- v5.3.2
- v5.3.1
- v5.3.0
- v5.2.5
- v5.2.4
- v5.2.3
- v5.2.2
- v5.2.1
- v5.2
- 5.1.x-dev
- v5.1.9
- 5.1.8
- v5.1.7
- v5.1.6
- v5.1.5
- v5.1.4
- v5.1.3
- v5.1.2
- v5.1.1
- v5.1
- 5.0.x-dev
- v5.0.2
- v5.0.1
- v5.0
- v2.1.10
- v2.1.9
- v2.1.8
- v2.1.7
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0
- 1.0.x-dev
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-analysis-2QAAJd
- dev-laravel_6.1_laravel_6.2
- dev-analysis-0g77AM
- dev-master
- dev-laravel-6.x-support
- dev-analysis-wjWwG2
- dev-fix/inheritance-eager-loading
This package is auto-updated.
Last update: 2024-10-14 11:37:59 UTC
README
(this project is looking for a new maintainer)
Analogue ORM
Analogue is a flexible, easy-to-use ORM for PHP. It is a transposition of the Eloquent ORM that ships with Laravel framework using a Data Mapper pattern instead of the original Active Record approach. it overcomes some of Eloquent's architectural limitations by using a strict separation of concerns; for example, you can use Value Objects or Single-table-inheritance, which are hard/impossible to implement correctly using the native ORM.
As a Laravel package, it integrates flawlessly inside the framework, and provides a more powerfull peristance layer, allowing to build enterprise-grade applications while retaining a simple and enjoyable development experience.
Installation
composer require analogue/orm
See Configuration for more information.
Concept
The concept is simple; your model layer is defined using 2 classes : one Entity, which can be any PHP class or extends the base Analogue\ORM\Entity class which provides magic getters and setters, and one EntityMap which defines relationships, castings, table name, database column names.
Take this simple domain model :
use Analogue\ORM\Entity; use Illuminate\Support\Collection; class Blog extends Entity { public function __construct() { $this->posts = new Collection; } public function addPost(Post $post) { $this->posts->push($post); } } class Post extends Entity { }
We can instruct Analogue how these objects are related using these classes :
use Analogue\ORM\EntityMap; class BlogMap extends EntityMap { public function posts(Blog $blog) { return $this->hasMany($blog, Post::class); } } class PostMap extends EntityMap { public function blog(Post $post) { return $this->belongsTo($post, Blog::class); } }
Now we can create related instance of or object and persist them to the database :
$blog = new Blog; $blog->title = "My first blog"; $post = new Post; $post->title->"My first post"; $blog->addPost($post); // Only the blog instance need to explicitely stored; Analogue takes care of synchronizing // related objects behinds the scene. mapper(Blog::class)->store($blog);
Once our objects are persisted into the database, we can query them using the fluent query builder :
$blog = mapper(Blog::class)->first(); echo $blog->posts->first()->title; // 'My first post'
Documentation
Check the Documentation for more details.
Features
- Framework agnostic
- Lazy loading
- Eager Loading
- Timestamps
- Soft Deletes
- Value Objects
- Polymorphic Relationships
- Dynamic Relationships
- Single table inheritance
- Cast entities to Array / Json
- Flexible event system
- Native multiple database connections support
- Extendable via custom database drivers / plugins
Changelog
Version 5.6
- Laravel 5.6 support
- Bring back ability to map DB columns that name are not equals to the name of the attribute.
- Add ability to map DB snake case columns to camel case properties on entities.
Version 5.5
- Laravel 5.5 support
- Pushed miminum requirements to PHP7
- Complete support of Plain PHP objects via reflection based hydration/dehydration
- Improved Lazy-loading proxies.
- New, more flexible Value Object implementation, that can now be defined as
embedsOne()
,embedsMany()
relationships - Embedded value object can now be stored as a mysql JSON field
- Analogue entities can now be instantiated using laravel's
IoC Container
or any PSR-11 compatible container. - Added MongoDB driver.
- Package auto discovery (L5.5)
Version 5.4
- Illuminate 5.4 Compatibility.
- Add Ability to map DB columns that name are not equals to the name of the attribute.
Version 5.3
- Illuminate 5.3 Compatibility.
- Now fully support Single Table Inheritance.
Version 5.1
- Illuminate 5.1 + 5.2 Compatibility.
Version 5.0
- Analogue version now mirrors illuminate version.
Version 2.1.3
- Mutator feature in base Entity class.
- Ability to add entities to a proxy collection without lazyloading it.
Version 2.1
- Package is now framework agnostic.
- Now support any plain object that implements Mappable interface.
- Introducing a MappableTrait for quick implementation.
- Queries can now be run directly on the mapper Object.
- Store/Delete methods now accept a array and collections as argument.
- EntityMap are now autodected when in the same namespace as the entity.
- Base Entity class Supports hidden attributes.
- Many workflow related improvements.
Version 2.0
- Laravel 5 Support.
Documentation
Check the wiki for full documentation.
Licence
This package is licensed under the MIT License.