ursusarctosua/doctrine-timestamp
doctrine-timestamp) appears to provide timestamp management capabilities (e.g., auto-updating created_at, updated_at, or custom timestamps) for Doctrine ORM entities in PHP/Laravel. This aligns well with:
timestamps() in models or packages like spatie/laravel-activitylog already handle timestamps/audit logs. This package’s value depends on Doctrine-specific features (e.g., custom timestamp columns, bulk updates, or complex event hooks).doctrine/dbal), this package could enhance timestamp logic without replacing Eloquent.EntityManager alongside Eloquent).| Risk Area | Description | Mitigation Strategy |
|---|---|---|
| ORM Conflict | Eloquent and Doctrine ORM may clash over model hydration, events, or timestamp logic. | Use Doctrine exclusively for timestamped entities or build a wrapper trait. |
| Performance Overhead | Doctrine’s event listeners add minor overhead. If used for bulk operations, this could slow down migrations or batch updates. | Benchmark with created_at/updated_at updates; consider database-level triggers as a fallback. |
| Laravel-Specific Gaps | Laravel’s timestamps() is simpler. This package may lack Laravel’s accessors/mutators or Carbon integration. |
Extend the package or write Laravel-specific adapters for Carbon timestamps. |
| License Incompatibility | CC-BY-SA-4.0 (Creative Commons) is not a typical open-source license for code. May conflict with Laravel’s MIT license or proprietary projects. | Clarify usage rights; consider forking or using a permissive-licensed alternative. |
| Limited Adoption | 0 stars/score suggests unproven reliability. May lack documentation or community support. | Evaluate via proof-of-concept (e.g., test on a non-critical entity). |
Why Doctrine?
Scope of Timestamps
deleted_at, archived_at)?Migration Path
timestamps() be converted to use this package?created_at columns)?Event-Driven Workflows
ModelCreating, ModelUpdating)?Observers or Model Events?Testing & Validation
| Component | Compatibility Notes |
|---|---|
| Laravel Eloquent | Low: Direct integration is difficult. Options: 1. Hybrid Models: Extend Eloquent models with Doctrine traits. 2. Doctrine-Only: Use this package for Doctrine-managed entities only. 3. Adapter Layer: Create a service to unify timestamp logic. |
| Doctrine ORM | High: Designed for Doctrine. Works with EntityManager, lifecycle callbacks, and custom repositories. |
| Laravel Services | Medium: May conflict with Laravel’s Model::boot() or registerGlobalScopes(). |
| Database | High: Agnostic to DB (MySQL, PostgreSQL, etc.), but Laravel migrations may need adjustments for Doctrine-specific schema changes. |
| Testing Tools | Low: No Laravel-specific test helpers (e.g., assertTimestamps). May require custom assertions. |
Assessment Phase
timestamps(), manual now(), etc.).Pilot Integration
created_at, updated_at, and custom timestamps.DoctrineTimestampable) that works with both Eloquent and Doctrine.trait DoctrineTimestampable {
use \ursusarctosua\DoctrineTimestamp\Timestampable;
// Override for Laravel Carbon compatibility
public function getCreatedAtAttribute() { ... }
}
Incremental Rollout
timestamps() with the package’s logic.Database Schema
deleted_at), ensure database triggers or application logic align.Schema::table('users', function (Blueprint $table) {
$table->timestamp('custom_updated_at')->nullable()->after('updated_at');
});
| Concern | Solution |
|---|---|
Laravel’s timestamps() |
Disable it for Doctrine-managed models: php <br> class User extends Model { <br> public $timestamps = false; // Disable Eloquent timestamps <br> use DoctrineTimestampable; <br> } |
| Carbon vs. DateTime | The package likely uses DateTime. Add a mutator to convert to Carbon for Laravel APIs. |
| Soft Deletes | If using SoftDeletes, ensure the package’s deleted_at logic doesn’t conflict with Eloquent’s. |
| Timezones | Doctrine may use UTC by default. Configure in config/app.php or via Doctrine’s ORM\Configuration. |
Prerequisites
composer require doctrine/dbal doctrine/orm.doctrine/laravel-doctrine or custom bootstrap).Core Integration
Post).Event Hooks
creating, updating).// In a Service Provider
$em->getEventManager()->addEventListener(
\Doctrine\ORM\Events::preUpdate,
[$this, 'onPreUpdate']
How can I help you explore Laravel packages today?