Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Removes fluent getter/setter and caches results for origin and hasOrigin #9639

Merged
merged 8 commits into from
Mar 25, 2024
39 changes: 19 additions & 20 deletions src/Data/HasOrigin.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,25 @@ public function value($key)

public function origin($origin = null)
{
return $this->fluentlyGetOrSet('origin')
->getter(function ($origin) {
if (! $origin) {
return null;
}

if ($found = Blink::get($this->getOriginBlinkKey())) {
return $found;
}

return tap($this->getOriginByString($origin), function ($found) {
Blink::put($this->getOriginBlinkKey(), $found);
});
})
->setter(function ($origin) {
Blink::forget($this->getOriginBlinkKey());

return is_object($origin) ? $this->getOriginIdFromObject($origin) : $origin;
})
->args(func_get_args());
if (func_num_args() === 0) {
if (! $this->origin) {
return null;
}

if ($found = Blink::get($this->getOriginBlinkKey())) {
return $found;
}

return tap($this->getOriginByString($this->origin), function ($found) {
Blink::put($this->getOriginBlinkKey(), $found);
});
}

Blink::forget($this->getOriginBlinkKey());

$this->origin = is_object($origin) ? $this->getOriginIdFromObject($origin) : $origin;

return $this;
}

abstract public function getOriginByString($origin);
Expand Down
Loading