@@ -8,15 +8,7 @@ Provides an easy way to get some entity/model behavior with static data
88
99### Add the package in your composer.json
1010
11- ``` json
12- {
13- "require" : {
14- "byscripts/static-entity" : " ~1.0"
15- }
16- }
17- ```
18-
19- Then run ` composer update ` (or ` composer update byscripts/static-entity ` if you don't want to update all your packages)
11+ At command line, run ` composer require byscripts/static-entity:~2.0 `
2012
2113### Usage
2214
@@ -122,28 +114,35 @@ $firefox->is(WebBrowser::FIREFOX); // true
122114WebBrowser::toId($firefox); // 2
123115WebBrowser::toId(2); // 2
124116
125- // The getIds() returns an array of ... well, ids.
117+ // The getIds() method returns an array of all ids present in data set
126118WebBrowser::getIds(); // [1, 2, 3, 4, 5]
127119
128120// The getAssoc() returns an associative array with `id` as key and `name` as value
129- WebBrowser::getAssoc (); // [1 => 'Chromium', 2 => 'Firefox', ...]
121+ WebBrowser::getAssociative (); // [1 => 'Chromium', 2 => 'Firefox', ...]
130122
131123// You can also pass the name of an argument you want to use as value
132- WebBrowser::getAssoc ('brand'); // [1 => 'Google', 2 => 'Mozilla', 3 => 'Microsoft', ...]
124+ WebBrowser::getAssociative ('brand'); // [1 => 'Google', 2 => 'Mozilla', 3 => 'Microsoft', ...]
133125
134- // The getAll() method return an array containing all instances of entities
126+ // The getAll() method returns an array containing all instances of entities
135127WebBrowser::getAll(); // [Object, Object, ...]
136128
137129// The exists() method check whether the passed ID exists in data set
138- WebBrowser::exists (3); // true
139- WebBrowser::exists (9); // false
130+ WebBrowser::hasId (3); // true
131+ WebBrowser::hasId (9); // false
140132```
141133
142134#### Alternative usage
143135
144- All static methods can be called indirectly from StaticEntity class by passing the desired class as last method argument.
136+ You can also directly use the StaticEntityBuilder to achieve same result
145137
146138```
147- StaticEntity::get(2, 'WebBrowser');
148- StaticEntity::getAssoc('brand', 'WebBrowser');
139+ $builder = new StaticEntityBuilder('WebBrowser');
140+
141+ $builder->get(WebBrowser::FIREFOX);
142+ $builder->getAssociative();
143+ $builder->getAssociative('other');
144+ $builder->getIds();
145+ $builder->getAll();
146+ $builder->hasId(WebBrowser::CHROMIUM);
147+ $builder->convertToId($instance);
149148```
0 commit comments