Exemplo n.º 1
0
 /**
  * {@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);
     }
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 /**
  * {@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];
 }
Exemplo n.º 4
0
 /**
  * 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();
 }