diablomedia/doctrine1-bundle
Symfony bundle that integrates Doctrine1 ORM with modern Symfony apps. Configure connections via YAML, get query logging in the profiler/debug toolbar, and support multiple connections with optional query/result caching. Works best with the DiabloMedia Doctrine1 fork.
Installation:
composer require diablomedia/doctrine1-bundle diablomedia/doctrine1
doctrine1 fork is recommended for better PHP compatibility.Enable Bundle:
Add to config/app.php under providers:
DiabloMedia\Bundle\Doctrine1Bundle\Doctrine1Bundle::class,
Configure Database:
Create config/doctrine1.php (or add to config/services.php):
'doctrine1' => [
'default_connection' => 'default',
'connections' => [
'default' => [
'url' => env('DATABASE_URL'),
'cache_class' => 'Doctrine_Cache_Array',
'enable_query_cache' => true,
'enable_result_cache' => true,
],
],
],
First Use Case:
Inject the Doctrine1 service in a controller/service:
use DiabloMedia\Bundle\Doctrine1Bundle\Doctrine1;
public function __construct(private Doctrine1 $doctrine) {}
public function index() {
$query = $this->doctrine->getConnection()->createQuery('SELECT * FROM users');
$results = $query->execute();
return view('users.index', ['users' => $results]);
}
Debugging:
Enable the Symfony profiler in config/packages/dev/doctrine1.yaml:
profiler: true
Access the toolbar at /_profiler to inspect Doctrine queries.
Connection Management:
writer, reader) for read/write separation:
$writer = $this->doctrine->getConnection('writer');
$reader = $this->doctrine->getConnection('reader');
Query Building:
$qb = $this->doctrine->getConnection()->createQueryBuilder();
$qb->select('u.*')->from('users', 'u')->where('u.active = 1');
$users = $qb->execute()->fetchAll();
Entity Mapping:
config/doctrine1.php:
'mappings' => [
'App\Entity' => [
'type' => 'annotation',
'dir' => __DIR__.'/../src/Entity',
'namespace' => 'App\Entity',
],
],
@Table, @Column) in your entities.Caching:
Doctrine_Cache_Apc, Doctrine_Cache_Memcache):
cache_class: 'Doctrine_Cache_Memcache'
memcache_host: '%env(MEMCACHE_HOST)%'
Migrations:
doctrine1:migrations:execute (if integrated) or raw SQL for schema changes:
php bin/console doctrine1:migrations:execute
Repository Pattern:
class UserRepository {
public function __construct(private Doctrine1 $doctrine) {}
public function findActiveUsers() {
return $this->doctrine->getConnection()
->createQuery('SELECT * FROM users WHERE active = 1')
->execute()
->fetchAll();
}
}
Transaction Management:
$conn = $this->doctrine->getConnection();
$conn->beginTransaction();
try {
$conn->execute('UPDATE accounts SET balance = balance - 100 WHERE id = ?', [1]);
$conn->execute('UPDATE accounts SET balance = balance + 100 WHERE id = ?', [2]);
$conn->commit();
} catch (\Exception $e) {
$conn->rollBack();
throw $e;
}
Event Listeners:
postInsert):
$conn->listen('postInsert', function ($event) {
// Post-save logic
});
Symfony Integration:
# config/services.yaml
services:
App\Service\UserService:
arguments:
$doctrine: '@doctrine1'
Laravel-Specific:
vendor/diablomedia/doctrine1-bundle/Resources/views/Profiler/doctrine1.html.twig to resources/views/vendor/doctrine1/profiler.html.twig.Testing:
Doctrine1TestCase for unit tests:
use DiabloMedia\Bundle\Doctrine1Bundle\Testing\Doctrine1TestCase;
class UserTest extends Doctrine1TestCase {
public function testFindUser() {
$user = $this->getDoctrine1()->getConnection()->fetchRow('SELECT * FROM users WHERE id = 1');
$this->assertEquals('John', $user['name']);
}
}
Performance:
enable_query_cache: true
cache_class: 'Doctrine_Cache_Redis'
redis_host: '%env(REDIS_HOST)%'
Legacy Code:
Doctrine_Connection directly for compatibility:
$conn = $this->doctrine->getConnection();
$result = $conn->fetchAll('SELECT * FROM legacy_table');
Profiler in Production:
APP_ENV). If you need it in staging, explicitly enable it in config/packages/staging/doctrine1.yaml:
profiler: true
Deprecated Twig Functions:
{{ deprecated() }} in templates (removed in v1.1.4). Replace with @deprecated tags or modern Twig syntax.Connection Pooling:
Doctrine_Connection_Manager or a PDO wrapper.Case-Sensitive Schema:
$query = 'SELECT `id`, `name` FROM `users`'; // Backticks for MySQL
Symfony 6+ Profiler:
Twig\Error\RuntimeError.Entity Metadata:
src/. Explicitly define mappings in config/doctrine1.php:
'mappings' => [
'App\Entity' => ['dir' => __DIR__.'/../../src/Entity'],
],
Transactions and PDO:
PDO::ATTR_AUTOCOMMIT = false for nested transactions:
$conn->getWrappedConnection()->exec('SET AUTOCOMMIT = 0');
Query Logging:
config/doctrine1.yaml:
logging: true
log_path: '%kernel.logs_dir%/doctrine1.log'
Profiler Data:
php bin/console cache:clear
Connection Issues:
url format in config (e.g., mysql://user:pass@host/db or postgresql://user:pass@host/db).cache_class (e.g., Doctrine_Cache_Array vs. Doctrine\Cache\ArrayCache).Entity Errors:
doctrine1:schema:validate to check mappings:
php bin/console doctrine1:schema:validate
Deprecation Warnings:
config/bootstrap.php (temporarily):
error_reporting(E_ALL & ~E_DEPRECATED);
How can I help you explore Laravel packages today?