Skip to content

Commit

Permalink
instance based mapper space casting
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Oct 21, 2024
1 parent 3a3100d commit c6ec472
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/Temporal.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function getEntityId(string $name): int
return $this->findOrCreate(Entity::class, ['name' => $name])->id;
}

public function getSpace(string $name): Space
public function getSpace(object|int|string $id): Space
{
return $this->mapper->getSpace($name);
return $this->mapper->getSpace($id);
}

public function hasSpace(string $class): bool
Expand Down Expand Up @@ -337,9 +337,7 @@ public function setLinkIdle(int $id, bool $flag): void
return;
}

$this->mapper->update(Link::class, $link, [
'idle' => $link->idle ? 0 : time()
]);
$this->mapper->update($link, ['idle' => $link->idle ? 0 : time()]);

$this->aggregator->updateLinkAggregation($link);
}
Expand Down Expand Up @@ -368,9 +366,7 @@ public function setReferenceIdle(
return;
}

$this->mapper->update(Reference::class, $reference, [
'idle' => $reference->idle ? 0 : time()
]);
$this->mapper->update($reference, ['idle' => $reference->idle ? 0 : time()]);

$this->aggregator->updateReferenceState($reference->entity, $id, $reference->target);
}
Expand All @@ -395,7 +391,7 @@ public function setOverrideIdle(
return;
}

$this->mapper->update(Override::class, $override, ['idle' => $flag ? time() : 0]);
$this->mapper->update($override, ['idle' => $flag ? time() : 0]);

$this->aggregator->updateOverrideAggregation($override->entity, $override->id);
}
Expand All @@ -421,9 +417,7 @@ public function setReferenceEnd(
]);

if ($reference->end != $end) {
$this->mapper->update(Reference::class, $reference, [
'end' => $end,
]);
$this->mapper->update($reference, ['end' => $end]);
$this->aggregator->updateReferenceState($reference->entity, $id, $target);
}
}
Expand All @@ -445,7 +439,7 @@ public function setOverrideEnd(
]);

if ($override->end != $end) {
$this->mapper->update(Override::class, $override, ['end' => $end]);
$this->mapper->update($override, ['end' => $end]);
$this->aggregator->updateOverrideAggregation($entity, $id);
}
}
Expand Down Expand Up @@ -493,17 +487,15 @@ public function link(array $link): void
throw new Exception("Invalid link configuration");
}

$this->mapper->update(Link::class, $node, [
$this->mapper->update($node, [
'begin' => $link['begin'],
'end' => $link['end'],
'actor' => $this->actor,
'timestamp' => Carbon::now()->timestamp,
]);

if (array_key_exists('data', $link)) {
$this->mapper->update(Link::class, $node, [
'data' => $link['data'],
]);
$this->mapper->update($node, ['data' => $link['data']]);
}

$this->aggregator->updateLinkAggregation($node);
Expand Down

0 comments on commit c6ec472

Please sign in to comment.