{"id":20156044,"url":"https://github.com/max-kut/model-entities","last_synced_at":"2025-03-03T01:44:42.219Z","repository":{"id":62525660,"uuid":"239313266","full_name":"max-kut/model-entities","owner":"max-kut","description":null,"archived":false,"fork":false,"pushed_at":"2020-04-10T16:09:19.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-13T12:48:39.861Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/max-kut.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}},"created_at":"2020-02-09T13:56:21.000Z","updated_at":"2020-04-10T16:09:22.000Z","dependencies_parsed_at":"2022-11-02T14:01:22.203Z","dependency_job_id":null,"html_url":"https://github.com/max-kut/model-entities","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max-kut%2Fmodel-entities","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max-kut%2Fmodel-entities/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max-kut%2Fmodel-entities/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/max-kut%2Fmodel-entities/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/max-kut","download_url":"https://codeload.github.com/max-kut/model-entities/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241596241,"owners_count":19988041,"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":[],"created_at":"2024-11-13T23:37:20.795Z","updated_at":"2025-03-03T01:44:42.190Z","avatar_url":"https://github.com/max-kut.png","language":"PHP","readme":"#PHP обертка над `json`-данными\n\nСлужит для более управляемой и документированной работы с данными json-полей моделей или ответов различных API\n\n###Установка\n`composer require maxkut/model-entities`\n\n###Концепция\nБиблиотека включает два абстрактных класса `\\Entities\\Entity` и `\\Entities\\EntityCollection\n`, которые содержат вспомогательные методы для типизации свойств конечных объектов.\nОчень важно документировать свойства создаваемых классов. Так Вы не забудете, какие свойства есть у того или иного объекта. В примере ниже задокументированы свойства класса Settings в PhpDoc. Плюс Ваша ide будет вам помогать с подсказками.\n\n###Пример\n```PHP\n// Как пример сложных json полей модели App\\Models\\User\nnamespace App\\Models\\Entities\\User;\nuse Entities\\Entity;\n/**\n * Class Settings\n * @property bool $property1\n * @property int $property2\n * @property array $property3\n */\nclass Settings extends Entity\n{\n    /**\n     * @var bool $strictParams - если true, \n     * то любые свойства, которые не объявлены в $attributes, $casts\n или для него нет акцессора/мутатора \n     * вызовут исключение Entities\\Exceptions\\NotDefinedPropertyException\n     */\n    public $strictParams = true;\n\n    protected $attributes = [\n        'property1' =\u003e null,\n        'property2' =\u003e null,\n        'property3' =\u003e null,\n    ];\n\n    protected $casts = [\n        'property1' =\u003e 'bool',\n        'property2' =\u003e 'int',\n        'property3' =\u003e 'array',\n    ];\n}\n\n///////////////////////////////////////////\n/// На примере моделей Eloquent ORM \n/// надо создать методы преобразования (акцессор и мутатор) для этого поля\n\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Model;\nuse App\\Models\\Entities\\User\\Settings;\n\nclass User extends Model\n{\n    //...\n    \n    protected function getSettingsAttribute($value){\n        return Settings::make($value);\n    }\n    \n    protected function setSettingsAttribute($value){\n        $this-\u003eattributes['settings'] =  Settings::make($value)-\u003etoJson();\n    }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmax-kut%2Fmodel-entities","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmax-kut%2Fmodel-entities","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmax-kut%2Fmodel-entities/lists"}