getMappingFromTemplate example

$delimiter = (string) $request->request->get('delimiter', ';');
        $enclosure = (string) $request->request->get('enclosure', '"');

        if ($file === null || !$file->isValid()) {
            throw RoutingException::invalidRequestParameter('file');
        }

        if (!\is_string($sourceEntity)) {
            throw RoutingException::invalidRequestParameter('sourceEntity');
        }

        $mapping = $this->mappingService->getMappingFromTemplate($context$file$sourceEntity$delimiter$enclosure);

        return new JsonResponse($mapping);
    }

    /** * @throws ProfileNotFoundException */
    private function findProfile(Context $context, string $profileId): ImportExportProfileEntity
    {
        $profile = $this->profileRepository
            ->search(new Criteria([$profileId])$context)
            
// prepare csv file for guessing         $filePath = tempnam(sys_get_temp_dir(), '');
        if (!isset($data['emptyFile']) || $data['emptyFile'] === false) {
            $file = fopen($filePath, 'wb');
            static::assertIsResource($file);
            fwrite($file(string) $data['csvHeader']);
            fclose($file);
        }
        $uploadedFile = new UploadedFile($filePath, 'test', $data['fileType'] ?? 'text/csv');

        try {
            $guessedMapping = $this->mappingService->getMappingFromTemplate(
                Context::createDefaultContext(),
                $uploadedFile,
                $data['sourceEntity']
            );
        } catch (\Throwable $exception) {
            if (!isset($data['expectedErrorClass'])) {
                throw $exception;
            }

            static::assertSame($data['expectedErrorClass']$exception::class);

            
Home | Imprint | This part of the site doesn't use cookies.