PluginProbe
404 Solution / 4.2.0
404 Solution v4.2.0
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / PluginLogicImportExport.php

PluginLogicImportExport.php in 404 Solution 4.2.0, at includes/PluginLogicImportExport.php

110 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 if (!defined('ABSPATH')) {
5 exit;
6 }
7
8 /**
9 * Import/export functionality delegated to ABJ_404_Solution_ImportExportService.
10 * Standalone class extracted from PluginLogicTrait_ImportExport.
11 */
12 class ABJ_404_Solution_PluginLogicImportExport {
13
14 /** @var callable */
15 private $serviceFactory;
16
17 /** @var ABJ_404_Solution_ImportExportService|null */
18 private $service = null;
19
20 /**
21 * @param callable $serviceFactory Returns an ABJ_404_Solution_ImportExportService instance.
22 */
23 function __construct(callable $serviceFactory) {
24 $this->serviceFactory = $serviceFactory;
25 }
26
27 /** @return ABJ_404_Solution_ImportExportService */
28 private function getService() {
29 if ($this->service === null) {
30 $this->service = ($this->serviceFactory)();
31 }
32 return $this->service;
33 }
34
35 /** @return string */
36 function getExportFilename(string $format = 'native'): string {
37 return $this->getService()->getExportFilename($format);
38 }
39
40 /** @return void */
41 function doExport(): void {
42 $this->getService()->doExport();
43 }
44
45 /**
46 * @param string $sourceFile Native export file path.
47 * @param string $destinationFile Output file path.
48 * @return string Empty string on success, error message otherwise.
49 */
50 function convertExportCsvToRedirectionFormat($sourceFile, $destinationFile) {
51 return $this->getService()->convertExportCsvToRedirectionFormat($sourceFile, $destinationFile);
52 }
53
54 /** @return string */
55 function doImportFile(): string {
56 return $this->getService()->doImportFile();
57 }
58
59 /**
60 * @param array<string, mixed> $dataArray
61 * @param bool $dryRun
62 * @return array<int, string>
63 */
64 function loadDataArrayFromFile(array $dataArray, bool $dryRun = false): array {
65 return $this->getService()->loadDataArrayFromFile($dataArray, $dryRun);
66 }
67
68 /** @return array<string, string> */
69 function splitCsvLine(string $line): array {
70 return $this->getService()->splitCsvLine($line);
71 }
72
73 /**
74 * @param array<int, string> $columns
75 * @return bool
76 */
77 function isCompatibleImportHeaderRow(array $columns): bool {
78 return $this->getService()->isCompatibleImportHeaderRow($columns);
79 }
80
81 /**
82 * @param array<int, string> $columns
83 * @return array<int, string>
84 */
85 function normalizeImportHeaders(array $columns): array {
86 $result = $this->getService()->normalizeImportHeaders($columns);
87 return array_map(function ($v) {
88 return is_string($v) ? $v : '';
89 }, $result);
90 }
91
92 /**
93 * @param array<int, string> $row
94 * @param array<int, string> $normalizedHeaders
95 * @return array<string, string>
96 */
97 function mapImportRowByHeaders(array $row, array $normalizedHeaders): array {
98 return $this->getService()->mapImportRowByHeaders($row, $normalizedHeaders);
99 }
100
101 /**
102 * @param array<int, string> $columns
103 * @return string
104 */
105 function detectImportFormatFromHeaders(array $columns): string {
106 return $this->getService()->detectImportFormatFromHeaders($columns);
107 }
108
109 }
110