PHP Classes
elePHPant
Icontem

EVDB: Store and retrieve objects in MongoDB databases

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Info   View files View files (16)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2010-10-24 (4 years ago) RSS 2.0 feedNot yet rated by the usersTotal: 253 All time: 7,087 This week: 1,168Up
Version License PHP version Categories  
evdb 1.0Custom (specified...5.3PHP 5, Databases
Description Author  

This package can be used to store and retrieve objects in MongoDB databases.

It can read object class schema definitions from files in the YAML format.

It can create, update, delete objects and well find objects by identifier or custom search parameters.

It supports plug-ins classes that may be called before or after updating or deleting an object.

Innovation Award  
PHP Programming Innovation award nominee
November 2010
Number 6
MongoDB is one many existing No SQL databases that has become very popular recently.

For many developers, using No SQL databases is still an odd thing due to many years working with relational databases which usually have a predefined set of tables with a fixed list of fields.

This package provides a solution to work with MongoDB No SQL databases in a way more similar to relational databases, i.e. using a set of tables with fixed set of fields defined in a schema file.

Manuel Lemos
Picture of Bartlomiej Rudzki
Name: Bartlomiej Rudzki <contact>
Classes: 1 package by
Country: Poland Poland
Age: ???
All time rank: 357484 in Poland Poland
Week rank: 1504 Up43 in Poland Poland Up
Innovation award
Innovation award
Nominee: 1x

Details provided by the author  
Key features of EVDB:

*****
You can define "classes" or "types" of objects which determine:
  - a collection where the object of a given class is stored in MongoDB (like a table in MySQL)
  - a default set of properties
[Example]:
Person:
  name: string(Default Name)
  age: integer(18)
[/Example]


*****
A property can be either of a built-in type (boolean, string, integer, float; with or without the default value) or any other previously defined type (as an embedded property or a reference pointer)
[Example]
Address:
  city: string
  street: string
  house_number: string
Place:
  name: string
  address: *Address
User:
  login: string
  password: string
  address: *Address # stored inside the User object, independent from any other Address objects
  favourite_place: &Place # reference pointer to the actual Place object
[/Example]


*****
Arrays can be of defined or undefined length
[Example]
Actor:
  movies: string[]
  top_3_awards: string[3]
[/Example]


*****
A type can inherit from 0 or more previously defined types
[Example]
%Person:         # "%" defines a class as abstract, see below
  name: string(Default Name)
Actor < Person:
  movies: string[]
Bodybuilder < Person:
  lift_weight: float(123.4)
Politician < Person:
  party: string
  elected_on: integer

# The fun part
ArnoldSchwarzenegger < [Actor, Bodybuilder, Politician]:
  name: string(!!Arnold Schwarzenegger)     # "!!" defines the casting rule, see below
[/Example]

So, an object of ArnoldSchwarzenegger type will have the following default properties:
  - name (string, "Arnold Schwarzenegger" value by default)
  - movies (array)
  - lift_weight (float, 123.4 value by default)
  - party (string)
  - elected_on (integer)

and will be stored in the "ArnoldSchwarzenegger" collection.

Creating a new object is really simple:
$actor = EVDB::create('Actor');


*****
Objects casting into another type can be done by writing something like:

$actor = EVDB::create('Actor'); // see Actor type in the example above
$politican = $actor->cast('Politician'); // it will have all default Politician properties added (and overwritten, if defined in the casting rules, see the name property of ArnoldSchwarzenegger type above for an example of the overwriting casting rule)

Object after casting will be saved in the collection of its new type.


*****
A class can be defined as abstract, meaning that it only acts as a property set definition. An object of the abstract type cannot be created nor can an object be cast into the abstract type.


*****
Plugins for specific EVDB object actions can be added
[Example] (EVDBUserPlugin <- customizes the "User" type)
// example of an event listener

public static function onBeforeSave(EVDBObject $obj)
{
   self::ensureUnique($obj, 'login'); // doesn't allow storing the User object with the same value of "login" property
   $obj->password = self::encode($obj->password); // to prevent storing the open-text passwords in the database
   return TRUE; // if omitted, the object will not be saved!
}

// example of a "magic" function
public static function getName($obj)
{
  return $obj->first_name.' '.$obj->last_name;
}
[/Example]

Collection/type plugins are automatically loaded by the EVDB, so to extend the functionality of a specific type defined in the EVDB schema, you just add a new file into the specific plugin directory (lib/DB/plugins) and the magic kicks in ;)

*****
Queries may be performed using some more "magic" methods
[Example]
$politicians = EVDB::find5PoliticiansByParty('Democrats'); // returns an array of up to 5 "Politician" objects with the property party equals to "Democrats";
[/Example]

Note: None of the "magic" methods is specified in the code, but if there's a "Politician" type with a "party" property, the methods like EVDB::findPoliticianByParty(), EVDB::findAllPoliticiansByParty(), EVDB::find123PoliticiansByParty(), etc. all can be used in the code.
  Files folder image Files  
File Role Description
Files folder imageplugins (1 file)
Plain text file EVDB.class.php Class Main class of the package
Plain text file EVDBException.class.php Class Exception class used in EVDB package
Plain text file EVDBObject.class.php Class Single EVDB object
Plain text file EVDBPlugin.class.php Class Abstract class for custom functionality of EVDB types
Plain text file EVDBYaml.class.php Class Converts EVDB schema files into PHP arrays
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENSE Lic. License file
Accessible without login Plain text file LICENSE.SF Lic. License file for sfYaml package
Accessible without login Plain text file README Doc. Readme file
Accessible without login Plain text file schema.evdb Data Example EVDB schema
Accessible without login Plain text file schema.evdb.lat69m.php Aux. Example of compiled EVDB schema
Plain text file sfYaml.class.php Class sfYaml offers convenience methods to load and dump YAML
Plain text file sfYamlDumper.class.php Class sfYamlDumper dumps PHP variables to YAML strings
Plain text file sfYamlInline.class.php Class sfYamlInline implements a YAML parser/dumper for the YAML inline syntax
Plain text file sfYamlParser.class.php Class sfYamlParser parses YAML strings to convert them to PHP arrays

  Files folder image Files  /  plugins  
File Role Description
  Plain text file EVDBUserPlugin.class.php Class Plugin for "User" type

 Version Control Unique User Downloads Download Rankings  
 0%Total:253All time:7,087
 This week:0This week:1,168Up