2017 © Pedro Peláez
 

library noorm

No ORM storage of PHP object

image

webd/noorm

No ORM storage of PHP object

  • Wednesday, September 6, 2017
  • by tdebatty
  • Repository
  • 1 Watchers
  • 1 Stars
  • 44 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

PHP-Noorm

Build Status Latest Stable Version, (*1)

No-ORM storage of PHP object., (*2)

PHP-Noorm makes it easy to persist your PHP object, without the overhead of Object-Relation Mapping (ORM)., (*3)

Installation

Install the latest version using composer:, (*4)

$ composer require webd/noorm

Quickstart

First, load composer, and define a directory where your objects can be saved (it has to be writable)., (*5)

require_once __DIR__  . "/../vendor/autoload.php";
use noorm\Persistent;

// Indicate where to save data
Persistent::SetDirectory("/tmp/noorm-example");

Define the classes that you want to persist. They have to extend the class \noorm\Persitent., (*6)

class Client extends Persistent {

  public $name = "";
  private $val;

  /**
   * Use annotations to indicate $items is a many-to-many relation to class Item
   * @target Item
   * @var \noorm\ManyToManyRelation
   */
  public $items;

  public function SetName($name) {
    $this->name = $name;
    return $this;
  }

  public function GetVal() {
    return $this->val;
  }

  public function SetVal($val) {
    $this->val = $val;
    return $this;
  }
}

class Item extends Persistent {

  public $name = "";

  /**
   * Use annotations to indicate $clients is a many-to-many relation to Client
   * @target Client
   * @var \noorm\ManyToManyRelation
   */
  public $clients;
}

You can now create objects and save them on disk., (*7)

// Create a new object and save it to disk
$client = new Client();
$client->name = "C1";
$client->Save();

The static method All() returns a \noorm\Dataset representing all the saved objects of this class. You can use this dataset to filter, sort or list your objects., (*8)

// Show all clients
/* @var $client Client */
foreach (Client::All()->Collect() as $client) {
  echo $client->name . " : ";
  echo $client->items->Get()->Count() . " items\n";
}

PHP-Noorm also manages many-to-many relations for you. These are described using annotations in your class definition., (*9)

// Create a new item
$item = new Item();
$item->name = "I";
$item->Save();

// Add this item to the first client
$client = Client::All()->First();
$client->items->Add($item);

Known bugs and limitations

These are planned improvements: - There can be only one many-to-many relation between two classes; - You cannot define a many-to-many relation between a class and itself; - All() will eagerly load all objects, which is memory expensive., (*10)

The Versions

06/09 2017

dev-master

9999999-dev

No ORM storage of PHP object

  Sources   Download

The Requires

 

The Development Requires

10/09 2015

0.2

0.2.0.0

No ORM storage of PHP object

  Sources   Download

The Requires

 

The Development Requires

10/09 2015

v0.1

0.1.0.0

No ORM storage of PHP object

  Sources   Download

The Requires

 

The Development Requires