PHPackages                             ticaje/m2-persistence - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ticaje/m2-persistence

ActiveMagento2-module

ticaje/m2-persistence
=====================

Middleware to Magento 2 persistency

1.1.3(4y ago)5124OSL-3.0PHPPHP ^7.0

Since Nov 26Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/M-Contributions/Persistence-Isolation-Module)[ Packagist](https://packagist.org/packages/ticaje/m2-persistence)[ RSS](/packages/ticaje-m2-persistence/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (8)Versions (11)Used By (0)

This module is an abstraction to Magento 2 persistence module, it acts as an API that provides a high level policy to connect a third party module to Magento.
==============================================================================================================================================================

[](#this-module-is-an-abstraction-to-magento-2-persistence-module-it-acts-as-an-api-that-provides-a-high-level-policy-to-connect-a-third-party-module-to-magento)

[![GPLv3 License](https://camo.githubusercontent.com/19f3b8cdb6c4ca7671e1af3240e94eb087c2b0c1181a3357d8381af53c9d40cb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d47504c76332d6d6172626c652e737667)](https://www.gnu.org/licenses/gpl-3.0.en.html)[![Latest Version on Packagist](https://camo.githubusercontent.com/f9a02d0f8602f041561e861bcc40bc9e15635329882884bc61f570adf9d26f62/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746963616a652f6d322d70657273697374656e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ticaje/m2-persistence)[![Quality Score](https://camo.githubusercontent.com/aec8c22da11857d05769289784c64b8bc2be6ae70d29104d317ac10c6616fa51/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4d2d436f6e747269627574696f6e732f50657273697374656e63792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/M-Contributions/Persistency)[![Total Downloads](https://camo.githubusercontent.com/d5c36ff388202a1cf78de96300e28e62102dc2b21e5e0e39e239b033d764f3e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746963616a652f6d322d70657273697374656e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ticaje/m2-persistence)[![Author](https://camo.githubusercontent.com/3c3154e7d1e6e1d3c45389165493e28fc0279eced5a2b180bc66058f847196ff/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f48424c61746572616c2e636f6d2d2532333032313133613f7374796c653d6c6162656c436f6c6f723d6c6967687467726579)](https://hblateral.com)

Preface
-------

[](#preface)

Magento framework is a great tool for building e-commerce solutions. It did spring out its version 2 some while ago and with it, its quality jumped up in a tremendous way. Even so, i wanted to provide certain facilities to developers that make live easier when coding in Magento and repetitive tasks show up.

I must say that, and perhaps a disclaimer is lurking around, this is a series of extensions developed under S.O.L.I.D and other OO design principles so we'd introduce some standardization in the way we develop in Magento since its designers took this way when they decided to walk a better path for the architecture of the framework. In short, S.O.L.I.D principles and good design practices dwell all over Magento ecosystem.

Installation
------------

[](#installation)

You can install this package using composer(the only way i recommend)

```
composer require ticaje/m2-persistence
```

What's the fuzz about this module
---------------------------------

[](#whats-the-fuzz-about-this-module)

This module is about Persistence. Magento 2 came out with a profound redesign of the framework from many standpoints, it introduces modern(perhaps not so new) OO Design techniques but if you look closer, when it comes to persistence, not greater changes have developed, it continues to shape the same ORM(if it ever had something close to an ORM) structure, the typical Model/Resource approach remains the same.

### Problem this module solves.

[](#problem-this-module-solves)

It's a fact that the same boiler-plating needs to be accomplished when developer needs to create a single Entity(in Magento entities are Models). This is way awkward because a bunch of classes(model, resources and collection) need to be created in order to create a single Entity. It turns out that Magento provides the tools to avoid developer going through this over and over again every time a single Entity comes into play, not to talk about creating more complex Entity relations.

This module actually refactors the way Magento does this, so developer can focus on defining proper entities and their relationships in a declarative way simply by means of DIC a.k.a di.xml.

I will provide an example of this since an image is worth a thousand words.

### A simple example

[](#a-simple-example)

Suppose you need to add a specific table to Magento because of your business model. The table name is gonna be "example\_table\_name"; the details of the schema we're not gonna discuss here cause it continues to be same, this module does not interfere on such a grounds. Once developer has defined the schema(through traditional Magento channels) the only thing left to complete the classes required to glue schema with ORM is to define the following xml within module's di.xml file.

```

            example_table_name
            entity_id

            Vendor\Module\Model\Resource\Example
            example_table_name

            Vendor\Module\Model\ExampleInterface::KEY_ID
            Vendor\Module\Model\Example
            Vendor\Module\Model\Example\Resource

```

Out of some inconsistency on wiring up the framework, we must create the concrete Model class that inherits from our Base Entity class. We did try, just like with resource and collection, to define it as a virtual type but there is no way to achieve the instantiation of the object, any help will be appreciated.

The Model Class for our: Example.

```
