Skip to content

Commit

Permalink
fix: all() function now returns array of objects
Browse files Browse the repository at this point in the history
  • Loading branch information
xchopin committed Jun 18, 2019
1 parent 74d8179 commit d77cc8e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Model/OneRoster.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ abstract class OneRoster extends Model

protected static $collection;


/**
* @return array
*/
Expand All @@ -35,8 +36,8 @@ protected static function generateHeader(): array
}

return [
'X-Requested-With' => 'XMLHttpRequest',
'Authorization' => "Bearer $jwt"
'X-Requested-With' => 'XMLHttpRequest',
'Authorization' => "Bearer $jwt"
];
}

Expand All @@ -47,13 +48,24 @@ public static function find($id)
return new static((array)$json);
}

public static function getClassName(){
return (new \ReflectionClass(get_called_class()))->getShortName();
}

protected static function extract($object)
{
$name = mb_strtolower(self::getClassName());
return $object->$name;
}

public static function all()
{
$header = self::generateHeader();
$json_array = OpenLRW::httpGet(self::PREFIX . static::$collection, $header);
$results = [];
foreach ($json_array as $json) {
$results[] = new static((array)$json);
$object = self::extract($json);
$results[] = new static((array)$object);;
}

return $results;
Expand Down

0 comments on commit d77cc8e

Please sign in to comment.