/** * @param Config $config * @return static */ public static function create(Config $config, ParserInterface $fallbackParser = null) { if (empty($config->getAttribute('mappings'))) { throw new UserException("Cannot initialize JSON Mapper with no mapping"); } $mappers = []; foreach ($config->getAttribute('mappings') as $type => $mapping) { if (empty($mapping)) { throw new UserException("Empty mapping for '{$type}' in config."); } $mappers[$type] = new Mapper($mapping, $type); } foreach ($config->getJobs() as $job) { $type = $job->getDataType(); if (empty($mappers[$type])) { if (is_null($fallbackParser)) { throw new UserException("Missing mapping for '{$type}' in config."); } } } $parser = new static($mappers); $parser->setFallbackParser($fallbackParser); return $parser; }
/** * @param JobConfig $jobConfig * @param RestClient $client * @param Config $config * @param Builder $builder */ protected function runJob($jobConfig, $client, $config, $builder) { // FIXME this is rather duplicated in RecursiveJob::createChild() $job = new GenericExtractorJob($jobConfig, $client, $this->parser); $job->setScroller($this->scroller); $job->setAttributes($config->getAttributes()); $job->setMetadata($this->metadata); $job->setBuilder($builder); $job->setResponseModules($this->modules['response']); if (!empty($config->getAttribute('userData'))) { $job->setUserParentId(is_scalar($config->getAttribute('userData')) ? ['userData' => $config->getAttribute('userData')] : $config->getAttribute('userData')); } $job->run(); }