Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nick-denry/managed-constant-models
Allow to declare constants with named attributes via standalone PHP class model
https://github.com/nick-denry/managed-constant-models
constants label laravel library models organize php yii2
Last synced: about 1 month ago
JSON representation
Allow to declare constants with named attributes via standalone PHP class model
- Host: GitHub
- URL: https://github.com/nick-denry/managed-constant-models
- Owner: nick-denry
- License: mit
- Created: 2021-04-25T19:32:18.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-25T13:32:29.000Z (over 3 years ago)
- Last Synced: 2024-11-25T00:13:42.890Z (about 1 month ago)
- Topics: constants, label, laravel, library, models, organize, php, yii2
- Language: PHP
- Homepage:
- Size: 30.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PHP Managed constant models
Allow to declare constants with named attributes via standalone class model[![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)
Installation
------------The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require --prefer-dist nick-denry/managed-constant-models
```or add
```
"nick-denry/managed-constant-models": "^0.1.0"
```to the require section of your `composer.json` file.
Usage
-----1. Create managed constats model
```php
[
'class' => 'task-active',
'label' => 'Активна',
],
self::DONE => [
'class' => 'task-done',
'label' => 'Завершена',
],
];}
```
2. Use it with your another model class, i.e. yii2 model
```php
0, 'DONE' => 1]
Task::getStatuses()::values(); // Returns array [0, 1]
Task::getStatuses()::listAttributes($constValue); // Returns array ['class' => 'task-active', 'label' => 'Активна']
Task::getStatuses()::attribute($constValue, 'class'); // Returns 'task-active'Task::getStatuses()::getList();
// Returns [
// ['id' => 0, 'class' => 'task-active', 'label' => 'Активна', ]
// ['id' => 1, 'class' => 'task-done', 'label' => 'Завершена', ],
// ]```