https://github.com/xanweb/c5-entity
Reusable classes for entities
https://github.com/xanweb/c5-entity
Last synced: 25 days ago
JSON representation
Reusable classes for entities
- Host: GitHub
- URL: https://github.com/xanweb/c5-entity
- Owner: Xanweb
- License: mit
- Created: 2021-03-24T14:26:39.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-22T14:30:47.000Z (over 3 years ago)
- Last Synced: 2025-05-15T04:09:49.666Z (25 days ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ConcreteCMS Entity
[](https://packagist.org/packages/xanweb/c5-entity)
[](LICENSE)Reusable classes for entities
## Installation
Include library to your composer.json
```bash
composer require xanweb/c5-entity
```## Usage
Simply you can extend EntityService and EntityObject classes to benefit from predefined methods```php
use Doctrine\ORM\Mapping as ORM;/**
* @ORM\Entity
* @ORM\Table(name="MyEntityTable")
*/
class MyEntity extends \Xanweb\C5\Entity\EntityObject {
...
}/**
* @method MyEntity createEntity()
* @method MyEntity create($data)
* @method MyEntity getByID($id)
* @method MyEntity[] getList()
*
* or if your IDE supports generic type
* @implements EntityService
*/
class MyEntityService extends \Xanweb\C5\Entity\Service\EntityService {
/**
* {@inheritdoc}
*
* @see \Xanweb\C5\Entity\Service\EntityService::getEntityClass()
*/
public function getEntityClass(): string
{
return MyEntity::class;
}
}
```Use TimeStampableTrait to include created date and last updated date fields to your entity.
Please note that usage of this trait requires "HasLifecycleCallbacks" annotation.
See https://www.doctrine-project.org/projects/doctrine-orm/en/2.8/reference/annotations-reference.html#annref_haslifecyclecallbacks```php
use Doctrine\ORM\Mapping as ORM;/**
* @ORM\Entity
* @ORM\Table(name="MyEntityTable")
* @ORM\HasLifecycleCallbacks
*/
class MyEntity extends \Xanweb\C5\Entity\EntityObject {
use \Xanweb\C5\Entity\Traits\TimeStampableTrait;
...
}
```