1 | <?php |
||
8 | class Repository extends Collection |
||
9 | { |
||
10 | /** |
||
11 | * Creates an \Burthorpe\Runescape\RS3\Stats\Repository instance from a raw feed directly from Jagex |
||
12 | * |
||
13 | * @param $rawFeed string Raw feed directly from Jagex |
||
14 | * @return \Burthorpe\Runescape\RS3\Stats\Repository |
||
15 | */ |
||
16 | 4 | public static function factory($rawFeed) |
|
17 | { |
||
18 | 4 | $repository = new static; |
|
19 | 4 | $skills = new SkillsRepository(); |
|
20 | |||
21 | 4 | $exploded = explode("\n", $rawFeed); |
|
22 | |||
23 | 4 | $spliced = array_splice( |
|
24 | 4 | $exploded, |
|
25 | 4 | 0, |
|
26 | 4 | $skills->count() |
|
27 | 4 | ); |
|
28 | |||
29 | 4 | for ($id = 0; $id < count($spliced); $id++) { |
|
30 | 4 | list($rank, $level, $experience) = explode(',', $spliced[$id]); |
|
31 | 4 | $skill = $skills->find($id); |
|
32 | |||
33 | 4 | $repository->push( |
|
34 | 4 | new Stat( |
|
35 | 4 | $skill, |
|
36 | 4 | $level, |
|
37 | 4 | $rank, |
|
38 | $experience |
||
39 | 4 | ) |
|
40 | 4 | ); |
|
41 | 4 | } |
|
42 | |||
43 | 4 | return $repository; |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * Find a stat by the given skill ID |
||
48 | * |
||
49 | * @param $id |
||
50 | * @return \Burthorpe\Runescape\RS3\Stats\Contract|null |
||
51 | */ |
||
52 | public function find($id) |
||
58 | |||
59 | /** |
||
60 | * Find a stat by the given skill name |
||
61 | * |
||
62 | * @param $name |
||
63 | * @return \Burthorpe\Runescape\RS3\Stats\Contract|null |
||
64 | */ |
||
65 | public function findByName($name) |
||
71 | |||
72 | /** |
||
73 | * Find a stat by the given skill class |
||
74 | * |
||
75 | * @param $class |
||
76 | * @return \Burthorpe\Runescape\RS3\Stats\Contract|null |
||
77 | */ |
||
78 | public function findByClass($class) |
||
84 | } |
||
85 |