1. Go to this page and download the library: Download phpdevcommunity/paper-orm library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use PaperORM\Entity\EntityInterface;
use PaperORM\Mapping\{PrimaryKeyColumn, StringColumn, BoolColumn, DateTimeColumn, OneToMany, JoinColumn};
class User implements EntityInterface
{
private ?int $id = null;
private string $name;
private string $email;
private bool $isActive = true;
private \DateTime $createdAt;
public static function getTableName(): string
{
return 'users';
}
public static function columnsMapping(): array
{
return [
(new PrimaryKeyColumn())->bindProperty('id'),
(new StringColumn())->bindProperty('name'),
(new StringColumn())->bindProperty('email'),
(new BoolColumn('is_active'))->bindProperty('isActive'), // 'is_active' is the column name
(new DateTimeColumn('created_at'))->bindProperty('createdAt') // 'created_at' is the column name
];
}
// Getters/Setters...
}
PhpDevCommunity\PaperORM\EntityManager;
// Configuration de base (MySQL, SQLite)
$entityManager = new EntityManager([
'driver' => 'sqlite',
'user' => null,
'password' => null,
'memory' => true,
]);
use PaperORM\Entity\EntityInterface;
use PaperORM\Mapping\{PrimaryKeyColumn, StringColumn, BoolColumn, DateTimeColumn, OneToMany, JoinColumn};
class User implements EntityInterface
{
private ?int $id = null;
private string $name;
private string $email;
private bool $isActive = true;
private \DateTime $createdAt;
public static function getTableName(): string
{
return 'users';
}
public static function columnsMapping(): array
{
return [
new PrimaryKeyColumn('id'),
new StringColumn('name'),
new StringColumn('email'),
new BoolColumn('isActive'),
new DateTimeColumn('createdAt')
];
}
// Getters/Setters...
}