Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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' => 'Завершена', ],
// ]

```