当前位置: 首页 > 软件库 > 数据库相关 > >

analogue

Analogue ORM : Data Mapper ORM for Laravel/PHP
授权协议 MIT License
开发语言 PHP
所属分类 数据库相关
软件类型 开源软件
地区 不详
投 递 者 喻渊
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

(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.

 相关资料
  • 问题内容: 我正在尝试使用jQuery的功能上传文件,但未获得任何输出。有人请帮我解决这个问题。我不知道此脚本是否正确。我的脚本是: 我还需要帮助,使用jQuery从文件上传字段获取数据。 问题答案: AJAX不支持文件上传。有些插件如ajaxfileupload基本上会创建一个隐藏的表单并动态上传文件。

  • 问题内容: 当前,我正在运行一个查询,该查询将显示“产品”表和与产品相关联的“用户”的所有内容。它打印在桌子上。我想创建一个按钮,显示所有记录。请注意,我只能只查看选定的记录。.我将如何处理? 因此,应该为每个返回的记录显示一个按钮。当我单击此按钮时,将出现另一个窗口,该窗口显示了全部内容(仅针对此记录)以及与之相关的用户。该按钮如何知道与其关联的记录。 问题答案: 这将带您到另一个页面。使用ge

  • 问题内容: 我在通过localhost上的PHP脚本选择数据库时遇到麻烦。 我100%确定数据库名称拼写正确,并且实际上它很好地出现在phpmyAdmin上,并且仅当我尝试通过在本地主机上运行PHP脚本尝试连接到它时,它才会显示以下错误: 我的PHP代码在这里: 我已经阅读了成千上万个论坛,并且我将尽一切努力。但是不知道这里出了什么问题吗? 一件有趣的事情是,如果我在PHP脚本中将数据库名称更改为

  • 问题内容: 这是一个时间表,它的作用是显示前一天的时间表以及谁预定了每个时段(这是针对广播电台的。) 目前,它显示谁按时间顺序预订了每个时段,但是我想说每个结果旁边的时间。查询输出24行(从午夜到23:00),我想说的是每个插槽旁边的(00:00,01:00,02:00,03:00… 21:00,22 :00,依此类推。) 这是我当前的代码: 你能帮我吗? 问题答案: 我认为我们都在努力解决一个非

  • 问题内容: 精通PHP但学习Java的人应该知道的PHP与Java之间的主要区别是什么? 编辑: 我的意思是这些语言的语法上的差异,即它们的数据类型,它们如何处理数组和引用变量等等:) 问题答案: 这不是一个详尽的清单,我是PHP开发人员,前一段时间做过Java之旅,所以做了Caveat Emptor。 Java中的每个变量都必须以数据类型开头。这包括基本类型,例如boolean,int,doub

  • 问题内容: 我在JavaScript中输入了一个绝对URL,并为window.location进行了硬编码。 我不想每次测试应用程序时都必须更改此设置。在PHP中,我可以通过测试$ _SERVER [“ HTTP_HOST”]变量来找出我所在的服务器,然后进行相应的调整来处理此问题。但是,我不太熟悉Java,想知道它是否具有类似的方法?或者,即使JavaScript也有类似的方法? 代码如下: 我

  • 问题内容: 在PHP中构建MVC框架后,我遇到了一个问题,可以使用Java样式泛型轻松解决。抽象的Controller类可能看起来像这样: 在某些情况下,Controller类的子类只能接受Model的子类。例如,ExtendedController应该只将ReOrderableModel接受到addModel方法中,因为它提供了ExtendedController需要访问的reOrder()方法

  • 问题内容: 我一直在尝试使用AES-128 CBC解密字符串,该字符串最初是使用JAVA AES加密加密的。在Java中,使用PKCS7填充。而且我尝试使用类似的PHP代码进行加密和解密。但是我得到了不同的结果。 我的Java代码 以及我正在使用的等效PHP代码。 在Java中 纯文本= 123456 密码文本= tpyxISJ83dqEs3uw8bN / + w =​​= 在PHP中 纯文本=