PaperORM is a PHP ORM designed for projects requiring a lightweight yet performant object-relational mapping solution.
|
|
1 maand geleden | |
|---|---|---|
| functions | 7 maanden geleden | |
| src | 1 maand geleden | |
| tests | 1 maand geleden | |
| .env.test.dist | 1 maand geleden | |
| .gitignore | 1 maand geleden | |
| LICENSE | 7 maanden geleden | |
| README.md | 1 maand geleden | |
| composer.json | 7 maanden geleden |
PaperORM is a PHP ORM designed for projects requiring a lightweight yet performant object-relational mapping solution.
PaperORM is a PHP ORM designed for projects requiring a lightweight yet performant object-relational mapping solution. Specifically developed for PHP 7.4 and above, it positions itself as a lighter alternative to existing solutions.
At just 3MB compared to Doctrine's 75MB with dependencies, PaperORM offers the essential features of a modern ORM while maintaining a minimal footprint. It includes:
PaperORM is available via Composer and installs in seconds.
composer require phpdevcommunity/paper-orm:1.0.3-alpha
Create a simple configuration file to connect PaperORM to your database:
<?php
require_once 'vendor/autoload.php';
use PhpDevCommunity\PaperORM\EntityManager;
// Basic configuration SQLite
$entityManager = new EntityManager([
'driver' => 'sqlite',
'user' => null,
'password' => null,
'memory' => true,
]);
// Basic configuration MySQL/Mariadb
$entityManager = new EntityManager([
'driver' => 'mariadb',
'host' => '127.0.0.1',
'port' => 3306,
'dbname' => 'paper_orm_test',
'user' => 'root',
'password' => 'root',
'charset' => 'utf8mb4',
]);
✅ PaperORM is now ready to use!
Note: PDO and corresponding database extensions must be enabled (pdo_mysql, pdo_sqlite, etc.).
Note: The
repositoryattribute/method is optional. If none is defined, a dummy repository will be automatically generated.
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...
}
use PaperORM\Entity\EntityInterface;
use PaperORM\Mapping\{PrimaryKeyColumn, StringColumn, BoolColumn, DateTimeColumn, OneToMany, JoinColumn};
#[Entity(table : 'user', repository : null)]
class User implements EntityInterface
{
#[PrimaryKeyColumn]
private ?int $id = null;
#[StringColumn]
private string $name;
#[StringColumn]
private string $email;
#[BoolColumn(name: 'is_active')]
private bool $isActive = true;
#[DateTimeColumn(name: 'created_at')]
private \DateTime $createdAt;
// Getters/Setters...
}
Fetching Entities:
// 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();
Insert/Update:
$newUser = new User();
$newUser->setName('Jean Dupont')
->setEmail('jean@example.com');
$entityManager->persist($newUser);
$entityManager->flush();
Delete:
$user = $entityManager->getRepository(User::class)->find(1);
$entityManager->remove($user);
$entityManager->flush();
// OneToMany relationship
class Article
{
// IF PHP >= 8
#[\PhpDevCommunity\PaperORM\Mapping\OneToMany(Comment::class, 'article')]
private \PhpDevCommunity\PaperORM\Collection\ObjectStorage $comments;
public function __construct() {
$this->comments = new ObjectStorage();
}
// ...
public static function columnsMapping(): array
{
return [
new OneToMany('comments', Comment::class, 'article')
];
}
}
// Fetch with join
$articleWithComments = $entityManager->getRepository(Article::class)
->find(1)
->with('comments')
->toObject();
// Associative array
$userArray = $repository->find(1)->toArray();
// Entity object
$userObject = $repository->find(1)->toObject();
// Object collection
$activeUsers = $repository->findBy()
->where('isActive', true)
->toObject();
PaperORM offers a simple API while covering the essential needs of a modern ORM.
PaperORM is currently in beta version and actively evolving. We invite interested developers to:
If you encounter issues, open a GitHub issue detailing:
Ideas for:
Complete documentation is being written. You can:
Note: This version is stable for development use but requires additional testing for production.
Active development continues - stay tuned for updates!
PaperORM est un ORM PHP conçu pour les projets qui nécessitent une solution de mapping objet-relationnel légère et performante. Développé spécifiquement pour PHP 7.4 et versions ultérieures, il se positionne comme une alternative plus légère aux solutions existantes.
Avec seulement 3Mo contre 75Mo pour Doctrine avec ses dépendances, PaperORM propose les fonctionnalités essentielles d'un ORM moderne tout en conservant une empreinte minimale. Il intègre notamment :
PaperORM est disponible via Composer et s'installe en quelques secondes.
composer require phpdevcommunity/paper-orm:1.0.3-alpha
Créez un fichier de configuration simple pour connecter PaperORM à votre base de données :
<?php
require_once 'vendor/autoload.php';
use PhpDevCommunity\PaperORM\EntityManager;
// Basic configuration SQLite
$entityManager = new EntityManager([
'driver' => 'sqlite',
'user' => null,
'password' => null,
'memory' => true,
]);
// Basic configuration MySQL/Mariadb
$entityManager = new EntityManager([
'driver' => 'mariadb',
'host' => '127.0.0.1',
'port' => 3306,
'dbname' => 'paper_orm_test',
'user' => 'root',
'password' => 'root',
'charset' => 'utf8mb4',
]);
✅ PaperORM est maintenant prêt à être utilisé !
Remarque : PDO et les extensions correspondantes à votre SGBD doivent être activées (pdo_mysql, pdo_sqlite, etc.).
Note: L’attribut ou la méthode
repositoryest facultatif. Si aucun n’est défini, un repository fictif sera généré automatiquement.
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...
}
use PaperORM\Entity\EntityInterface;
use PaperORM\Mapping\{PrimaryKeyColumn, StringColumn, BoolColumn, DateTimeColumn, OneToMany, JoinColumn};
#[Entity(table : 'user', repository : null)]
class User implements EntityInterface
{
#[PrimaryKeyColumn]
private ?int $id = null;
#[StringColumn]
private string $name;
#[StringColumn]
private string $email;
#[BoolColumn(name: 'is_active')]
private bool $isActive = true;
#[DateTimeColumn(name: 'created_at')]
private \DateTime $createdAt;
// Getters/Setters...
}
Récupération d'entités :
// 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();
Insertion/Mise à jour :
$newUser = new User();
$newUser->setName('Jean Dupont')
->setEmail('jean@example.com');
$entityManager->persist($newUser);
$entityManager->flush();
Suppression :
$user = $entityManager->getRepository(User::class)->find(1);
$entityManager->remove($user);
$entityManager->flush();
// Relation OneToMany
class Article
{
// IF PHP >= 8
#[\PhpDevCommunity\PaperORM\Mapping\OneToMany(Comment::class, 'article')]
private \PhpDevCommunity\PaperORM\Collection\ObjectStorage $comments;
public function __construct() {
$this->comments = new ObjectStorage();
}
// ...
public static function columnsMapping(): array
{
return [
new OneToMany('comments', Comment::class, 'article')
];
}
}
// Récupération avec jointure
$articleWithComments = $entityManager->getRepository(Article::class)
->find(1)
->with('comments')
->toObject();
// Tableau associatif
$userArray = $repository->find(1)->toArray();
// Objet entité
$userObject = $repository->find(1)->toObject();
// Collection d'objets
$activeUsers = $repository->findBy()
->where('isActive', true)
->toCollection();
PaperORM propose une API simple tout en couvrant les besoins essentiels d'un ORM moderne.
PaperORM est actuellement en version bêta et évolue activement. Nous invitons tous les développeurs intéressés à :
Si vous rencontrez un problème, ouvrez une issue GitHub en détaillant :
Des idées pour :
La documentation complète est en cours de rédaction. Vous pouvez :
Note : Cette version est stable pour un usage en développement, mais nécessite des tests supplémentaires pour la production.
Le développement actif continue - restez à l'écoute pour les mises à jour !