# Entity documentation
An entity in the context of the MMO framework is a class that represents a data model with various capabilities. It extends from the aEntity class and includes properties, metadata, validation, change tracking, links, status management, collection management, and error handling.
Entities in the MMO framework are powerful tools for managing data models. By defining properties with the `ArrayProperty` attribute and using the provided methods, you can efficiently handle data. This documentation should help you get started with creating and using entities in the project.
1. **Define the Class**: Create a new class that extends the `Entity` class.
2. **Add Properties**: Use the `ArrayProperty` attribute to define properties and their metadata.
3. **Constructor**: Implement a constructor to initialize the entity with data and optionally a collection.
4. **Methods**: Add methods to manipulate and access the entity's properties.
### Defining a Custom Entity Example
```php
namespace MMO\core\entities;
use MMO\core\attributes\ArrayProperty;
use MMO\core\interfaces\iCollection;
class CustomEntity extends Entity {
#[ArrayProperty()]
protected ?string $customProperty = null;
public function __construct(array $data = [], ?iCollection $collection = null) {
parent::__construct($data, $collection);
}
public function getCustomProperty(): ?string {
return $this->customProperty;
}
public function setCustomProperty(?string $value): void {
$this->customProperty = $value;
$this->markChanged('customProperty');
}
}
```
### Capabilities of an Entity
1. **Properties**:
- Defined using the `ArrayProperty` attribute.
- Can have getters, setters, and schema definitions.
2. **Metadata**:
- Provides metadata such as title, label, and links.
3. **Validation**:
- Can be validated against their schema.
4. **Change Tracking**:
- Tracks changes to properties and can mark properties as changed.
5. **Links**:
- Can have links to other entities or resources.
6. **Status Management**:
- Can manage status (e.g., active, archived).
7. **Collection Management**:
- Can be part of a collection and manage its association with the collection.
8. **Error Handling**:
- Can handle and store errors related to property setting and validation.
By following these guidelines, you can create custom entities that leverage the capabilities of the `Entity` class in the MMO framework.