dsdeboer/propel1
Symfony bundle and integration helpers for Propel 1, providing configuration, service wiring, and utilities to use the Propel ORM in modern PHP applications. Useful for projects maintaining legacy Propel 1 models while leveraging Symfony components.
Installation Add Propel to your Laravel project via Composer:
composer require dsdeboer/propel1
Ensure your composer.json includes "propel/propel": "1.6.*" (or the latest stable version).
Schema Configuration
Define your database schema in an XML file (e.g., schema.xml) under config/propel/schema/. Example:
<database name="default" connection="mysql:host=localhost;dbname=test">
<table name="users">
<column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" />
<column name="name" type="VARCHAR" size="255" />
</table>
</database>
Build the Model Layer Generate Propel models from your schema:
php vendor/bin/propel-gen build --config=config/propel/schema.xml
First Query Use Propel’s Query API in a Laravel controller or service:
use Propel\Runtime\Connection\ConnectionManagerSingle;
use Propel\Runtime\Propel;
$users = UserQuery::create()->find();
return response()->json($users);
Service Layer Abstraction Create a service class to encapsulate Propel queries:
namespace App\Services;
use Propel\Runtime\ActiveQuery\ModelCriteria;
class UserService {
public function getAllUsers(): array {
return UserQuery::create()->find();
}
}
Dependency Injection
Bind Propel’s ConnectionManager to Laravel’s IoC container in AppServiceProvider:
public function register() {
$this->app->singleton('propel.connection', function () {
return ConnectionManagerSingle::getInstance();
});
}
Eloquent-like Facade
Extend Laravel’s Facade to simplify Propel usage:
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Propel extends Facade {
protected static function getFacadeAccessor() {
return 'propel.connection';
}
}
CRUD Operations
$user = new User();
$user->setName('John Doe');
$user->save();
$user = UserQuery::create()->findPk(1);
$user->setName('Updated Name')->save();
$user->delete();
Complex Queries
Use Propel’s Criteria for filtering:
$activeUsers = UserQuery::create()
->filterByIsActive(true)
->orderByName()
->find();
Transactions Wrap Propel operations in Laravel transactions:
DB::transaction(function () {
$user = new User();
$user->setName('Alice')->save();
// Additional Propel operations...
});
Migrations
Sync Propel schema with Laravel migrations by extending SchemaBuilder:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
// Propel-specific logic here
});
Schema Synchronization
php vendor/bin/propel-gen build --config=config/propel/schema.xml
propel-gen diff-schema to compare schema changes.Lazy Loading
Propel’s lazy loading can cause N+1 queries. Use withColumn() or join():
$users = UserQuery::create()
->withColumn('UserProfile', 'ProfileQuery')
->find();
Connection Management
Propel’s ConnectionManager may conflict with Laravel’s DB facade. Explicitly specify connections:
ConnectionManager::getInstance()->setDefaultDSN('mysql:host=localhost;dbname=laravel_db');
Caching Queries Propel caches queries aggressively. Clear cache after schema changes:
php vendor/bin/propel-gen build --clear-cache
Query Logging
Enable Propel’s debug mode in config/propel/runtime/propel.ini:
propel.debug = true
propel.log.level = debug
Common Errors
schema.xml matches your database.schema.xml (Propel is case-sensitive).primaryKey="true" in schema.xml.Custom Behavior
Extend Propel’s BaseModel for reusable logic:
namespace App\Models;
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
class BaseUser extends \BaseUser implements ActiveRecordInterface {
public function isAdmin() {
return $this->getRole() === 'admin';
}
}
Event Listeners
Use Propel’s Peer classes to hook into lifecycle events:
UserPeer::doSave($user);
// Add custom logic before/after save
Validation Integrate Laravel’s validation with Propel:
$validator = Validator::make($request->all(), [
'name' => 'required|string',
]);
if ($validator->fails()) {
throw new \PropelException('Validation failed');
}
How can I help you explore Laravel packages today?