monomelodies / ornament
PHP5 ORM toolkit
Requires
- php: >=5.4
- zeptech/annotations: ^1.1
Requires (Dev)
- phpunit/dbunit: >=1.2
- phpunit/phpunit: >=4.0
Suggests
- monomelodies/dabble: PDO-based database abstraction layer
- monomelodies/dormant: Dabble-specific Ornament adapter
- monomelodies/formulaic: PHP5 OO-forms with data binding for (Ornament) models
This package is auto-updated.
Last update: 2024-12-16 05:57:24 UTC
README
PHP5 ORM toolkit
ORM is a fickle beast. Many libraries (e.g. Propel, Doctrine, Eloquent etc)
assume your database should correspond to your models. This is simply not the
case; models contain business logic and may, may not or may in part refer to
database tables, NoSQL databases, flat files, an external API or whatever. The
point is: the models shouldn't care, and there should be no "conventional"
mapping through their names. (A common example would be a model of pages in
multiple languages, where the data might be stored in a page
table and a
page_i18n
table for the language-specific data.)
Also, the use of extensive and/or complicated config files sucks. (XML? This is 2015, people!)
Installation
Composer (recommended)
Add "monomelodies/ornament" to your composer.json
requirements:
$ composer require monomelodies/ornament
Manual installation
- Get the code;
- Clone the repository, e.g. from GitHub;
- Download the ZIP (e.g. from Github) and extract.
- Make your project recognize Ornament:
- Register
/path/to/ornament/src
for the namespaceOrnament\\
in your PSR-4 autoloader (recommended); - Alternatively, manually
include
the files you need.
- Register
Basic usage
Ornament models (or "entities" if you're used to Doctrine-speak) are really nothing more than vanilla PHP classes; there is no need to extend any base object of sorts (since you might want to do that in your own framework!).
Ornament is a toolkit, so it supplies a number of Trait
s one can use
to
extend your models' behaviour beyond the ordinary.
The most basic implementation would look as follows:
<?php use Ornament\Model; use Ornament\Adapter\Pdo; class MyModel { use Model; // Public properties on a Model are considered "handleable" by Ornament: public $id; public $name; public $value; public function __construct() { $this->addAdapter(new Pdo($GLOBALS['database'])); } }