atijust / mappa
A simple object mapper for PDO
dev-master
2015-09-15 15:29 UTC
Requires
- php: >=5.5
- doctrine/inflector: ~1.0
Requires (Dev)
- phpunit/phpunit: ~4.0
This package is not auto-updated.
Last update: 2024-11-09 18:17:01 UTC
README
Mappa is a simple object mapper for PDO.
$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, [Mappa\Statement::class, [new Mappa\Hydrator()]]); $stmt = $pdo->prepare("SELECT *, books.name || ' - ' || categories.name AS title FROM books JOIN categories ON categories.id = books.category_id WHERE books.id = ?"); echo get_class($stmt); // Mappa\Statement $stmt->execute([1]); var_export($stmt->hydrate([Book::class, Category::class])); // array ( // 'books' => // Book::__set_state(array( // 'id' => '1', // 'name' => 'B01', // 'category_id' => '1', // )), // 'categories' => // Category::__set_state(array( // 'id' => '1', // 'name' => 'C01', // )), // '' => // stdClass::__set_state(array( // 'title' => 'B01 - C01', // )), // )
Mappa works with PHP 5.5 or later.
TODO
- Improve error handling
- Pass custom arguments to entity constructor