/** * {@inheritdoc} */ public function fileOfName(FileName $aName) { $statement = $this->execute('SELECT * FROM file WHERE name = :name AND extension = :extension', ['name' => $aName->name(), 'extension' => $aName->extension()]); if ($row = $statement->fetch(\PDO::FETCH_ASSOC)) { return $this->buildFile($row); } }
/** * Handles the given command. * * @param ByHashUploadFileCommand $aCommand The command * * @throws FileAlreadyExistsException when file is already exists */ public function __invoke(ByHashUploadFileCommand $aCommand) { $id = new FileId($aCommand->id()); $file = $this->repository->fileOfId($id); if (null !== $file) { throw new FileAlreadyExistsException(); } $name = FileName::fromHash($aCommand->name()); if (true === $this->filesystem->has($name)) { throw new FileAlreadyExistsException(); } $this->filesystem->write($name, $aCommand->uploadedFile()); $file = $this->factory->build($id, $name, new FileMimeType($aCommand->mimeType())); $this->repository->persist($file); }
/** * {@inheritdoc} */ public function write(FileName $aName, $aContent) { foreach ($this->files as $key => $file) { if ($file['filename'] === $aName->filename()) { return; } } $this->files[] = ['filename' => $aName->filename(), 'content' => $aContent]; }
/** * Method that checks if the name given is equal to the current. * * @param FileName $aName * * @return bool */ public function equals(FileName $aName) { return $this->filename() === $aName->filename(); }