geosocio/entity-utils

Utilities for Doctrine Entities

1.2.2 2018-02-19 13:01 UTC

This package is auto-updated.

Last update: 2024-04-11 23:45:33 UTC


README

Provides simply Doctrine Entity Utilities.

Parameter Bag

Easily construct an entity through the constructor.

use GeoSocio\EntityUtils\ParameterBag;

class User {

  __construct(array $data = []) {
    $params = new ParameterBag($data);
    $this->id = $params->getInt('id');
    $this->first = $params->getString('first');
    $this->last = $params->getString('last');
    $this->address = $params->getInstance('address', Address::class, new Address());
    $this->posts = $params->getCollection('posts', Post::class, new ArrayCollection());
  }

}

CreatedTrait

Include the trait in your entity to add a 'created' field that is added on persist.

use GeoSocio\EntityUtils\CreatedTrait;

class User {

  use CreatedTrait;

}