PHPackages                             innobitlab/php-fly-rrm - 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. [Database &amp; ORM](/categories/database)
4. /
5. innobitlab/php-fly-rrm

ActiveLibrary[Database &amp; ORM](/categories/database)

innobitlab/php-fly-rrm
======================

An entity free 'RRM' to extract structured data from relational DBMS

519PHP

Since Mar 28Pushed 11y ago4 watchersCompare

[ Source](https://github.com/innobitLab/php-fly-rrm)[ Packagist](https://packagist.org/packages/innobitlab/php-fly-rrm)[ RSS](/packages/innobitlab-php-fly-rrm/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

php-fly-rrm
===========

[](#php-fly-rrm)

[![Build Status](https://camo.githubusercontent.com/3efe455b655080eccf76af2ab0cd1e6a5d88f12615f099963cecd1161f8198ca/68747470733a2f2f7472617669732d63692e6f72672f696e6e6f6269744c61622f7068702d666c792d72726d2e706e67)](https://travis-ci.org/innobitLab/php-fly-rrm)[![SensioLabsInsight](https://camo.githubusercontent.com/dc6ea0c481899381e904c2f4a089c54377acb940ee4234353bf3ce54f6a9423a/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f64346264656433612d316464352d346331342d396435342d3062623335666336326435642f6d696e692e706e67)](https://insight.sensiolabs.com/projects/d4bded3a-1dd5-4c14-9d54-0bb35fc62d5d)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/c9a7f60640af46cd5ea27e6b4a762fccabff5ec4c02034262f542c2cdf49915f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f696e6e6f6269744c61622f7068702d666c792d72726d2f6261646765732f7175616c6974792d73636f72652e706e673f733d62666165633239373638386137323931666564393966636332363433663262636434356664333163)](https://scrutinizer-ci.com/g/innobitLab/php-fly-rrm/)[![Code Coverage](https://camo.githubusercontent.com/ca8940145425dcc74dc06a742b950f50d1b350a74d182a3a0b9952f27dcfd165/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f696e6e6f6269744c61622f7068702d666c792d72726d2f6261646765732f636f7665726167652e706e673f733d38303937303562633131616136316439626432613732396163646135306665316637386466393634)](https://scrutinizer-ci.com/g/innobitLab/php-fly-rrm/)[![Total Downloads](https://camo.githubusercontent.com/9961bcbdea9f8dad457517e6cb1c1f72e2770858cfc445749585d7ec0634076c/68747470733a2f2f706f7365722e707567782e6f72672f696e6e6f6269746c61622f7068702d666c792d72726d2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/innobitlab/php-fly-rrm)[![License](https://camo.githubusercontent.com/0595ef7919ca50304f16906b156c548b1826a4127785733ae51899f404ff9302/68747470733a2f2f706f7365722e707567782e6f72672f696e6e6f6269746c61622f7068702d666c792d72726d2f6c6963656e73652e706e67)](https://packagist.org/packages/innobitlab/php-fly-rrm)

An entity free "RRM" (Resource Relational Mapping) to extract structured data from relational DBMS

Why a Resource Relational Mapping
---------------------------------

[](#why-a-resource-relational-mapping)

Because sometimes you need to extract data from a relational DBMS in a **structured** way, and maybe you don't want to add an "heavy" ORM with all his dependencies... or you can't beacuse of a legacy context.

Give me an example
------------------

[](#give-me-an-example)

Ready, set, go!

Suppose we have this type of database:

**users**

idusernamepassword1adminmysecret2james.whitewhitesnow**contracts**

idname1full-time2half-time**banks**

idname1the money free bank2super bank3momeny first bank**employees**

idnamesurnameid\_contractid\_user\_creatorid\_user\_last\_edit1MarioRossi21null2GiuseppeVerdi112**payments**

idvalueid\_employeeid\_bank11200.2312215402331240.2312and you have been asked to export this data in a similar structured json format:

```
{
   "employees":[
      {
         "name":"Mario",
         "surname":"Rossi",
         "contract":{
            "name":"half-time"
         },
         "creator":{
            "username":"admin"
         },
         "last-edit":null,
         "payments":[
            {
               "value":1200.23,
               "bank":{
                  "name":"super bank"
               }
            },
            {
               "value":1240.23,
               "bank":{
                  "name":"super bank"
               }
            }
         ]
      },
      {
         "name":"Giuseppe",
         "surname":"Verdi",
         "contract":{
            "name":"full-time"
         },
         "creator":{
            "username":"admin"
         },
         "last-edit":{
            "username":"james.white"
         },
         "payments":[
            {
               "value":1540,
               "bank":{
                  "name":"money first bank"
               }
            }
         ]
      }
   ]
}
```

and you have been asked to make this export configurable via a similar YAML file:

```
resource:
	alias: 'employees'
	table: 'employees'
	primary-key: 'id'

	fields:
		-
			name: 'name'
		-
			name: 'surname'

	relationships:
		-
			type: 'many-to-one'
			join-column: 'id_contract'

			resource:
				alias: 'contract'
				table: 'contracts'
				primary-key: 'id'

				fields:
					-
						name: 'name'

		-
			type: 'many-to-one'
			join-column: 'id_user_creation'

			resource:
				alias: 'creator'
				table: 'users'
				primary-key: 'id'

				fields:
					-
						name: 'username'

		-
			type: 'many-to-one'
			join-column: 'id_user_last_edit'

			resource:
				alias: 'last-edit'
				table: 'users'
				primary-key: 'id'

				fields:
					-
						name: 'username'

		-
			type: 'one-to-many'
			join-column: 'id_employee'

			resource:
				alias: 'payments'
				table: 'payments'
				primary-key: 'id'

				fields:
					-
						name: 'value'
						type: 'number'

				relationships:
					-
						type: 'many-to-one'
						join-column: 'id_bank'
						primary-key: 'id'

						fields:
							-
								name: 'name'
```

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

[](#installation)

### Composer

[](#composer)

You can install `innobitlab/php-fly-rrm` using [composer](http://getcomposer.org/) Dependency Manager.

If you need information about installing composer:

Add this to your composer.json file:

```
{
	"require": {
    	"innobitlab/php-fly-rrm": "dev-master"
	}
}

```

Usage
-----

[](#usage)

### Without facade (more flexibility)

[](#without-facade-more-flexibility)

```
