{"id":21467463,"url":"https://github.com/elusivecodes/fyreentity","last_synced_at":"2025-04-22T19:02:29.015Z","repository":{"id":62508418,"uuid":"446076559","full_name":"elusivecodes/FyreEntity","owner":"elusivecodes","description":"FyreEntity is a free, open-source entity library for PHP.","archived":false,"fork":false,"pushed_at":"2024-12-19T13:45:15.000Z","size":164,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-30T13:38:25.928Z","etag":null,"topics":["entity","orm","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elusivecodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-09T12:04:33.000Z","updated_at":"2024-12-19T13:44:58.000Z","dependencies_parsed_at":"2025-01-23T15:47:26.012Z","dependency_job_id":null,"html_url":"https://github.com/elusivecodes/FyreEntity","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreEntity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreEntity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreEntity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elusivecodes%2FFyreEntity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elusivecodes","download_url":"https://codeload.github.com/elusivecodes/FyreEntity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250306609,"owners_count":21408925,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["entity","orm","php"],"created_at":"2024-11-23T08:18:12.568Z","updated_at":"2025-04-22T19:02:29.000Z","avatar_url":"https://github.com/elusivecodes.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FyreEntity\r\n\r\n**FyreEntity** is a free, open-source entity library for *PHP*.\r\n\r\n\r\n## Table Of Contents\r\n- [Installation](#installation)\r\n- [Basic Usage](#basic-usage)\r\n- [Methods](#methods)\r\n- [Entities](#entities)\r\n\r\n\r\n\r\n## Installation\r\n\r\n**Using Composer**\r\n\r\n```\r\ncomposer require fyre/entity\r\n```\r\n\r\nIn PHP:\r\n\r\n```php\r\nuse Fyre\\Entity\\EntityLocator;\r\n```\r\n\r\n\r\n## Basic Usage\r\n\r\n- `$inflector` is an [*Inflector*](https://github.com/elusivecodes/FyreInflector).\r\n\r\n```php\r\n$entityLocator = new EntityLocator($inflector);\r\n```\r\n\r\n**Autoloading**\r\n\r\nIt is recommended to bind the *EntityLocator* to the [*Container*](https://github.com/elusivecodes/FyreContainer) as a singleton.\r\n\r\n```php\r\n$container-\u003esingleton(EntityLocator::class);\r\n```\r\n\r\n\r\n## Methods\r\n\r\n**Add Namespace**\r\n\r\nAdd a namespace for locating entities.\r\n\r\n- `$namespace` is a string representing the namespace.\r\n\r\n```php\r\n$entityLocator-\u003eaddNamespace($namespace);\r\n```\r\n\r\n**Clear**\r\n\r\nClear all namespaces and entities.\r\n\r\n```php\r\n$entityLocator-\u003eclear();\r\n```\r\n\r\n**Find**\r\n\r\nFind the entity class name for an alias.\r\n\r\n- `$alias` is a string representing the alias.\r\n\r\n```php\r\n$className = $entityLocator-\u003efind($alias);\r\n```\r\n\r\n**Find Alias**\r\n\r\nFind the alias for an entity class name.\r\n\r\n- `$className` is a string representing the entity class name.\r\n\r\n```php\r\n$alias = $entityLocator-\u003efindAlias($className);\r\n```\r\n\r\n**Get Default Entity Class**\r\n\r\nGet the default entity class name.\r\n\r\n```php\r\n$defaultEntityClass = $entityLocator-\u003egetDefaultEntityClass();\r\n```\r\n\r\n**Get Namespaces**\r\n\r\nGet the namespaces.\r\n\r\n```php\r\n$namespaces = $entityLocator-\u003egetNamespaces();\r\n```\r\n\r\n**Has Namespace**\r\n\r\nCheck if a namespace exists.\r\n\r\n- `$namespace` is a string representing the namespace.\r\n\r\n```php\r\n$hasNamespace = $entityLocator-\u003ehasNamespace($namespace);\r\n```\r\n\r\n**Map**\r\n\r\nMap an alias to an entity class name.\r\n\r\n- `$alias` is a string representing the alias.\r\n- `$className` is a string representing the entity class name.\r\n\r\n```php\r\n$entityLocator-\u003emap($alias, $className);\r\n```\r\n\r\n**Remove Namespace**\r\n\r\nRemove a namespace.\r\n\r\n- `$namespace` is a string representing the namespace.\r\n\r\n```php\r\n$entityLocator-\u003eremoveNamespace($namespace);\r\n```\r\n\r\n**Set Default Entity Class**\r\n\r\nSet the default entity class name.\r\n\r\n- `$defaultEntityClass` is a string representing the default entity class name.\r\n\r\n```php\r\n$entityLocator-\u003esetDefaultEntityClass($defaultEntityClass);\r\n```\r\n\r\n\r\n## Entities\r\n\r\n```php\r\nuse Fyre\\Entity\\Entity;\r\n```\r\n\r\n- `$data` is an array containing the data for populating the entity.\r\n- `$options` is an array containing the options for creating the entity.\r\n    - `source` is a string representing the entity source, and will default to *null*.\r\n    - `new` is a boolean indicating whether the entity is new, and will default to *true*.\r\n    - `clean` is a boolean indicating whether to clean the entity after init, and will default to *true*.\r\n\r\n```php\r\n$entity = new Entity($data, $options);\r\n```\r\n\r\n**Clean**\r\n\r\nClean the entity.\r\n\r\n```php\r\n$entity-\u003eclean();\r\n```\r\n\r\n**Clear**\r\n\r\nClear values from the entity.\r\n\r\n- `$fields` is an array containing the fields to clear.\r\n\r\n```php\r\n$entity-\u003eclear($fields);\r\n```\r\n\r\n**Extract**\r\n\r\nExtract values from the entity.\r\n\r\n- `$fields` is an array containing the fields to extract.\r\n\r\n```php\r\n$values = $entity-\u003eextract($fields);\r\n```\r\n\r\n**Extract Dirty**\r\n\r\nExtract dirty values from the entity.\r\n\r\n- `$fields` is an array containing the fields to extract.\r\n\r\n```php\r\n$values = $entity-\u003eextractDirty($fields);\r\n```\r\n\r\nIf the `$field` argument is omitted, this method will return all dirty values.\r\n\r\n```php\r\n$values = $entity-\u003eextractDirty();\r\n```\r\n\r\n**Extract Original**\r\n\r\nExtract original values from the entity.\r\n\r\n- `$fields` is an array containing the fields to extract.\r\n\r\n```php\r\n$values = $entity-\u003eextractOriginal($fields);\r\n```\r\n\r\n**Fill**\r\n\r\nFill the entity with values.\r\n\r\n- `$fields` is an array containing the data to fill.\r\n- `$options` is an array containing options for filling the entity.\r\n    - `guard` is a boolean indicating whether to check whether the field is accessible, and will default to *true*.\r\n    - `mutate` is a boolean indicating whether to mutate the value, and will default to *true*.\r\n\r\n```php\r\n$entity-\u003efill($data, $options);\r\n```\r\n\r\nIf 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.\r\n\r\n**Fill Invalid**\r\n\r\nFill the entity with invalid values.\r\n\r\n- `$fields` is an array containing the data to fill.\r\n- `$overwrite` is a boolean indicating whether to overwrite existing values, and will default to *false*.\r\n\r\n```php\r\n$entity-\u003efillInvalid($data, $overwrite);\r\n```\r\n\r\n**Get**\r\n\r\nGet a value from the entity.\r\n\r\n- `$field` is a string representing the field name.\r\n\r\n```php\r\n$value = $entity-\u003eget($field);\r\n```\r\n\r\nAlternatively, you can get a value using the magic `__get` method or array syntax.\r\n\r\n```php\r\n$value = $entity-\u003e$field;\r\n$value = $entity[$field];\r\n```\r\n\r\nIf 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.\r\n\r\n**Get Accessible**\r\n\r\nGet the accessible fields from the entity.\r\n\r\n```php\r\n$accessible = $entity-\u003egetAccessible();\r\n```\r\n\r\n**Get Dirty**\r\n\r\nGet the dirty fields from the entity.\r\n\r\n```php\r\n$dirty = $entity-\u003egetDirty();\r\n```\r\n\r\n**Get Error**\r\n\r\nGet the errors for an entity field.\r\n\r\n- `$field` is a string representing the field name.\r\n\r\n```php\r\n$errors = $entity-\u003egetError($field);\r\n```\r\n\r\n**Get Errors**\r\n\r\nGet all errors for the entity.\r\n\r\n```php\r\n$errors = $entity-\u003egetErrors();\r\n```\r\n\r\n**Get Hidden**\r\n\r\nGet the hidden fields from the entity.\r\n\r\n```php\r\n$hidden = $entity-\u003egetHidden();\r\n```\r\n\r\n**Get Invalid**\r\n\r\nGet invalid value(s) from the entity.\r\n\r\n- `$field` is a string representing the field name.\r\n\r\n```php\r\n$value = $entity-\u003egetInvalid($field);\r\n```\r\n\r\nIf the `$field` argument is omitted, this method will return all invalid values.\r\n\r\n```php\r\n$invalid = $entity-\u003egetInvalid();\r\n```\r\n\r\n**Get Original**\r\n\r\nGet an original value from the entity.\r\n\r\n- `$field` is a string representing the field name.\r\n\r\n```php\r\n$value = $entity-\u003egetOriginal($field);\r\n```\r\n\r\nIf the `$field` argument is omitted, this method will return all original values.\r\n\r\n```php\r\n$original = $entity-\u003egetOriginal();\r\n```\r\n\r\n**Get Source**\r\n\r\nGet the entity source.\r\n\r\n```php\r\n$source = $entity-\u003egetSource();\r\n```\r\n\r\n**Get Virtual**\r\n\r\nGet the virtual fields from the entity.\r\n\r\n```php\r\n$virtual = $entity-\u003egetVirtual();\r\n```\r\n\r\n**Get Visible**\r\n\r\nGet the visible fields from the entity.\r\n\r\n```php\r\n$visible = $entity-\u003egetVisible();\r\n```\r\n\r\n**Has**\r\n\r\nDetermine if an entity value is set.\r\n\r\n- `$field` is a string representing the field name.\r\n\r\n```php\r\n$has = $entity-\u003ehas($field);\r\n```\r\n\r\nAlternatively, you can determine if a value is set using the magic `__isset` method or array syntax.\r\n\r\n```php\r\n$isset = isset($entity-\u003e$field);\r\n$isset = isset($entity[$field]);\r\n```\r\n\r\n**Has Value**\r\n\r\nDetermine if an entity value is not empty.\r\n\r\n- `$field` is a string representing the field name.\r\n\r\n```php\r\n$hasValue = $entity-\u003ehasValue($field);\r\n```\r\n\r\n**Has Errors**\r\n\r\nDetermine if the entity has errors.\r\n\r\n```php\r\n$hasErrors = $entity-\u003ehasErrors();\r\n```\r\n\r\n**Is Accessible**\r\n\r\nDetermine if an entity field is accessible.\r\n\r\n- `$field` is a string representing the field name.\r\n\r\n```php\r\n$isAccessible = $entity-\u003eisAccessible($field);\r\n```\r\n\r\n**Is Dirty**\r\n\r\nDetermine if an entity field is dirty.\r\n\r\n- `$field` is a string representing the field name.\r\n\r\n```php\r\n$isDirty = $entity-\u003eisDirty($field);\r\n```\r\n\r\nIf the `$field` argument is omitted, this method will determine whether the entity has any dirty fields.\r\n\r\n```php\r\n$isDirty = $entity-\u003eisDirty();\r\n```\r\n\r\n**Is Empty**\r\n\r\nDetermine if an entity value is empty.\r\n\r\n- `$field` is a string representing the field name.\r\n\r\n```php\r\n$isEmpty = $entity-\u003eisEmpty($field);\r\n```\r\n\r\nIf the `$field` argument is omitted, this method will determine whether all entity fields are empty.\r\n\r\n```php\r\n$isEmpty = $entity-\u003eisEmpty();\r\n```\r\n\r\n**Is New**\r\n\r\nDetermine if the entity is new.\r\n\r\n```php\r\n$isNew = $entity-\u003eisNew();\r\n```\r\n\r\n**Restore State**\r\n\r\nRestore the saved entity state.\r\n\r\n- `$restoreErrors` is a boolean indicating whether to restore the errors, and will default to *true*.\r\n\r\n```php\r\n$entity-\u003erestoreState($restoreErrors);\r\n```\r\n\r\n**Save State**\r\n\r\nSave the current entity state.\r\n\r\n```php\r\n$entity-\u003esaveState();\r\n```\r\n\r\n**Set**\r\n\r\nSet an entity value.\r\n\r\n- `$field` is a string representing the field name.\r\n- `$value` is the value to set.\r\n- `$options` is an array containing options for filling the entity.\r\n    - `guard` is a boolean indicating whether to check whether the field is accessible, and will default to *true*.\r\n    - `mutate` is a boolean indicating whether to mutate the value, and will default to *true*.\r\n\r\n```php\r\n$entity-\u003eset($field, $value, $options);\r\n```\r\n\r\nAlternatively, you can set a value using the magic `__set` method or array syntax.\r\n\r\n```php\r\n$entity-\u003e$field = $value;\r\n$entity[$field] = $value;\r\n```\r\n\r\nIf 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.\r\n\r\n**Set Access**\r\n\r\nSet whether a field is accessible.\r\n\r\n- `$field` is a string representing the field name.\r\n- `$accessible` is a boolean indicating whether the field is accessible.\r\n\r\n```php\r\n$entity-\u003esetAccess($field, $accessible);\r\n```\r\n\r\n**Set Dirty**\r\n\r\nSet whether a field is dirty.\r\n\r\n- `$field` is a string representing the field name.\r\n- `$dirty` is a boolean indicating whether the field is dirty, and will default to *true*.\r\n\r\n```php\r\n$entity-\u003esetDirty($field, $dirty);\r\n```\r\n\r\n**Set Error**\r\n\r\nSet errors for an entity field.\r\n\r\n- `$field` is a string representing the field name.\r\n- `$error` is a string or array containing the errors.\r\n- `$overwrite` is a boolean indicating whether to overwrite existing errors, and will default to *false*.\r\n\r\n```php\r\n$entity-\u003esetError($field, $error, $ovewrite);\r\n```\r\n\r\n**Set Errors**\r\n\r\nSet all errors for the entity.\r\n\r\n- `$errors` is an array containing the errors.\r\n- `$overwrite` is a boolean indicating whether to overwrite existing errors, and will default to *false*.\r\n\r\n```php\r\n$entity-\u003esetErrors($errors, $overwrite);\r\n```\r\n\r\n**Set Hidden**\r\n\r\nSet hidden fields.\r\n\r\n- `$field` is an array containing the field names.\r\n- `$merge` is a boolean indicating whether to merge with existing fields.\r\n\r\n```php\r\n$entity-\u003esetHidden($fields, $merge);\r\n```\r\n\r\n**Set Invalid**\r\n\r\nSet an invalid value.\r\n\r\n- `$field` is a string representing the field name.\r\n- `$value` is the value to set.\r\n- `$overwrite` is a boolean indicating whether to overwrite existing errors, and will default to *true*.\r\n\r\n```php\r\n$entity-\u003esetInvalid($field, $value, $overwrite);\r\n```\r\n\r\n**Set New**\r\n\r\nSet whether the entity is new.\r\n\r\n- `$new` is a boolean whether the entity is new, and will default to *true*.\r\n\r\n```php\r\n$entity-\u003esetNew($new);\r\n```\r\n\r\n**Set Source**\r\n\r\nSet the entity source.\r\n\r\n- `$source` is a string representing the source.\r\n\r\n```php\r\n$entity-\u003esetSource($source);\r\n```\r\n\r\n**Set Virtual**\r\n\r\nSet virtual fields.\r\n\r\n- `$field` is an array containing the field names.\r\n- `$merge` is a boolean indicating whether to merge with existing fields.\r\n\r\n```php\r\n$entity-\u003esetVirtual($fields, $merge);\r\n```\r\n\r\n**To Array**\r\n\r\nConvert the entity to an array.\r\n\r\n```php\r\n$array = $entity-\u003etoArray();\r\n```\r\n\r\n**To JSON**\r\n\r\nConvert the entity to a JSON string.\r\n\r\n```php\r\n$json = $entity-\u003etoJson();\r\n```\r\n\r\nAlternatively, you can cast the value to a string using the magic `__toString` method.\r\n\r\n```php\r\n$json = (string) $entity;\r\n```\r\n\r\n**Unset**\r\n\r\nUnset an entity value.\r\n\r\n- `$field` is a string representing the field name.\r\n\r\n```php\r\n$entity-\u003eunset($field);\r\n```\r\n\r\nAlternatively, you can unset a value using the magic `__unset` method or array syntax.\r\n\r\n```php\r\nunset($entity-\u003e$field);\r\nunset($entity[$field]);\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyreentity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felusivecodes%2Ffyreentity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felusivecodes%2Ffyreentity/lists"}