/**
  * Sync a file.
  *
  * @param File          $resource
  * @param DiskInterface $disk
  * @return null|FileInterface
  */
 public function sync(File $resource, DiskInterface $disk)
 {
     $folder = $this->syncFolder($resource, $disk);
     if (!($file = $this->files->findByNameAndFolder(basename($resource->getPath()), $folder))) {
         $file = $this->files->create(['name' => basename($resource->getPath()), 'folder_id' => $folder ? $folder->getId() : null, 'disk_id' => $disk->getId(), 'size' => $resource->getSize(), 'mime_type' => $resource->getMimetype(), 'extension' => pathinfo($resource->getPath(), PATHINFO_EXTENSION), 'entry_type' => $folder->getEntryModelName()]);
     } else {
         $this->files->save($file);
     }
     return $file;
 }
 /**
  * Upload a file.
  *
  * @param UploadedFile    $file
  * @param FolderInterface $folder
  * @return bool|FileInterface
  */
 public function upload(UploadedFile $file, FolderInterface $folder)
 {
     $rules = 'required';
     if ($allowed = $folder->getAllowedTypes()) {
         $rules .= '|mimes:' . implode(',', $allowed);
     }
     $validation = $this->validator->make(['file' => $file], ['file' => $rules]);
     if (!$validation->passes()) {
         return false;
     }
     $disk = $folder->getDisk();
     /* @var FileInterface $entry */
     $entry = $this->manager->put($disk->getSlug() . '://' . $folder->getSlug() . '/' . $file->getClientOriginalName(), file_get_contents($file->getRealPath()));
     if (in_array($entry->getExtension(), $this->config->get('anomaly.module.files::mimes.types.image'))) {
         $size = getimagesize($file->getRealPath());
         $this->files->save($entry->setAttribute('width', $size[0])->setAttribute('height', $size[1]));
     }
     return $entry;
 }