From 8d5d5092aa6015d198bde580426935f88a45e05f Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Tue, 26 Jan 2016 11:47:53 -0600 Subject: [PATCH] Refactor env ID generation --- src/Concurrent/Internal/FileTask.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Concurrent/Internal/FileTask.php b/src/Concurrent/Internal/FileTask.php index 61410d7..e889cea 100644 --- a/src/Concurrent/Internal/FileTask.php +++ b/src/Concurrent/Internal/FileTask.php @@ -44,12 +44,9 @@ public function run(Environment $environment) { if ('f' === $this->operation[0]) { if ('fopen' === $this->operation) { - if ($environment->exists($this->args[0])) { - throw new FileException('The file handle has already been opened on the worker.'); - } $file = new File($this->args[0], $this->args[1]); $id = $file->getId(); - $environment->set('file' . $id, $file); + $environment->set($this->makeId($id), $file); return [$id, $file->stat()['size'], $file->inAppendMode()]; } @@ -57,7 +54,7 @@ public function run(Environment $environment) throw new FileException('No file ID provided.'); } - $id = 'file' . array_shift($this->args); + $id = $this->makeId(array_shift($this->args)); if (!$environment->exists($id)) { throw new FileException('No file handle with the given ID has been opened on the worker.'); @@ -107,6 +104,16 @@ public function run(Environment $environment) } } + /** + * @param int $id + * + * @return string + */ + private function makeId($id) + { + return '__file_' . $id; + } + /** * @param string $path *