Ejemplo n.º 1
0
 /**
  * Builds an import from a configuration array.
  *
  * @param array $config
  *   The configuration array.
  *
  * @return \Devour\Importer\ImporterInterface
  *   A new importer.
  *
  * @throws \RuntimeException
  *   Thrown if the configuration file is invalid.
  */
 public static function fromConfiguration(array $config)
 {
     // We will get an exception anyway if these do not exist, but this is a more
     // user-friendly way to do it.
     foreach (['transporter', 'processor'] as $part) {
         if (empty($config[$part]['class'])) {
             throw new \RuntimeException(sprintf('The %s class is required.', $part));
         }
     }
     $config = array_replace_recursive(static::defaultConfiguration(), $config);
     $builder = ImporterBuilder::get()->setImporter($config['importer']['class'], $config['importer']['configuration'])->setTransporter($config['transporter']['class'], $config['transporter']['configuration'])->setProcessor($config['processor']['class'], $config['processor']['configuration'])->setMap($config['map']['class'], $config['map']['configuration'])->setTableClass($config['table']['class']);
     if ($config['parser']['class']) {
         $builder->setParser($config['parser']['class'], $config['parser']['configuration']);
     }
     return $builder->build();
 }
Ejemplo n.º 2
0
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage The "IDONOTEXIST" class does not exist.
  */
 public function testInvalidClass()
 {
     ImporterBuilder::get()->setTransporter('IDONOTEXIST');
 }