Skip to content

Commit 8a1c2f0

Browse files
committed
First commit of v3
1 parent d55e244 commit 8a1c2f0

20 files changed

+2077
-926
lines changed

.travis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
language: php
22
php:
3-
- 5.3
4-
- 5.4
5-
- 5.5
6-
- 5.6
7-
- hhvm
3+
- 7.1
4+
- 7.2
5+
- 7.3
86

97
before_script:
108
- composer install --dev

README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ Provides an easy way to get some entity/model behavior with static data
1010

1111
### Add the package in your composer.json
1212

13-
At command line, run `composer require byscripts/static-entity:~2.0`
13+
At command line, run `composer require byscripts/static-entity:~3.0`
1414

1515
### Usage
1616

1717
#### Create your static entity
1818

1919
```php
20-
use Byscripts\StaticEntity\StaticEntity;
20+
<?php
21+
use Byscripts\StaticEntity\AbstractStaticEntity;
2122

22-
class WebBrowser extends StaticEntity
23+
class WebBrowser extends AbstractStaticEntity
2324
{
2425
const CHROMIUM = 1;
2526
const FIREFOX = 2;
@@ -52,7 +53,7 @@ class WebBrowser extends StaticEntity
5253
return $this->license;
5354
}
5455

55-
static public function getDataSet()
56+
static public function getDataSet(): array
5657
{
5758
return [
5859
self::CHROMIUM => [
@@ -93,6 +94,8 @@ class WebBrowser extends StaticEntity
9394
#### Play with it
9495

9596
```php
97+
<?php
98+
9699
// Get an instance of WebBrowser, hydrated with Firefox data
97100
$firefox = WebBrowser::get(WebBrowser::FIREFOX);
98101

@@ -106,10 +109,6 @@ $firefox->getId(); // 2
106109
// Other methods are ones implemented in the static entity
107110
$firefox->getName(); // Firefox
108111

109-
// The is() method check the argument against the instance ID
110-
$firefox->is(WebBrowser::CHROMIUM); // false
111-
$firefox->is(WebBrowser::FIREFOX); // true
112-
113112
// The toId() method transform an entity to ID.
114113
// If an id is passed, it is returned as is, after checking it exists.
115114
// The method is mainly intended for a setter method to accept both type.
@@ -135,16 +134,20 @@ WebBrowser::hasId(9); // false
135134

136135
#### Alternative usage
137136

138-
You can also use the StaticEntityBuilder class
137+
You can also use the `Provider` class.
138+
139+
In this case, your entity is not required to extends `AbstractStaticEntity`,
140+
but still needs to implements `StaticEntityInterface`
139141

140142
```php
141-
$builder = new StaticEntityBuilder('WebBrowser');
142-
143-
$builder->get(WebBrowser::FIREFOX);
144-
$builder->getAssociative();
145-
$builder->getAssociative('other');
146-
$builder->getIds();
147-
$builder->getAll();
148-
$builder->hasId(WebBrowser::CHROMIUM);
149-
$builder->convertToId($instance);
143+
<?php
144+
use Byscripts\StaticEntity\Provider;
145+
146+
Provider::get(WebBrowser::class, WebBrowser::FIREFOX);
147+
Provider::getAssociative(WebBrowser::class);
148+
Provider::getAssociative(WebBrowser::class, 'otherKey');
149+
Provider::getIds(WebBrowser::class);
150+
Provider::getAll(WebBrowser::class);
151+
Provider::hasId(WebBrowser::class, WebBrowser::CHROMIUM);
152+
Provider::toId(WebBrowser::class, $instanceOrId);
150153
```

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=5.3.0"
13+
"php": ">=7.1.0"
1414
},
1515
"autoload": {
1616
"psr-4": {
@@ -21,5 +21,8 @@
2121
"psr-4": {
2222
"Byscripts\\StaticEntity\\Tests\\": "tests/"
2323
}
24+
},
25+
"require-dev": {
26+
"phpunit/phpunit": "^7.4"
2427
}
2528
}

0 commit comments

Comments
 (0)