2017 © Pedro Peláez
 

project casket

A compact PHP Object Relational Management library

image

dragonmantank/casket

A compact PHP Object Relational Management library

  • Thursday, November 27, 2014
  • by dragonmantank
  • Repository
  • 1 Watchers
  • 1 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Casket

Last Updated: 2014-05-02, Chris Tankersley, (*1)

Build Status, (*2)

Scrutinizer Code Quality, (*3)

Casket is a compact Object Relational Management library for PHP. It allows for quick prototyping and management of objects that need to be persisted. Casket is a fork of PhpORM, an older ORM I created. You can find it at https://github.com/dragonmantank/PhpORM, (*4)

Since persistence doesn't always mean to a database, it can easily be extended to support different persistance layers., (*5)

This version uses Aura.SQL to provide support for any database provider supported by Aura.SQL. All you need is PDO!, (*6)

Parts of Casket

  • Entities - Singular Objects
  • Repositories - Allows searching and retrieving
  • Storage - Ways to access different data stores

Entities

Entities are the 'things' in the application. If you are building a pet website, Entities would be something like a 'Animal', 'AdoptionAgency', 'Address'. Entities are a single object that needs to be persisted, more normally in a database., (*7)

An Entity would look like this:, (*8)

Class Animal
{
    public $id;           // Database ID
    public $type;         // Type of animal
    public $inductionDate // Date Animal came to Shelter
    public $name;         // Name of the animal
    public $shelter_id    // Foreign key of the animal shelter
}

You could then access the entity like this:, (*9)

$animal = new Animal();
$animal->type = 'Cat';
$animal->inductionDate = time();
$animalRepository->save($animal);

Repositories

Repositories are the recommended way to get information out of the data storage. We've done away with the need for using direct Data Access Objects. Repositories are generally set around a specific Entity and work only with that Entity. This allows the Repository to automatically generate Entities based on the data sources., (*10)

For database-backed persistance, a basic repository needs no specific class and can utilize the shipped DBRepository class. It requires just a storage mechanism and a prototype object to base it's results on., (*11)

// $storage is a pre-created connection to your data store, see the Storage section
$animalRepo = new Casket\Repository\DBRepository($storage, new Animal());

This repository will return Animal entities (or collections of Animal entities):, (*12)

$cats = $animalRepo->fetchAllBy(array('type' => 'cat'));  // Return all the cats
$dog = $repo->find($dogId); // Find the specified object by primary key
$fluffy = $repo->findBy(array('name' => 'Fluffy')); // Search by something other than primary key

Storage

Storage systems provide a standard way to interact with some sort of storage system, be it a database or an API. Casket ships with a PDO-based storage system that utilizes Aura.SQL and Aura.SQL-Query to provide access to many different database backends., (*13)

For the AuraExtendedPdo storage system, you just need to invoke it with an AuraExtendedPdo object and a QueryFactory from Aura.SQL-Query., (*14)

$storage = new Casket\Storage\AuraExtendedPdo($extendedPdo, new Aura\SqlQuery\QueryFactory('mysql'));

You can then use the storage with your Repositories so they can access data:, (*15)

$animalRepo = new Casket\Repository\DBRepository($storage, new Animal());

The Versions

27/11 2014

dev-master

9999999-dev

A compact PHP Object Relational Management library

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

orm database