Download the PHP package julienlinard/doctrine-php without Composer
On this page you can find all versions of the php package julienlinard/doctrine-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download julienlinard/doctrine-php
More information about julienlinard/doctrine-php
Files in julienlinard/doctrine-php
Package doctrine-php
Short Description Modern ORM for PHP 8+ inspired by Doctrine, with Entity Manager, Repository Pattern, Query Builder and PHP 8 Attributes mapping
License MIT
Homepage https://github.com/julien-lin/doctrine-php
Informations about the package doctrine-php
Doctrine PHP - Modern ORM for PHP 8+
🇬🇧 Read in English
A modern, lightweight ORM (Object-Relational Mapping) for PHP 8+ inspired by Doctrine ORM. Features Entity Manager, Repository Pattern, Query Builder, and PHP 8 Attributes mapping with automatic optimizations.
✨ Features
- 🚀 Entity Manager - Complete entity lifecycle management
- 📦 Repository Pattern - Powerful repositories with CRUD methods
- 🔨 Query Builder - Fluent SQL query construction
- 🏷️ PHP 8 Attributes - Modern entity definition with attributes
- 🔗 Relations - OneToMany, ManyToOne, ManyToMany support
- 📊 Migrations - Automatic schema migration system with rollback
- 🔄 Transactions - Full transaction support with automatic rollback
- ⚡ Performance - Query cache, batch operations, N+1 optimization
- 📝 Query Logging - Built-in SQL query logging for debugging
- 🗄️ Multi-DBMS - MySQL, PostgreSQL, SQLite support
🚀 Quick Start
Installation
Requirements: PHP 8.0+ and PDO extension
Basic Usage
📖 Documentation
Table of Contents
- Entity Definition
- Entity Manager
- Repository
- Query Builder
- Relations
- Transactions
- Migrations
- Performance Features
- Query Logging
- API Reference
Entity Definition
Entities are defined using PHP 8 attributes:
Supported Column Types
string/varchar- VARCHAR with optional lengthtext- TEXTinteger/int- INTboolean/bool- TINYINT(1) or BOOLEANfloat/double- DOUBLEdecimal- DECIMAL with precision/scaledatetime- DATETIMEdate- DATEtime- TIMEjson- JSON (auto serialization)
Entity Manager
The Entity Manager is the central component for managing entities.
Basic Operations
Batch Operations
Insert multiple entities efficiently with a single query:
Transactions
Simplified transaction management with automatic rollback:
Repository
Repositories provide convenient methods for querying entities.
Standard Methods
Advanced Queries
Eager Loading (Optimized N+1)
Load relations efficiently with batch loading:
Custom Repository
Create custom repositories with shared MetadataReader:
Query Builder
Build complex SQL queries with a fluent interface:
Relations
OneToMany / ManyToOne
ManyToMany
Note: Automatic indexes are created on foreign key columns for optimal query performance.
Transactions
Automatic Transaction (Recommended)
Manual Transaction
Migrations
Generate and execute database migrations automatically.
Generate Migrations
CLI Commands
The package includes a ready-to-use CLI script:
Configuration
The CLI script automatically detects configuration from:
- Environment variable
DOCTRINE_CONFIG(path to PHP file) config/database.php(from current directory)../config/database.php(from current directory)- Environment variables
DB_HOST,DB_NAME,DB_USER,DB_PASSWORD
Example config/database.php:
Migration Rollback
Migrations can be rolled back using the CLI:
The system supports:
- Automatic rollback generation (CREATE TABLE → DROP TABLE)
- Custom rollback files (
migration_name_down.sql) - Migration classes implementing
MigrationInterfacewithdown()method
Performance Features
Query Cache
Cache query results to improve performance:
Batch Operations
Insert multiple entities efficiently:
N+1 Query Optimization
Eager loading with batch loading prevents N+1 queries:
Automatic Indexes
Foreign key columns automatically get indexes for optimal join performance.
Query Logging
Log all SQL queries for debugging and performance analysis:
API Reference
EntityManager Methods
| Method | Description |
|---|---|
persist(object $entity): void |
Mark entity for persistence |
persistBatch(array $entities): void |
Mark multiple entities for batch insert |
flush(): void |
Execute pending operations |
remove(object $entity): void |
Mark entity for deletion |
find(string $entityClass, int\|string $id): ?object |
Find entity by ID |
getRepository(string $entityClass): EntityRepository |
Get entity repository |
createRepository(string $repositoryClass, string $entityClass): EntityRepository |
Create custom repository |
transaction(callable $callback): mixed |
Execute in transaction with auto rollback |
beginTransaction(): void |
Start transaction |
commit(): void |
Commit transaction |
rollback(): void |
Rollback transaction |
enableQueryLog(bool $enabled, ?string $logFile, bool $logToConsole): QueryLoggerInterface |
Enable query logging |
disableQueryLog(): void |
Disable query logging |
getQueryLogger(): ?QueryLoggerInterface |
Get query logger |
generateMigration(string $entityClass): string |
Generate migration SQL |
generateMigrations(array $entityClasses): string |
Generate migrations for multiple entities |
EntityRepository Methods
| Method | Description |
|---|---|
find(int\|string $id): ?object |
Find entity by ID |
findOrFail(int\|string $id): object |
Find entity by ID or throw exception |
findAll(bool $useCache, ?int $cacheTtl): array |
Find all entities |
findBy(array $criteria, ?array $orderBy, ?int $limit, ?int $offset, bool $useCache, ?int $cacheTtl): array |
Find entities by criteria |
findOneBy(array $criteria): ?object |
Find one entity by criteria |
findOneByOrFail(array $criteria): object |
Find one entity or throw exception |
findAllWith(array $relations): array |
Find all with eager-loaded relations (optimized) |
🎯 Best Practices
Performance
-
Use batch operations for multiple inserts:
-
Use eager loading to avoid N+1 queries:
-
Enable query cache for frequently accessed data:
- Use transactions for multiple operations:
Code Quality
-
Use
findOrFail()instead of checking for null: -
Use custom repositories for complex queries:
- Enable query logging during development:
🔗 Integration Examples
With Symfony/Laravel-style Framework
📝 License
MIT License - See the LICENSE file for details.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
💝 Support
If this package is useful to you, consider becoming a sponsor to support development.
Developed with ❤️ by Julien Linard
All versions of doctrine-php with dependencies
ext-pdo Version *