/** * Get the filesystem's disk. * * @return \Anomaly\FilesModule\Disk\Contract\DiskInterface|null */ protected function getFilesystemDisk() { $filesystem = $this->directory->getFilesystem(); if ($filesystem instanceof AdapterFilesystem) { return $filesystem->getDisk(); } return null; }
/** * Sync a file. * * @param Directory $resource * @param DiskInterface $disk * @return null|FolderInterface */ public function sync(Directory $resource, DiskInterface $disk) { $path = $resource->getPath(); if ($path === '.') { return null; } if (!($folder = $this->folders->findBySlug($path))) { $folder = $this->folders->create(['name' => $path, 'disk_id' => $disk->getId()]); } return $folder; }
/** * Sync a file. * * @param Directory $resource * @param DiskInterface $disk * @return null|FolderInterface */ public function sync(Directory $resource, DiskInterface $disk) { $path = $resource->getPath(); if ($path === '.') { return null; } /* @var FolderInterface|null $parent */ $parent = null; $folder = null; foreach (explode('/', $path) as $name) { if (!($folder = $this->folders->findByName($name, $disk, $parent))) { $folder = $this->folders->create(['name' => $name, 'disk_id' => $disk->getId(), 'parent_id' => $parent ? $parent->getId() : null]); } $parent = $folder; } return $folder; }
public function testDirListContents() { $prophecy = $this->prophesize('League\\Flysystem\\FilesystemInterface'); $prophecy->listContents('path', true)->willReturn($listing = ['listing']); $filesystem = $prophecy->reveal(); $dir = new Directory(null, 'path'); $dir->setFilesystem($filesystem); $output = $dir->getContents(true); $this->assertEquals($listing, $output); }