Skip to content

Commit

Permalink
Simplify Memory::loadData()
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Sep 30, 2024
1 parent d2881dd commit 127ccdb
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/Boot/src/Memory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,28 @@ public function loadData(string $section, string &$filename = null): mixed
return null;
}

$fp = false;
$lock = false;

try {
$fp = \fopen($filename, 'r');
if ($fp === false) {
return null;
}

if (!\flock($fp, \LOCK_SH | \LOCK_NB)) {
\fclose($fp);
$lock = \flock($fp, \LOCK_SH | \LOCK_NB);

if ($lock === false) {
return null;
}

$data = include($filename);

\flock($fp, \LOCK_UN);
return include($filename);
} catch (\Throwable) {
return null;
} finally {
if (isset($fp)) {
\fclose($fp);
}
$lock === false or \flock($fp, \LOCK_UN);
$fp === false or \fclose($fp);
}

return $data;
}

public function saveData(string $section, mixed $data): void
Expand Down

0 comments on commit 127ccdb

Please sign in to comment.