You can install TDBM 5 in any framework that can load service-providers compatible with the container-interop/service-provider interface.
In this document, we will describe integration of TDBM 5 with Simplex. Your mileage may vary based on the container you are using.
{
"autoload": {
"psr-4": {
"App\\": "src/"
}
},
"require": {
"php": ">=7.2",
"mnapoli/simplex": "^0.4.1",
"thecodingmachine/tdbm-universal-provider": "^5",
"thecodingmachine/discovery": "^1.2"
},
"minimum-stability": "dev",
"prefer-stable": true
}
The thecodingmachine/tdbm-universal-provider package has dependencies on a number of other service providers that will be loaded automatically:
vendor/bin/app_console
)Then let's create a container.php
file at the root of your project and let's fill it with all service-providers:
container.php
<?php
use Simplex\Container;
use TheCodingMachine\Discovery\Discovery;
use Interop\Container\ServiceProviderInterface;
$serviceProviders = [];
foreach (Discovery::getInstance()->get(ServiceProviderInterface::class) as $serviceProviderName)
{
$serviceProviders[] = new $serviceProviderName();
}
$container = new Container($serviceProviders);
// The settings for the database must be stored in the container.
// See https://github.com/thecodingmachine/dbal-universal-module for more information
$container->set('dbal.dbname', 'my_database');
$container->set('dbal.host', 'localhost');
$container->set('dbal.user', 'root');
$container->set('dbal.password', '');
$container->set('dbal.port', 3306);
return $container;
When installation is done, you need to generate DAOs and beans from your data model.
Run the following command:
vendor/bin/app_console tdbm:generate
The TDBM service provider will create one service per DAO.
The service name is the fully qualified class name of the DAO.
For instance:
App\Daos\UserDao
=> $container->get('App\\Daos\\UserDao')
We strongly recommend using TDBM along a migration tool. For instance, Doctrine migrations. Since you use container-interop/service-providers, you can benefit from the Doctrine Migrations universal module.
Let's now learn how to access the database.
Found a typo? Something is wrong in this documentation? Just fork and edit it!