sync ordering

This commit is contained in:
Maxime Renou 2020-05-12 16:02:34 +02:00
parent 807d12a2b5
commit 911045cdd2
1 changed files with 21 additions and 2 deletions

View File

@ -14,6 +14,14 @@ use Psr\Http\Message\StreamInterface;
class Connect class Connect
{ {
protected static $resources = [
'Role',
'Company',
'Team',
'User',
'UserTeam'
];
protected $app; protected $app;
protected $synchronized = []; protected $synchronized = [];
@ -26,7 +34,7 @@ class Connect
public function setSynchronized($models) public function setSynchronized($models)
{ {
$this->synchronized = []; $items = [];
foreach ($models as $model) foreach ($models as $model)
{ {
@ -36,8 +44,19 @@ class Connect
$class = explode('\\', $model); $class = explode('\\', $model);
$resource = $model::$connectResource ?? end($class); $resource = $model::$connectResource ?? end($class);
$this->synchronized[$resource] = $model; $items[$resource] = $model;
} }
$synchronized = [];
foreach (self::$resources as $resourceType) { // Re-ordering
foreach ($items as $resource => $model) {
if ($resource == $resourceType)
$synchronized[$resource] = $model;
}
}
$this->synchronized = $synchronized;
} }
// API // API