/** * {@inheritdoc} */ public function transport(SourceInterface $source) { $filename = $source->getSource(); if (FileSystem::checkFile($filename)) { return new Stream(fopen($filename, 'r+')); } throw new \RuntimeException(sprintf('The file "%s" does not exist or is not readable.', $filename)); }
public function testCheckDirectory() { mkdir(static::DIRECTORY); $this->assertFalse(FileSystem::checkDirectory('does_not_exist')); // Remove read permission. chmod(static::DIRECTORY, 00); $this->assertFalse(FileSystem::checkDirectory(static::DIRECTORY)); chmod(static::DIRECTORY, 777); $this->assertTrue(FileSystem::checkDirectory(static::DIRECTORY)); }
/** * Builds an import from a configuration file. * * @param string $filename * The name of the configuration file. * * @return \Devour\Importer\ImporterInterface * A new importer. * * @see \Devour\Importer\ImporterFactory::fromConfiguration() */ public static function fromConfigurationFile($filename) { if (!FileSystem::checkFile($filename)) { throw new \RuntimeException(sprintf('The configuration file "%s" does not exist or is not readable.', $filename)); } $configuration = Yaml::parse(file_get_contents($filename)); if (!is_array($configuration)) { throw new \RuntimeException(sprintf('The configuration file "%s" is invalid.', $filename)); } return static::fromConfiguration($configuration); }
/** * Gets the sources provided in the input. * * @return \Devour\Source\SourceInterface[] * A list of source objects. */ protected function getSources(InputInterface $input) { $sources = $input->getArgument('source'); // Sources could be a file that contains a list of sources. if ($input->getOption('source_file') && FileSystem::checkFile($sources[0])) { $sources = file_get_contents($sources[0]); $sources = array_map('trim', explode("\n", $sources)); } return array_map(function ($source) { return new Source($source); }, array_filter($sources)); }
protected function getBootstrapFile(InputInterface $input) { $bootstrap = $input->getParameterOption(['--bootstrap', '-b']); if ($bootstrap !== FALSE && !FileSystem::checkFile($bootstrap)) { throw new \RuntimeException('Invalid bootstrap file.'); } return $bootstrap; }