/** * {@inheritdoc} */ public function getBackupsToRemove(BackupCollection $existingBackups, Backup $newBackup) { $size = $existingBackups->getTotalFileSize() + $newBackup->getSize(); if ($size < $this->maxSize) { return new BackupCollection(); } $backupsToRemove = array(); /** @var Backup[] $existingBackups */ foreach ($existingBackups as $backup) { $backupsToRemove[] = $backup; $size -= $backup->getSize(); if ($size < $this->maxSize) { break; } } return new BackupCollection($backupsToRemove); }
/** * {@inheritdoc} */ public function all() { $backups = array(); /** @var SplFileInfo[] $files */ $files = Finder::create()->in($this->directory)->files()->depth(0)->sortByModifiedTime(); foreach ($files as $file) { $backups[] = Backup::fromFile($file->getPathname()); } return $backups; }
/** * {@inheritdoc} */ public function push($filename, LoggerInterface $logger) { $this->doRotate(Backup::fromFile($filename), $logger); return $this->destination->push($filename, $logger); }