This Library is inspired by Doma(https://github.com/domaframework/doma).
php >= 5.5.x
Omelet can be installed with Composer.
Define the following requirement in your composer.json file:
{
"require": {
"ritalin/omelet": "*"
}
}
-
Define Dao (Data Access Object) interface.
- DAO method is need to describe an annotation comment to distingish database command/query.
use \Omelet\Annotation\Select; interface TodoDao { /** * @Select */ function listAll(); }
-
Prepare sql file of same name as method. sql file path depends on namespace for dao interface.
-- listAll.sql select * from todo order by id
-
Instanciate \Omelet\Builder\DaoBuilderContext .
- At least, need to a connection string to database as configuration.
$config = \Omelet\Builder\Configuration; $config->connectionString = "driver=pdo_sqlite&path=/path/to/todo.sqlite3"; $context = new \Omelet\Builder\DaoBuilderContext($config);
-
Generate Dao concrete class.
$context->build(Todo::class);
-
Use Dao.
- A Dao concrete class name note that 'Impl' is suffixed to interface name by default.
$conn = \Doctrine\DBAL\DriverManager->getConnection($context->connectionString()); $dao = new TodoImpl($conn, $context); $rows = $dao->listAll();
Please see ritalin/omelet-bear-example implemented with BEAR.Sunday (https://github.com/bearsunday/BEAR.Sunday) framework.
now work in progress ...