PHPackages                             fyre/entity - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. fyre/entity

ActiveLibrary[Database &amp; ORM](/categories/database)

fyre/entity
===========

An entity library.

v7.0.2(7mo ago)0224↓77.8%3MITPHP

Since Jan 9Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/elusivecodes/FyreEntity)[ Packagist](https://packagist.org/packages/fyre/entity)[ RSS](/packages/fyre-entity/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (6)Versions (36)Used By (3)

FyreEntity
==========

[](#fyreentity)

**FyreEntity** is a free, open-source entity library for *PHP*.

Table Of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Basic Usage](#basic-usage)
- [Methods](#methods)
- [Entities](#entities)

Installation
------------

[](#installation)

**Using Composer**

```
composer require fyre/entity

```

In PHP:

```
use Fyre\Entity\EntityLocator;
```

Basic Usage
-----------

[](#basic-usage)

- `$inflector` is an [*Inflector*](https://github.com/elusivecodes/FyreInflector).

```
$entityLocator = new EntityLocator($inflector);
```

**Autoloading**

It is recommended to bind the *EntityLocator* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.

```
$container->singleton(EntityLocator::class);
```

Methods
-------

[](#methods)

**Add Namespace**

Add a namespace for locating entities.

- `$namespace` is a string representing the namespace.

```
$entityLocator->addNamespace($namespace);
```

**Clear**

Clear all namespaces and entities.

```
$entityLocator->clear();
```

**Find**

Find the entity class name for an alias.

- `$alias` is a string representing the alias.

```
$className = $entityLocator->find($alias);
```

**Find Alias**

Find the alias for an entity class name.

- `$className` is a string representing the entity class name.

```
$alias = $entityLocator->findAlias($className);
```

**Get Default Entity Class**

Get the default entity class name.

```
$defaultEntityClass = $entityLocator->getDefaultEntityClass();
```

**Get Namespaces**

Get the namespaces.

```
$namespaces = $entityLocator->getNamespaces();
```

**Has Namespace**

Check if a namespace exists.

- `$namespace` is a string representing the namespace.

```
$hasNamespace = $entityLocator->hasNamespace($namespace);
```

**Map**

Map an alias to an entity class name.

- `$alias` is a string representing the alias.
- `$className` is a string representing the entity class name.

```
$entityLocator->map($alias, $className);
```

**Remove Namespace**

Remove a namespace.

- `$namespace` is a string representing the namespace.

```
$entityLocator->removeNamespace($namespace);
```

**Set Default Entity Class**

Set the default entity class name.

- `$defaultEntityClass` is a string representing the default entity class name.

```
$entityLocator->setDefaultEntityClass($defaultEntityClass);
```

Entities
--------

[](#entities)

```
use Fyre\Entity\Entity;
```

- `$data` is an array containing the data for populating the entity.
- `$options` is an array containing the options for creating the entity.
    - `source` is a string representing the entity source, and will default to *null*.
    - `new` is a boolean indicating whether the entity is new, and will default to *true*.
    - `clean` is a boolean indicating whether to clean the entity after init, and will default to *true*.
    - `guard` is a boolean indicating whether to check whether the fields are accessible, and will default to *false*.
    - `mutate` is a boolean indicating whether to mutate the values, and will default to *true*.

```
$entity = new Entity($data, $options);
```

**Clean**

Clean the entity.

```
$entity->clean();
```

**Clear**

Clear values from the entity.

- `$fields` is an array containing the fields to clear.

```
$entity->clear($fields);
```

**Clear Temporary Fields**

Clear temporary fields from the entity.

```
$entity->clearTemporaryFields();
```

**Extract**

Extract values from the entity.

- `$fields` is an array containing the fields to extract.

```
$values = $entity->extract($fields);
```

**Extract Dirty**

Extract dirty values from the entity.

- `$fields` is an array containing the fields to extract.

```
$values = $entity->extractDirty($fields);
```

If the `$field` argument is omitted, this method will return all dirty values.

```
$values = $entity->extractDirty();
```

**Extract Original**

Extract original values from the entity.

- `$fields` is an array containing the fields to extract.

```
$values = $entity->extractOriginal($fields);
```

**Extract Original Changed**

Extract original changed values from the entity.

- `$fields` is an array containing the fields to extract.

```
$values = $entity->extractOriginalChanged($fields);
```

**Fill**

Fill the entity with values.

- `$data` is an array containing the data to fill.
- `$options` is an array containing options for filling the entity.
    - `guard` is a boolean indicating whether to check whether the fields are accessible, and will default to *true*.
    - `mutate` is a boolean indicating whether to mutate the values, and will default to *true*.
    - `original` is a boolean indicating whether to set the fields as original, and will default to *false*.

```
$entity->fill($data, $options);
```

If the `mutate` option is set to *true*, and a `_setFieldName` method exists in the entity (where the field name is *field\_name*), then that method will be called for each value being set. The argument will be the value being populated, and the return value of that method will be stored in the entity instead.

**Fill Invalid**

Fill the entity with invalid values.

- `$data` is an array containing the data to fill.
- `$overwrite` is a boolean indicating whether to overwrite existing values, and will default to *false*.

```
$entity->fillInvalid($data, $overwrite);
```

**Get**

Get a value from the entity.

- `$field` is a string representing the field name.

```
$value = $entity->get($field);
```

Alternatively, you can get a value using the magic `__get` method or array syntax.

```
$value = $entity->$field;
$value = $entity[$field];
```

If a `_getFieldName` method exists in the entity (where the field name is *field\_name*), then that method will be called for the value being retrieved. The argument of that method will be the value stored in the entity, and the return value of that method will be returned instead.

**Get Accessible**

Get the accessible fields from the entity.

```
$accessible = $entity->getAccessible();
```

**Get Dirty**

Get the dirty fields from the entity.

```
$dirty = $entity->getDirty();
```

**Get Error**

Get the errors for an entity field.

- `$field` is a string representing the field name.

```
$errors = $entity->getError($field);
```

**Get Errors**

Get all errors for the entity.

```
$errors = $entity->getErrors();
```

**Get Hidden**

Get the hidden fields from the entity.

```
$hidden = $entity->getHidden();
```

**Get Invalid**

Get invalid value(s) from the entity.

- `$field` is a string representing the field name.

```
$value = $entity->getInvalid($field);
```

If the `$field` argument is omitted, this method will return all invalid values.

```
$invalid = $entity->getInvalid();
```

**Get Original**

Get an original value from the entity.

- `$field` is a string representing the field name.
- `$fallback` is a boolean indicating whether to fallback to the current value, and will default to *true*.

```
$value = $entity->getOriginal($field, $fallback);
```

If the `$field` argument is omitted, this method will return all original values.

```
$original = $entity->getOriginal();
```

**Get Original Fields**

Get the original fields from the entity.

```
$originalFields = $entity->getOriginalFields();
```

**Get Original Values**

Get the original values from the entity.

```
$originalValues = $entity->getOriginalValues();
```

**Get Source**

Get the entity source.

```
$source = $entity->getSource();
```

**Get Temporary Fields**

Get the temporary fields from the entity.

```
$temporaryFields = $entity->getTemporaryFields();
```

**Get Virtual**

Get the virtual fields from the entity.

```
$virtual = $entity->getVirtual();
```

**Get Visible**

Get the visible fields from the entity.

```
$visible = $entity->getVisible();
```

**Has**

Determine if an entity value is set.

- `$field` is a string representing the field name.

```
$has = $entity->has($field);
```

Alternatively, you can determine if a value is set using the magic `__isset` method or array syntax.

```
$isset = isset($entity->$field);
$isset = isset($entity[$field]);
```

**Has Original**

Determine if an entity field has an original value.

- `$field` is a string representing the field name.

```
$hasOriginal = $entity->hasOriginal($field);
```

**Has Value**

Determine if an entity value is not empty.

- `$field` is a string representing the field name.

```
$hasValue = $entity->hasValue($field);
```

**Has Errors**

Determine if the entity has errors.

```
$hasErrors = $entity->hasErrors();
```

**Is Accessible**

Determine if an entity field is accessible.

- `$field` is a string representing the field name.

```
$isAccessible = $entity->isAccessible($field);
```

**Is Dirty**

Determine if an entity field is dirty.

- `$field` is a string representing the field name.

```
$isDirty = $entity->isDirty($field);
```

If the `$field` argument is omitted, this method will determine whether the entity has any dirty fields.

```
$isDirty = $entity->isDirty();
```

**Is Empty**

Determine if an entity is empty.

```
$isEmpty = $entity->isEmpty();
```

**Is New**

Determine if the entity is new.

```
$isNew = $entity->isNew();
```

**Is Original Field**

Determine if an entity field is original.

- `$field` is a string representing the field name.

```
$isOriginalField = $entity->isOriginalField($field);
```

**Set**

Set an entity value.

- `$field` is a string representing the field name.
- `$value` is the value to set.
- `$options` is an array containing options for filling the entity.
    - `guard` is a boolean indicating whether to check whether the field is accessible, and will default to *true*.
    - `mutate` is a boolean indicating whether to mutate the value, and will default to *true*.
    - `original` is a boolean indicating whether to set the field as an original, and will default to *false*.

```
$entity->set($field, $value, $options);
```

Alternatively, you can set a value using the magic `__set` method or array syntax.

```
$entity->$field = $value;
$entity[$field] = $value;
```

If the `mutate` option is set to *true*, and a `_setFieldName` method exists in the entity (where the field name is *field\_name*), then that method will be called for the value being set. The argument will be the value being populated, and the return value of that method will be stored in the entity instead.

**Set Access**

Set whether a field is accessible.

- `$field` is a string representing the field name.
- `$accessible` is a boolean indicating whether the field is accessible.

```
$entity->setAccess($field, $accessible);
```

**Set Dirty**

Set whether a field is dirty.

- `$field` is a string representing the field name.
- `$dirty` is a boolean indicating whether the field is dirty, and will default to *true*.

```
$entity->setDirty($field, $dirty);
```

**Set Error**

Set errors for an entity field.

- `$field` is a string representing the field name.
- `$error` is a string or array containing the errors.
- `$overwrite` is a boolean indicating whether to overwrite existing errors, and will default to *false*.

```
$entity->setError($field, $error, $ovewrite);
```

**Set Errors**

Set all errors for the entity.

- `$errors` is an array containing the errors.
- `$overwrite` is a boolean indicating whether to overwrite existing errors, and will default to *false*.

```
$entity->setErrors($errors, $overwrite);
```

**Set Hidden**

Set hidden fields.

- `$fields` is an array containing the field names.
- `$merge` is a boolean indicating whether to merge with existing fields.

```
$entity->setHidden($fields, $merge);
```

**Set Invalid**

Set an invalid value.

- `$field` is a string representing the field name.
- `$value` is the value to set.
- `$overwrite` is a boolean indicating whether to overwrite existing errors, and will default to *true*.

```
$entity->setInvalid($field, $value, $overwrite);
```

**Set New**

Set whether the entity is new.

- `$new` is a boolean whether the entity is new, and will default to *true*.

```
$entity->setNew($new);
```

**Set Original Fields**

Set original fields.

- `$fields` is an array containing the field names.
- `$merge` is a boolean indicating whether to merge with existing fields.

```
$entity->setOriginalFields($fields, $merge);
```

**Set Source**

Set the entity source.

- `$source` is a string representing the source.

```
$entity->setSource($source);
```

**Set Temporary Fields**

- `$fields` is an array containing the field names.
- `$overwrite` is a boolean indicating whether to overwrite existing fields, and will default to *false*.

```
$entity->setTemporaryFields($fields, $overwrite);
```

**Set Virtual**

Set virtual fields.

- `$fields` is an array containing the field names.
- `$merge` is a boolean indicating whether to merge with existing fields.

```
$entity->setVirtual($fields, $merge);
```

**To Array**

Convert the entity to an array.

```
$array = $entity->toArray();
```

**To JSON**

Convert the entity to a JSON string.

```
$json = $entity->toJson();
```

Alternatively, you can cast the value to a string using the magic `__toString` method.

```
$json = (string) $entity;
```

**Unset**

Unset an entity value.

- `$field` is a string representing the field name.

```
$entity->unset($field);
```

Alternatively, you can unset a value using the magic `__unset` method or array syntax.

```
unset($entity->$field);
unset($entity[$field]);
```

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance62

Regular maintenance activity

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~41 days

Recently: every ~19 days

Total

35

Last Release

234d ago

Major Versions

v2.0 → v3.02023-07-24

v3.0.4 → v4.02024-06-02

v4.0.3 → v5.02024-11-01

v5.1.4 → v6.02025-04-25

v6.0.7 → v7.02025-10-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/fad81fd5941e3a637c8a5749d05ae3ed9314d5e2fee57f59c3d9ec3b41259c6b?d=identicon)[elusivecodes](/maintainers/elusivecodes)

---

Top Contributors

[![elusivecodes](https://avatars.githubusercontent.com/u/18050480?v=4)](https://github.com/elusivecodes "elusivecodes (26 commits)")

---

Tags

entityormphp

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/fyre-entity/health.svg)

```
[![Health](https://phpackages.com/badges/fyre-entity/health.svg)](https://phpackages.com/packages/fyre-entity)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
