filesystem = $filesystem; $this->tmpPath = $tmpPath; if (!is_callable($pathResolver)) { throw new \LogicException('pathResolver should be callable'); } $this->pathResolver = $pathResolver; } /** * @param string $filename * @param string $suffix * @return string */ public function bookFile($filename, $suffix = '') { $output = $this->tmpPath .'/lzrt_' . substr($filename, 0, 3) . '_' . $suffix . '.' . pathinfo($filename, PATHINFO_EXTENSION); $infos = pathinfo($output); $n = 0; while (true) { $output = sprintf('%s/%s-%d%s', $infos['dirname'], $infos['filename'], ++ $n, (isset($infos['extension']) ? '.' . $infos['extension'] : '')); try { if (! $this->filesystem->exists($output)) { $this->filesystem->touch($output); break; } } catch (IOException $e) { } } return $this->resolvePath($output); } /** * @param string $path * @return string */ private function resolvePath($path) { $callable = $this->pathResolver; return $callable($path); } }