/** * Tests Start::getConfig */ public function testGetConfig() { $conf = new Configuration('/tmp/foo.xml'); $conf->setDebug(true); $start = new Start($conf); $config = $start->getConfiguration(); $this->assertEquals(true, $config->getDebug()); }
/** * Returns the phpbu Configuration. * * @return \phpbu\App\Configuration */ public function getConfiguration() { $configuration = new Configuration(); $configuration->setFilename($this->filename); $this->setAppSettings($configuration); $this->setPhpSettings($configuration); $this->setLoggers($configuration); $this->setBackups($configuration); return $configuration; }
/** * Handles the bootstrap file inclusion. * * @param \phpbu\App\Configuration $configuration * @throws \phpbu\App\Exception */ protected function handleBootstrap(Configuration $configuration) { $filename = $configuration->getBootstrap(); if (!empty($filename)) { $pathToFile = stream_resolve_include_path($filename); if (!$pathToFile || !is_readable($pathToFile)) { throw new Exception(sprintf('Cannot open bootstrap file "%s".' . PHP_EOL, $filename)); } require $pathToFile; } }
/** * Execute the backup. * * @param \phpbu\App\Configuration\Backup $conf * @param \phpbu\App\Backup\Target $target * @throws \Exception */ protected function executeSource(Configuration\Backup $conf, Target $target) { $this->result->backupStart($conf); /* @var \phpbu\App\Runner\Source $runner */ $source = $this->factory->createSource($conf->getSource()->type, $conf->getSource()->options); $runner = $this->factory->createRunner('source'); $runner->run($source, $target, $this->result, $this->configuration->isSimulation()); $this->result->backupEnd($conf); }
protected function archiveBackup(Configuration $configuration, $sourcePath, $targetPath, $targetFilename, $compress) { // Create a backup $name = $this->identifier . '-archive-' . str_random(8); $backup = app(Backup::class, [$name, false]); // Define the options $sourceOptions = ['path' => $sourcePath, 'removeDir' => true, 'showStdErr' => true]; // Define a source and a target based on those options $source = app(Source::class, ['tar', $sourceOptions]); $target = app(Target::class, [$targetPath, $targetFilename, $compress]); // Persist the source and the target in the backup $backup->setSource($source); $backup->setTarget($target); // Add backup to runner configuration $configuration->addBackup($backup); }
/** * Set the backup configurations. * * @param \phpbu\App\Configuration $configuration * @throws \phpbu\App\Exception */ public function setBackups(Configuration $configuration) { if (!isset($this->json['backups'])) { throw new Exception('no backup configured'); } foreach ($this->json['backups'] as $backup) { $configuration->addBackup($this->getBackupConfig($backup)); } }
/** * Create and register all configured loggers. * * @param \phpbu\App\Configuration $configuration */ protected function setupLoggers(Configuration $configuration) { foreach ($configuration->getLoggers() as $log) { // this is a already fully setup Listener so just add it if (is_a($log, '\\phpbu\\App\\Listener')) { $logger = $log; } else { // this is a configuration blueprint for a logger, so create and add it /** @var \phpbu\App\Configuration\Logger $log */ /** @var \phpbu\App\Listener $logger */ $logger = $this->factory->createLogger($log->type, $log->options); } $this->result->addListener($logger); } }
/** * Set the backup configurations. * * @param \phpbu\App\Configuration $configuration * @throws \phpbu\App\Exception */ public function setBackups(Configuration $configuration) { foreach ($this->xpath->query('backups/backup') as $backupNode) { $configuration->addBackup($this->getBackupConfig($backupNode)); } }