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('id'),
new StringColumn('name'),
new StringColumn('email'),
new BoolColumn('isActive'),
new DateTimeColumn('createdAt')
];
}
// Getters/Setters...
}
// Get user by ID
$user = $entityManager->getRepository(User::class)->find(1);
// Filtered query
$users = $entityManager->getRepository(User::class)
->findBy()
->where('isActive', true)
->orderBy('name', 'ASC')
->limit(10)
->toArray();
$newUser = new User();
$newUser->setName('Jean Dupont')
->setEmail('[email protected]');
$entityManager->persist($newUser);
$entityManager->flush();
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...
}
// Récupérer un utilisateur par ID
$user = $entityManager->getRepository(User::class)->find(1);
// Requête avec filtres
$users = $entityManager->getRepository(User::class)
->findBy()
->where('isActive', true)
->orderBy('name', 'ASC')
->limit(10)
->toArray();
$newUser = new User();
$newUser->setName('Jean Dupont')
->setEmail('[email protected]');
$entityManager->persist($newUser);
$entityManager->flush();