Skip to content

Commit af365e3

Browse files
author
Kevin Buchholz
authored
Feature/improve readme (#11)
Feature/improve readme
2 parents 6c4de74 + e63742a commit af365e3

22 files changed

+1529
-12
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
[![Packagist downloads](https://img.shields.io/packagist/dt/sourceboat/laravel-enumeration.svg?style=flat-square)](https://packagist.org/packages/sourceboat/laravel-enumeration)
77
[![MIT Software License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.md)
88

9-
Strongly typed enum implementation for Laravel. Based on [eloquent/enumeration](https://github.com/eloquent/enumeration) and inspired by [bensampo/laravel-enum](https://github.com/bensampo/laravel-enum)
9+
Enum implementation for Laravel. Based on [eloquent/enumeration](https://github.com/eloquent/enumeration) and inspired by [bensampo/laravel-enum](https://github.com/bensampo/laravel-enum)
1010

1111
## Features
1212

13-
* Strongly typed
1413
* Key/value-definition via class constants
1514
* Full featured suite of methods
1615
* Enum artisan generator
1716
* Validation rules for passing enum values as input parameters
1817
* Localization support
19-
* Extendible
18+
* Extensible
2019

2120
## Table of Contents
2221

@@ -41,10 +40,12 @@ Strongly typed enum implementation for Laravel. Based on [eloquent/enumeration](
4140
Via Composer
4241

4342
``` bash
43+
4444
$ composer require sourceboat/laravel-enumeration
4545
```
4646

4747
If you're using Laravel < 5.5 you'll need to add the service provider to `config/app.php`
48+
4849
``` php
4950
'Sourceboat\Enumeration\EnumerationServiceProvider'
5051
```
@@ -58,6 +59,7 @@ php artisan make:enum UserType
5859
## Usage
5960

6061
Given the following enum:
62+
6163
``` php
6264
<?php
6365

@@ -81,6 +83,7 @@ final class UserType extends Enumeration
8183
```
8284

8385
Values can now be accessed like so:
86+
8487
``` php
8588
UserType::Moderator() // Returns an instance of UserType with UserType::Moderator()->value === 1
8689
```
@@ -190,6 +193,7 @@ UserType::toLocalizedSelectArray(); // Returns [0 => 'Administrator', 1 => 'Mode
190193
## Validation
191194

192195
### Array Validation
196+
193197
You may validate that a value passed to a controller is a valid value for a given enum by using the `EnumerationValue` rule, for easier handling there are helper methods for creating the rule: `Enumeration::makeRule()`, `Enumeration::makeRuleWithWhitelist($whitelist)` and `Enumeration::makeRuleWithBlacklist($blacklist)`.
194198

195199
``` php
@@ -330,8 +334,3 @@ Much of the functionality in this Package is inspired by [bensampo/laravel-enum]
330334
- [laravel/framework](https://github.com/laravel/framework) is licensed under MIT
331335

332336
This package is also licensed under the MIT license.
333-
334-
## TODOs
335-
336-
* [x] Tests for all enumeration-functions and the rule.
337-
* [x] Model-Trait to enable casting of enumerations and "on the fly"-validation for enumeration values on models.

src/Enums/Interfaces/Weighted.php

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<?php
2+
3+
namespace Sourceboat\Enumeration\Enums\Interfaces;
4+
5+
use Eloquent\Enumeration\EnumerationInterface;
6+
7+
/**
8+
* Defines the interface for weighted enums.
9+
*/
10+
interface Weighted extends EnumerationInterface
11+
{
12+
/**
13+
* Get members of this enum greater than $weighted.
14+
*
15+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $weighted
16+
* @return array
17+
*/
18+
public static function getMembersGreaterThan(Weighted $weighted): array;
19+
20+
/**
21+
* Get members of this enum greater than or equal to $weighted.
22+
*
23+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $weighted
24+
* @return array
25+
*/
26+
public static function getMembersGreaterThanOrEqualTo(Weighted $weighted): array;
27+
28+
/**
29+
* Get members of this enum equal to $weighted.
30+
*
31+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $weighted
32+
* @return array
33+
*/
34+
public static function getMembersEqualTo(Weighted $weighted): array;
35+
36+
/**
37+
* Get members of this enum less than or equal to $weighted.
38+
*
39+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $weighted
40+
* @return array
41+
*/
42+
public static function getMembersLessThanOrEqualTo(Weighted $weighted): array;
43+
44+
/**
45+
* Get members of this enum less than or equal to $weighted.
46+
*
47+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $weighted
48+
* @return array
49+
*/
50+
public static function getMembersLessThan(Weighted $weighted): array;
51+
52+
/**
53+
* Get members of this enum between the given members weights.
54+
*
55+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $lower
56+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $higher
57+
* @return array
58+
*/
59+
public static function getMembersBetween(Weighted $lower, Weighted $higher): array;
60+
61+
/**
62+
* Get members of this enum between or equal to the given members weights.
63+
*
64+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $lower
65+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $higher
66+
* @return array
67+
*/
68+
public static function getMembersBetweenOrEqualTo(Weighted $lower, Weighted $higher): array;
69+
70+
/**
71+
* Get members of this enum greater than this.
72+
*
73+
* @return array
74+
*/
75+
public function getMembersGreaterThanThis(): array;
76+
77+
/**
78+
* Get members of this enum greater than or queal to this.
79+
*
80+
* @return array
81+
*/
82+
public function getMembersGreaterThanOrEqualToThis(): array;
83+
84+
/**
85+
* Get members of this enum equal to this.
86+
*
87+
* @return array
88+
*/
89+
public function getMembersEqualToThis(): array;
90+
91+
/**
92+
* Get members of this enum less than or equal to this.
93+
*
94+
* @return array
95+
*/
96+
public function getMembersLessThanOrEqualToThis(): array;
97+
98+
/**
99+
* Get members of this enum less than this.
100+
*
101+
* @return array
102+
*/
103+
public function getMembersLessThanThis(): array;
104+
105+
/**
106+
* Get members of this enum between this and the given higher bound.
107+
*
108+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $higher
109+
* @return array
110+
*/
111+
public function getMembersBetweenThisAnd(Weighted $higher): array;
112+
113+
/**
114+
* Get members of this enum between or equal to this and the given higher bound.
115+
*
116+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $higher
117+
* @return array
118+
*/
119+
public function getMembersBetweenOrEqualToThisAnd(Weighted $higher): array;
120+
121+
/**
122+
* The weight of this enum member.
123+
*
124+
* @return int|float
125+
*/
126+
public function weight();
127+
128+
/**
129+
* Determine if this members weight is greater than the given members weight.
130+
*
131+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $member
132+
* @return bool
133+
*/
134+
public function isGreaterThan(Weighted $member): bool;
135+
136+
/**
137+
* Determine if this members weight is greater or equal than the given members weight.
138+
*
139+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $member
140+
* @return bool
141+
*/
142+
public function isGreaterThanOrEqualTo(Weighted $member): bool;
143+
144+
/**
145+
* Determine if this members weight is equal to the given members weight.
146+
*
147+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $member
148+
* @return bool
149+
*/
150+
public function isEqualTo(Weighted $member): bool;
151+
152+
/**
153+
* Determine if this members weight is less than the given members weight.
154+
*
155+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $member
156+
* @return bool
157+
*/
158+
public function isLessThan(Weighted $member): bool;
159+
160+
/**
161+
* Determine if this members weight is less than or euqal to the given members weight.
162+
*
163+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $member
164+
* @return bool
165+
*/
166+
public function isLessThanOrEqualTo(Weighted $member): bool;
167+
168+
/**
169+
* Determine if this members weight is between the given members weight.
170+
*
171+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $lower
172+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $higher
173+
* @return bool
174+
*/
175+
public function isBetween(Weighted $lower, Weighted $higher): bool;
176+
177+
/**
178+
* Determine if this members weight is between or equal to the given members weight.
179+
*
180+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $lower
181+
* @param \Sourceboat\Enumeration\Enums\Interfaces\Weighted $higher
182+
* @return bool
183+
*/
184+
public function isBetweenOrEqualTo(Weighted $lower, Weighted $higher): bool;
185+
}

0 commit comments

Comments
 (0)