{"id":22116214,"url":"https://github.com/nick-denry/managed-constant-models","last_synced_at":"2026-05-10T09:40:23.320Z","repository":{"id":52567302,"uuid":"361520260","full_name":"nick-denry/managed-constant-models","owner":"nick-denry","description":"Allow to declare constants with named attributes via standalone PHP class model","archived":false,"fork":false,"pushed_at":"2021-05-25T13:32:29.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-29T11:22:57.998Z","etag":null,"topics":["constants","label","laravel","library","models","organize","php","yii2"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nick-denry.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-25T19:32:18.000Z","updated_at":"2021-05-28T22:08:55.000Z","dependencies_parsed_at":"2022-09-22T14:25:03.344Z","dependency_job_id":null,"html_url":"https://github.com/nick-denry/managed-constant-models","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nick-denry%2Fmanaged-constant-models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nick-denry%2Fmanaged-constant-models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nick-denry%2Fmanaged-constant-models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nick-denry%2Fmanaged-constant-models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nick-denry","download_url":"https://codeload.github.com/nick-denry/managed-constant-models/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245216577,"owners_count":20579184,"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":["constants","label","laravel","library","models","organize","php","yii2"],"created_at":"2024-12-01T12:19:59.527Z","updated_at":"2026-05-10T09:40:23.312Z","avatar_url":"https://github.com/nick-denry.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003ePHP Managed constant models\u003c/h1\u003e\nAllow to declare constants with named attributes via standalone class model\n\n[![Latest Stable Version](https://poser.pugx.org/nick-denry/managed-constant-models/version)](https://packagist.org/packages/nick-denry/managed-constant-models) [![Total Downloads](https://poser.pugx.org/nick-denry/managed-constant-models/downloads)](https://packagist.org/packages/nick-denry/managed-constant-models) [![Latest Unstable Version](https://poser.pugx.org/nick-denry/managed-constant-models/v/unstable)](//packagist.org/packages/nick-denry/managed-constant-models) [![License](https://poser.pugx.org/nick-denry/managed-constant-models/license)](https://packagist.org/packages/nick-denry/managed-constant-models)\n\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist nick-denry/managed-constant-models\n```\n\nor add\n\n```\n\"nick-denry/managed-constant-models\": \"^0.1.1\"\n```\n\nto the require section of your `composer.json` file.\n\nUsage\n-----\n\n\n1. Create managed constats model\n\n    ```php\n    \u003c?php\n\n    namespace app\\models;\n\n    use nickdenry\\managedConstants\\interfaces\\ManagedConstantInterface;\n    use nickdenry\\managedConstants\\traits\\ManagedConstantTrait;\n\n    /**\n    * TaskStatus constant model\n    */\n    class TaskStatus implements ManagedConstantInterface\n    {\n\n        use ManagedConstantTrait;\n\n        const ACTIVE = 0;\n        const DONE = 1;\n        const _ATTRIBUTES = [\n            self::ACTIVE =\u003e [\n                'class' =\u003e 'task-active',\n                'label' =\u003e 'Активна',\n            ],\n            self::DONE =\u003e [\n                'class' =\u003e 'task-done',\n                'label' =\u003e 'Завершена',\n            ],\n        ];\n\n    }\n\n    ```\n\n2. Use it with your another model class, i.e. yii2 model\n\n\n    ```php\n    \u003c?php\n\n    namespace app\\models;\n\n    use app\\models\\TaskStatus;\n\n    /**\n    * This is the model class for table \"task\".\n    *\n    * @property int $id\n    * @property string $title\n    * @property int|null $created_at\n    * @property int|null $updated_at\n    */\n    class Task extends \\yii\\db\\ActiveRecord\n    {\n        ...\n        /**\n        * Get task statuses.\n        */\n        public static function getStatuses()\n        {\n            return new TaskStatus(); //TaskStatus()::class;\n        }\n        ...\n\n    }\n\n-----\n\n3. Get constatns with the code\n\n\n    ```php\n    \u003c?php\n\n    $constValue = Task::getStatuses()::ACTIVE; //$constValue = 0;\n\n    Task::getStatuses()::ACTIVE; // ACTIVE constant;\n    Task::getStatuses()::DONE; // DONE constant;\n    Task::getStatuses()::constants(); // Returns array ['ACTIVE' =\u003e 0, 'DONE' =\u003e 1]\n    Task::getStatuses()::values(); // Returns array [0, 1]\n    Task::getStatuses()::listAttributes($constValue); // Returns array ['class' =\u003e 'task-active', 'label' =\u003e 'Активна']\n    Task::getStatuses()::attribute($constValue, 'class'); // Returns 'task-active'\n\n    Task::getStatuses()::getList();\n    // Returns [\n    //    ['id' =\u003e 0, 'class' =\u003e 'task-active', 'label' =\u003e 'Активна', ]\n    //    ['id' =\u003e 1, 'class' =\u003e 'task-done', 'label' =\u003e 'Завершена', ],\n    // ]\n\n    ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnick-denry%2Fmanaged-constant-models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnick-denry%2Fmanaged-constant-models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnick-denry%2Fmanaged-constant-models/lists"}