=========== Inspiration =========== In text below, you may find some ideas on how to use ``runopencode/metadata`` library in your projects. Implementing timestampable behavior using ``runopencode/metadata`` ------------------------------------------------------------------ Assume that you want to implement, in example, timestampable behavior for your Doctrine entities and you do not want to use 3rd party library (such as ``gedmo/doctrine-extensions``, https://github.com/doctrine-extensions/DoctrineExtensions) for that, this libray makes that a trivial task. First thing which you would need is an attribute so you can mark properties which should be automatically updated with current timestamp on entity creation and update: .. code-block:: php :linenos: getObject(); $when = new \DateTimeImmutable('now'); $this->touch($entity, $when, Timestampable::CREATE, Timestampable::UPDATE); } public function preUpdate(LifecycleEventArgs $args): void { $entity = $args->getObject(); $when = new \DateTimeImmutable('now'); $this->touch($entity, $when, Timestampable::UPDATE); } private function touch(object $entity, \DateTimeImmutable $when, string ...$on): void { $properties = $this->reader->properties($entity, Timestampable::class); if (0 === \count($properties)) { return; } foreach ($on as $condition) { foreach ($properties as $property) { $attribute = $property->get(Timestampable::class); if ($condition !== $attribute->on) { continue; } $property->write($entity, $when); } } } }