PHP code example of chamber-orchestra / doctrine-clock-bundle

1. Go to this page and download the library: Download chamber-orchestra/doctrine-clock-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chamber-orchestra / doctrine-clock-bundle example snippets


// config/bundles.php
return [
    ChamberOrchestra\MetadataBundle\ChamberOrchestraMetadataBundle::class => ['all' => true],
    ChamberOrchestra\DoctrineClockBundle\ChamberOrchestraDoctrineClockBundle::class => ['all' => true],
];

use ChamberOrchestra\DoctrineClockBundle\Entity\TimestampTrait;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Article
{
    use TimestampTrait; // adds createdDatetime + updatedDatetime

    // ... your fields
}

use ChamberOrchestra\DoctrineClockBundle\Mapping\Attribute\CreateTimestamp;
use ChamberOrchestra\DoctrineClockBundle\Mapping\Attribute\UpdateTimestamp;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Clock\DatePoint;

#[ORM\Entity]
class Article
{
    #[CreateTimestamp]
    #[ORM\Column(type: 'date_point', nullable: false)]
    private DatePoint $createdAt;

    #[UpdateTimestamp]
    #[ORM\Column(type: 'date_point', nullable: false)]
    private DatePoint $modifiedAt;

    // ... getters, setters
}