Skip to content

Commit

Permalink
Refactor env ID generation
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Jan 26, 2016
1 parent 580e48f commit 8d5d509
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Concurrent/Internal/FileTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,17 @@ 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()];
}

if (!isset($this->args[0])) {
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.');
Expand Down Expand Up @@ -107,6 +104,16 @@ public function run(Environment $environment)
}
}

/**
* @param int $id
*
* @return string
*/
private function makeId($id)
{
return '__file_' . $id;
}

/**
* @param string $path
*
Expand Down

0 comments on commit 8d5d509

Please sign in to comment.