2017 © Pedro Peláez
 

library maphper-loader

image

solleer/maphper-loader

  • Wednesday, July 18, 2018
  • by solleer
  • Repository
  • 1 Watchers
  • 1 Stars
  • 33 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 43 % Grown

The README.md

Maphper-Loader

An Easy Way to Create Maphper Instances, (*1)

Dependencies

This library has dependencies on Dice and Maphper with can both be found at Level-2, (*2)

Purpose

This project was started to make it easier to create instances of the Maphper class found at Level-2 with little configuration Each Loader just requires a file to be passed to it and you can call the getMaphper method to get the maphper you want, (*3)

Use

Lets take this first example from Maphper's README, (*4)

$pdo = new PDO('mysql:dbname=maphpertest;host=127.0.0.1', 'username', 'password');
$blogSource = new \Maphper\DataSource\Database($pdo, 'blog', 'id');
$blogs = new \Maphper\Maphper($blogSource);

This can be changed to have a file called config.json with the maphper config info config.json, (*5)

{
    "blogs" : {
        "type" : "database",
        "table" : "blog",
        "primaryKey" : "id"
    }
}

And then the php becomes, (*6)

$loader = new \MaphperLoader\Json("config.json", new \Dice\Dice());
$blogs = $loader->getMaphper("blogs");

MaphperLoader uses dice to handle dependencies such as PDO. You just need to add a rule for PDO and you are all set., (*7)

Relations

MaphperLoader supports all Maphper relationships including: One, Many, and ManyMany, (*8)

One

Here is some sample JSON for a One Relationship, (*9)

{
    "blog" : {
        "type" : "database",
        "table" : "blog",
        "primaryKey" : "id",
        "relations" : [
            {
                "name" : "author",
                "to" : "author",
                "type" : "one",
                "localKey" : "authorId",
                "foreignKey" : "id"
            }
        ]
    },
    "author" : {
        "type" : "database",
        "table" : "author",
        "primaryKey" : "id"
    }
}

A one relationship has the following properties * name - the name of the relation when being accessed * to - the maphper being connected to * type - the type of relation * localKey - the key in the current Maphper being linked from * foreignKey - the key in the other Maphper being linker to, (*10)

Many

{
    "blog" : {
        "type" : "database",
        "table" : "blog",
        "primaryKey" : "id"
    },
    "author" : {
        "type" : "database",
        "table" : "author",
        "primaryKey" : "id",
        "relations" : [
            {
                "name" : "blogs",
                "to" : "blog",
                "type" : "many",
                "localKey" : "id",
                "foreignKey" : "authorId"
            }
        ]
    }
}

A many relation has the same properties of a One relation except the type is set to many, (*11)

ManyMany

{
    "actors" : {
        "type" : "database",
        "table" : "actor",
        "primaryKey" : "aid",
        "relations" : [
            {
                "name" : "movies",
                "to" : "movies",
                "type" : "ManyMany",
                "intermediate" : "cast",
                "intermediateKey" : "movieId",
                "foreignKey" : "mid"
            }
        ]
    },
    "movies" : {
        "type" : "database",
        "table" : "movie",
        "primaryKey" : "mid",
        "relations" : [
            {
                "name" : "actors",
                "to" : "actors",
                "type" : "ManyMany",
                "intermediate" : "cast",
                "intermediateKey" : "actorId",
                "foreignKey" : "aid"
            }
        ]
    },
    "cast" : {
        "type" : "database",
        "table" : "cast",
        "primaryKey" : ["movieId", "actorId"]
    }
}

A ManyMany relation must have an intermediate Maphper to connect the two Maphpers Both Maphpers being connected must also have the ManyMany relationship defined In the above example that is the cast Maphper, (*12)

The ManyMany Relation has the following properties * name - the name of the relation when being accessed * to - the Maphper being connected to * type - the type of relation, in this case "ManyMany" * intermediate - the intermediate Maphper * intermediateKey - the key of the column in the intermediate maphper that connects to the other Maphper * foreignKey - must be the primary key of the other Maphper, (*13)

The Versions

18/07 2018

dev-master

9999999-dev

  Sources   Download

The Requires

 

18/07 2018

v2.0.0

2.0.0.0

  Sources   Download

The Requires

 

18/07 2018
25/03 2018
03/01 2018
25/04 2017